Author: mattmann
Date: Sat Sep 12 17:40:55 2015
New Revision: 1702654
URL: http://svn.apache.org/r1702654
Log:
Fix for NUTCH-2092: Unit Test for NutchServer contributedy by Sujen Shah
<[email protected]> this closes #54.
Added:
nutch/trunk/src/test/org/apache/nutch/service/
nutch/trunk/src/test/org/apache/nutch/service/TestNutchServer.java
Modified:
nutch/trunk/CHANGES.txt
nutch/trunk/ivy/ivy.xml
nutch/trunk/src/java/org/apache/nutch/service/NutchServer.java
Modified: nutch/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/nutch/trunk/CHANGES.txt?rev=1702654&r1=1702653&r2=1702654&view=diff
==============================================================================
--- nutch/trunk/CHANGES.txt (original)
+++ nutch/trunk/CHANGES.txt Sat Sep 12 17:40:55 2015
@@ -2,6 +2,8 @@ Nutch Change Log
Nutch Current Development 1.11-SNAPSHOT
+* NUTCH-2092: Unit Test for NutchServer (Sujen Shah via mattmann)
+
* NUTCH-2096 Explicitly indicate broswer binary to use when selecting
selenium remote option in config (Kim Whitehall via mattmann)
Modified: nutch/trunk/ivy/ivy.xml
URL:
http://svn.apache.org/viewvc/nutch/trunk/ivy/ivy.xml?rev=1702654&r1=1702653&r2=1702654&view=diff
==============================================================================
--- nutch/trunk/ivy/ivy.xml (original)
+++ nutch/trunk/ivy/ivy.xml Sat Sep 12 17:40:55 2015
@@ -71,14 +71,15 @@
<dependency org="com.github.crawler-commons"
name="crawler-commons" rev="0.6" />
- <dependency org="org.apache.cxf" name="cxf" rev="3.0.4"/>
- <dependency org="org.apache.cxf" name="cxf-rt-frontend-jaxws"
rev="3.0.4"/>
- <dependency org="org.apache.cxf" name="cxf-rt-frontend-jaxrs"
rev="3.0.4"/>
- <dependency org="org.apache.cxf" name="cxf-rt-transports-http"
rev="3.0.4"/>
- <dependency org="org.apache.cxf" name="cxf-rt-transports-http-jetty"
rev="3.0.4"/>
- <dependency org="com.fasterxml.jackson.core" name="jackson-databind"
rev="2.5.1" />
- <dependency org="com.fasterxml.jackson.dataformat"
name="jackson-dataformat-cbor" rev="2.5.1" />
- <dependency org="com.fasterxml.jackson.jaxrs"
name="jackson-jaxrs-json-provider" rev="2.5.1" />
+ <dependency org="org.apache.cxf" name="cxf" rev="3.0.4"
conf="*->default"/>
+ <dependency org="org.apache.cxf" name="cxf-rt-frontend-jaxws"
rev="3.0.4" conf="*->default"/>
+ <dependency org="org.apache.cxf" name="cxf-rt-frontend-jaxrs"
rev="3.0.4" conf="*->default"/>
+ <dependency org="org.apache.cxf" name="cxf-rt-transports-http"
rev="3.0.4" conf="*->default"/>
+ <dependency org="org.apache.cxf" name="cxf-rt-transports-http-jetty"
rev="3.0.4" conf="*->default"/>
+ <dependency org="org.apache.cxf" name="cxf-rt-rs-client" rev="3.0.4"
conf="test->default"/>
+ <dependency org="com.fasterxml.jackson.core" name="jackson-databind"
rev="2.5.1" conf="*->default"/>
+ <dependency org="com.fasterxml.jackson.dataformat"
name="jackson-dataformat-cbor" rev="2.5.1" conf="*->default"/>
+ <dependency org="com.fasterxml.jackson.jaxrs"
name="jackson-jaxrs-json-provider" rev="2.5.1" conf="*->default"/>
<!--artifacts needed for testing -->
<dependency org="junit" name="junit" rev="4.11"
conf="test->default" />
Modified: nutch/trunk/src/java/org/apache/nutch/service/NutchServer.java
URL:
http://svn.apache.org/viewvc/nutch/trunk/src/java/org/apache/nutch/service/NutchServer.java?rev=1702654&r1=1702653&r2=1702654&view=diff
==============================================================================
--- nutch/trunk/src/java/org/apache/nutch/service/NutchServer.java (original)
+++ nutch/trunk/src/java/org/apache/nutch/service/NutchServer.java Sat Sep 12
17:40:55 2015
@@ -107,7 +107,7 @@ public class NutchServer {
return server;
}
- private static void startServer() {
+ protected static void startServer() {
server.start();
}
@@ -211,6 +211,10 @@ public class NutchServer {
return jobs.isEmpty();
}
+ protected static void setPort(int port) {
+ NutchServer.port = port;
+ }
+
public int getPort() {
return port;
}
Added: nutch/trunk/src/test/org/apache/nutch/service/TestNutchServer.java
URL:
http://svn.apache.org/viewvc/nutch/trunk/src/test/org/apache/nutch/service/TestNutchServer.java?rev=1702654&view=auto
==============================================================================
--- nutch/trunk/src/test/org/apache/nutch/service/TestNutchServer.java (added)
+++ nutch/trunk/src/test/org/apache/nutch/service/TestNutchServer.java Sat Sep
12 17:40:55 2015
@@ -0,0 +1,65 @@
+/**
+ * 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.nutch.service;
+
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestNutchServer {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(TestNutchServer.class);
+ NutchServer server = NutchServer.getInstance();
+
+ private int port[] = {8081, 9999, 9100, 8900};
+ private final String ENDPOINT_ADDRESS = "http://localhost:";
+
+ @Test
+ public void testNutchServerStartup() {
+ boolean isRunning = false;
+ for(int i=0;i<port.length; i++) {
+ try {
+ startServer(port[i]);
+ isRunning = true;
+ break;
+ }catch(Exception e) {
+ LOG.info("Could not start server on port: {}. Tries remaining
{}",port[i],port.length-i);
+ }
+ }
+ if(!isRunning) {
+ LOG.info("Could not start server, all ports in use");
+ }
+ else {
+ LOG.info("Testing admin endpoint");
+ WebClient client = WebClient.create(ENDPOINT_ADDRESS + server.getPort());
+ Response response = client.path("admin").get();
+
Assert.assertTrue(response.readEntity(String.class).contains("startDate"));
+ response = client.path("stop").get();
+
Assert.assertTrue(response.readEntity(String.class).contains("Stopping"));
+ }
+ }
+
+ private void startServer(int port) throws Exception{
+ NutchServer.setPort(port);
+ NutchServer.startServer();
+ }
+}