camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject git commit: CAMEL-7223: Avoid using hard-coded ports for the unit-tests
Date Tue, 18 Feb 2014 21:11:25 GMT
Repository: camel
Updated Branches:
  refs/heads/master e532b283d -> e10f04b50


CAMEL-7223: Avoid using hard-coded ports for the unit-tests

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e10f04b5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e10f04b5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e10f04b5

Branch: refs/heads/master
Commit: e10f04b506f81dc7d5dbbe90af5259e813673c25
Parents: e532b28
Author: Babak Vahdat <bvahdat@apache.org>
Authored: Tue Feb 18 22:11:05 2014 +0100
Committer: Babak Vahdat <bvahdat@apache.org>
Committed: Tue Feb 18 22:11:05 2014 +0100

----------------------------------------------------------------------
 .../camel/component/solr/SolrComponent.java     |  5 +--
 .../component/solr/InitSolrEndpointTest.java    |  5 ++-
 .../solr/SolrComponentTestSupport.java          | 12 +++----
 .../component/solr/SolrServerMissingTest.java   |  5 ++-
 .../camel/component/solr/SolrTestSupport.java   | 37 ++++++++++++++++++++
 5 files changed, 48 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e10f04b5/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
index a8827b4..646d8ed 100644
--- a/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
+++ b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
@@ -66,6 +66,7 @@ public class SolrComponent extends DefaultComponent {
         }
     }
 
+    @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
         Endpoint endpoint = new SolrEndpoint(uri, this, remaining);
         setProperties(endpoint, parameters);
@@ -95,7 +96,7 @@ public class SolrComponent extends DefaultComponent {
     void shutdownServers(SolrServerReference ref, boolean remove) {
         try {
             if (ref.getSolrServer() != null) {
-                LOG.info("Shutting down solr server: " + ref.getSolrServer());
+                LOG.info("Shutting down solr server: {}", ref.getSolrServer());
                 ref.getSolrServer().shutdown();
             }
         } catch (Exception e) {
@@ -103,7 +104,7 @@ public class SolrComponent extends DefaultComponent {
         }
         try {
             if (ref.getUpdateSolrServer() != null) {
-                LOG.info("Shutting down update solr server: " + ref.getUpdateSolrServer());
+                LOG.info("Shutting down update solr server: {}", ref.getUpdateSolrServer());
                 ref.getUpdateSolrServer().shutdownNow();
             }
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/camel/blob/e10f04b5/components/camel-solr/src/test/java/org/apache/camel/component/solr/InitSolrEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/InitSolrEndpointTest.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/InitSolrEndpointTest.java
index e75d99a..b00de3c 100644
--- a/components/camel-solr/src/test/java/org/apache/camel/component/solr/InitSolrEndpointTest.java
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/InitSolrEndpointTest.java
@@ -17,12 +17,11 @@
 package org.apache.camel.component.solr;
 
 import org.apache.camel.ResolveEndpointFailedException;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class InitSolrEndpointTest extends CamelTestSupport {
+public class InitSolrEndpointTest extends SolrTestSupport {
 
-    private String solrUrl = "solr://localhost:8999/solr";
+    private String solrUrl = "solr://localhost:" + getPort() + "/solr";
 
     @Test
     public void endpointCreatedCorrectlyWithAllOptions() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/e10f04b5/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
index 4e0366c..ff8f59a 100644
--- a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
@@ -20,8 +20,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -31,10 +29,8 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 
-public class SolrComponentTestSupport extends CamelTestSupport {
-    public static final int PORT = AvailablePortFinder.getNextAvailable(8899);
-    public static final String SOLR_ROUTE_URI = "solr://localhost:" + PORT + "/solr";
-
+public class SolrComponentTestSupport extends SolrTestSupport {
+    protected static final String SOLR_ROUTE_URI = "solr://localhost:" + getPort() + "/solr";
     protected static final String TEST_ID = "test1";
     protected static final String TEST_ID2 = "test2";
     protected static JettySolrRunner solrRunner;
@@ -71,10 +67,10 @@ public class SolrComponentTestSupport extends CamelTestSupport {
         System.setProperty("solr.directoryFactory", "solr.RAMDirectoryFactory");
 
         // Start a Solr instance.
-        solrRunner = new JettySolrRunner("src/test/resources/solr", "/solr", PORT);
+        solrRunner = new JettySolrRunner("src/test/resources/solr", "/solr", getPort());
         solrRunner.start();
 
-        solrServer = new HttpSolrServer("http://localhost:" + PORT + "/solr");
+        solrServer = new HttpSolrServer("http://localhost:" + getPort() + "/solr");
     }
 
     @AfterClass

http://git-wip-us.apache.org/repos/asf/camel/blob/e10f04b5/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrServerMissingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrServerMissingTest.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrServerMissingTest.java
index b778cfa..f2bcca5 100644
--- a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrServerMissingTest.java
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrServerMissingTest.java
@@ -18,11 +18,10 @@ package org.apache.camel.component.solr;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.junit.Test;
 
-public class SolrServerMissingTest extends CamelTestSupport {
+public class SolrServerMissingTest extends SolrTestSupport {
 
     @Test
     public void indexSingleDocumentToNonexistentServer() throws Exception {
@@ -38,7 +37,7 @@ public class SolrServerMissingTest extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").to("solr://localhost:8999/missingSolr");
+                from("direct:start").to("solr://localhost:" + getPort() + "/missingSolr");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/e10f04b5/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTestSupport.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTestSupport.java
new file mode 100644
index 0000000..5d7b120
--- /dev/null
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTestSupport.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.solr;
+
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+
+import org.junit.BeforeClass;
+
+public abstract class SolrTestSupport extends CamelTestSupport {
+
+    private static int port;
+
+    @BeforeClass
+    public static void initPort() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(8999);
+    }
+
+    protected static int getPort() {
+        return port;
+    }
+
+}


Mime
View raw message