Apache Lucene open-source search software
SOLR-4394: phase 2, promoted SSL randomization logic up to SolrJettyTestBase
Chris M. Hostetter881c0b21eb19
diff --git a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.javaindex d4b83bc2876..d8c5468878e 100644--- a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java+++ b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java@@ -26,7 +26,6 @@ import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpHead;import org.apache.http.client.methods.HttpPost;import org.apache.http.client.methods.HttpRequestBase;-import org.apache.http.client.utils.URIUtils;import org.apache.http.client.utils.URLEncodedUtils;import org.apache.http.message.BasicNameValuePair;import org.apache.http.util.EntityUtils;@@ -49,10 +48,8 @@ public abstract class CacheHeaderTestBase extends SolrJettyTestBase {qparams.add(new BasicNameValuePair(params[i * 2], params[i * 2 + 1]));}- java.net.URI uri = URIUtils.createURI("http",- new URI(httpserver.getBaseURL()).getHost(),- new URI(httpserver.getBaseURL()).getPort(), "/solr/select",- URLEncodedUtils.format(qparams, "UTF-8"), null);+ URI uri = URI.create(httpserver.getBaseURL() + "/select?" ++ URLEncodedUtils.format(qparams, "UTF-8"));if ("GET".equals(method)) {m = new HttpGet(uri);@@ -73,10 +70,9 @@ public abstract class CacheHeaderTestBase extends SolrJettyTestBase {for(int i=0;i<params.length/2;i++) {qparams.add(new BasicNameValuePair(params[i*2], params[i*2+1]));}- java.net.URI uri = URIUtils.createURI("http",- new URI(httpserver.getBaseURL()).getHost(),- new URI(httpserver.getBaseURL()).getPort(), "/solr/update",- URLEncodedUtils.format(qparams, "UTF-8"), null);++ URI uri = URI.create(httpserver.getBaseURL() + "/update?" ++ URLEncodedUtils.format(qparams, "UTF-8"));if ("GET".equals(method)) {m=new HttpGet(uri);diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.javaindex 99344121e85..e467bbc4ff5 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java@@ -25,6 +25,8 @@ import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.client.solrj.response.UpdateResponse;import org.apache.solr.common.SolrInputDocument;import org.junit.Test;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;/***@@ -32,6 +34,7 @@ import org.junit.Test;*/public abstract class LargeVolumeTestBase extends SolrJettyTestBase{+ private static Logger log = LoggerFactory.getLogger(LargeVolumeTestBase.class);// for real load testing, make these numbers biggerstatic final int numdocs = 100; //1000 * 1000;diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.javaindex 4333b92e721..fc8f751bbba 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java@@ -41,7 +41,7 @@ public class SolrExampleBinaryTest extends SolrExampleTests {{try {// setup the server...- String url = "http://127.0.0.1:"+port+context;+ String url = jetty.getBaseUrl().toString();HttpSolrServer s = new HttpSolrServer( url );s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);s.setDefaultMaxConnectionsPerHost(100);diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.javaindex d453a986b7f..64a49119d6e 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java@@ -61,6 +61,8 @@ import org.apache.solr.common.params.AnalysisParams;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.FacetParams;import org.junit.Test;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;/*** This should include tests against the example solr config@@ -72,6 +74,8 @@ import org.junit.Test;*/abstract public class SolrExampleTests extends SolrJettyTestBase{+ private static Logger log = LoggerFactory.getLogger(SolrExampleTests.class);+static {ignoreException("uniqueKey");}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.javaindex 1f9f8482b12..2283e3ecb25 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java@@ -36,7 +36,7 @@ public class SolrExampleXMLTest extends SolrExampleTests {@Overridepublic SolrServer createNewSolrServer() {try {- String url = "http://127.0.0.1:" + port + context;+ String url = jetty.getBaseUrl().toString();HttpSolrServer s = new HttpSolrServer(url);s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);s.setDefaultMaxConnectionsPerHost(100);diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.javaindex 0803ce39ab1..3bd3b99c502 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java@@ -21,18 +21,10 @@ import org.apache.solr.client.solrj.SolrExampleTests;import org.apache.solr.client.solrj.impl.HttpSolrServer;import org.apache.solr.util.ExternalPaths;-import java.io.File;-import java.util.Map;-import java.util.HashMap;-import org.junit.Assert;-import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;-import org.slf4j.Logger;-import org.slf4j.LoggerFactory;-/*** TODO? perhaps use:* http://docs.codehaus.org/display/JETTY/ServletTester@@ -41,73 +33,11 @@ import org.slf4j.LoggerFactory;*/public class SolrExampleJettyTest extends SolrExampleTests {- private static Logger log = LoggerFactory.getLogger(SolrExampleJettyTest.class);-- private static boolean manageSslProps = true;-- private static final File TEST_KEYSTORE = new File(ExternalPaths.SOURCE_HOME,- "example/etc/solrtest.keystore");-- private static final Map<String,String> SSL_PROPS = new HashMap<String,String>();- static {- SSL_PROPS.put("tests.jettySsl","false");- SSL_PROPS.put("tests.jettySsl.clientAuth","false");- SSL_PROPS.put("javax.net.ssl.keyStore", TEST_KEYSTORE.getAbsolutePath());- SSL_PROPS.put("javax.net.ssl.keyStorePassword","secret");- SSL_PROPS.put("javax.net.ssl.trustStore", TEST_KEYSTORE.getAbsolutePath());- SSL_PROPS.put("javax.net.ssl.trustStorePassword","secret");- }-@BeforeClasspublic static void beforeTest() throws Exception {-- // // //-- // :TODO: SOLR-4394 promote SSL up to SolrJettyTestBase?-- // consume the same amount of random no matter what- final boolean trySsl = random().nextBoolean();- final boolean trySslClientAuth = random().nextBoolean();-- // only randomize SSL if none of the SSL_PROPS are already set- final Map<Object,Object> sysprops = System.getProperties();- for (String prop : SSL_PROPS.keySet()) {- if (sysprops.containsKey(prop)) {- log.info("System property explicitly set, so skipping randomized ssl properties: " + prop);- manageSslProps = false;- break;- }- }-- assertTrue("test keystore does not exist, can't be used for randomized " +- "ssl testing: " + TEST_KEYSTORE.getAbsolutePath(),- TEST_KEYSTORE.exists() );-- if (manageSslProps) {- log.info("Randomized ssl ({}) and clientAuth ({})", trySsl, trySslClientAuth);- for (String prop : SSL_PROPS.keySet()) {- System.setProperty(prop, SSL_PROPS.get(prop));- }- // now explicitly re-set the two random values- System.setProperty("tests.jettySsl", String.valueOf(trySsl));- System.setProperty("tests.jettySsl.clientAuth", String.valueOf(trySslClientAuth));- }- // // //--createJetty(ExternalPaths.EXAMPLE_HOME, null, null);}- @AfterClass- public static void afterTest() throws Exception {- if (manageSslProps) {- for (String prop : SSL_PROPS.keySet()) {- System.clearProperty(prop);- }- }- }--@Testpublic void testBadSetup(){diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.javaindex 8bae61bff93..9fe6760d0b9 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java@@ -55,7 +55,8 @@ public class SolrExampleStreamingTest extends SolrExampleTests {{try {// setup the server...- String url = "http://127.0.0.1:"+port+context; // smaller queue size hits locks more often+ String url = jetty.getBaseUrl().toString();+ // smaller queue size hits locks more oftenConcurrentUpdateSolrServer s = new ConcurrentUpdateSolrServer( url, 2, 5 ) {public Throwable lastError = null;@@ -79,7 +80,7 @@ public class SolrExampleStreamingTest extends SolrExampleTests {// SOLR-3903final List<Throwable> failures = new ArrayList<Throwable>();ConcurrentUpdateSolrServer s = new ConcurrentUpdateSolrServer- ("http://127.0.0.1:"+port+context, 2, 2) {+ (jetty.getBaseUrl().toString(), 2, 2) {@Overridepublic void handleError(Throwable ex) {failures.add(ex);diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.javaindex ddf4c1e5daa..f6d51230044 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java@@ -147,8 +147,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {@Testpublic void testTimeout() throws Exception {- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"- + jetty.getLocalPort() + "/solr/slow/foo");+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() ++ "/slow/foo");SolrQuery q = new SolrQuery("*:*");server.setSoTimeout(2000);try {@@ -163,8 +163,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {@Testpublic void testQuery(){DebugServlet.clear();- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"- + jetty.getLocalPort() + "/solr/debug/foo");+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() ++ "/debug/foo");SolrQuery q = new SolrQuery("foo");q.setParam("a", "\u1234");try {@@ -250,8 +250,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {@Testpublic void testDelete(){DebugServlet.clear();- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"- + jetty.getLocalPort() + "/solr/debug/foo");+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() ++ "/debug/foo");try {server.deleteById("id");} catch (Throwable t) {}@@ -291,8 +291,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {@Testpublic void testUpdate(){DebugServlet.clear();- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"- + jetty.getLocalPort() + "/solr/debug/foo");+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() ++ "/debug/foo");UpdateRequest req = new UpdateRequest();req.add(new SolrInputDocument());req.setParam("a", "\u1234");@@ -352,8 +352,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {@Testpublic void testRedirect() throws Exception {- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"- + jetty.getLocalPort() + "/solr/redirect/foo");+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() ++ "/redirect/foo");SolrQuery q = new SolrQuery("*:*");// default = falsetry {@@ -373,8 +373,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {@Testpublic void testCompression() throws Exception {- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"- + jetty.getLocalPort() + "/solr/debug/foo");+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() ++ "/debug/foo");SolrQuery q = new SolrQuery("*:*");// verify request header gets set@@ -395,8 +395,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {assertNull(DebugServlet.headers.get("Accept-Encoding"));// verify server compresses output- HttpGet get = new HttpGet("http://127.0.0.1:" + jetty.getLocalPort()- + "/solr/select?q=foo&wt=xml");+ HttpGet get = new HttpGet(jetty.getBaseUrl().toString() ++ "/select?q=foo&wt=xml");get.setHeader("Accept-Encoding", "gzip");HttpClient client = HttpClientUtil.createClient(null);HttpEntity entity = null;@@ -414,8 +414,7 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {}// verify compressed response can be handled- server = new HttpSolrServer("http://127.0.0.1:" + jetty.getLocalPort()- + "/solr");+ server = new HttpSolrServer(jetty.getBaseUrl().toString());server.setAllowCompression(true);q = new SolrQuery("foo");QueryResponse response = server.query(q);@@ -426,7 +425,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {@Testpublic void testSetParametersExternalClient(){HttpClient client = HttpClientUtil.createClient(null);- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1/", client);+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString(),+ client);try {server.setMaxTotalConnections(1);fail("Operation should not succeed.");@@ -441,7 +441,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {@Testpublic void testGetRawStream() throws SolrServerException, IOException{HttpClient client = HttpClientUtil.createClient(null);- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:" + jetty.getLocalPort() + "/solr", client, null);+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString(),+ client, null);QueryRequest req = new QueryRequest();NamedList response = server.request(req);InputStream stream = (InputStream)response.get("stream");diff --git a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.javaindex 69f9f8d6c82..473771e84b8 100755--- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java@@ -22,16 +22,71 @@ import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;import org.apache.solr.client.solrj.embedded.JettySolrRunner;import org.apache.solr.client.solrj.impl.HttpSolrServer;import org.apache.solr.util.ExternalPaths;++import java.io.File;+import java.util.Map;+import java.util.HashMap;+import org.junit.AfterClass;+import org.junit.BeforeClass;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;+abstract public class SolrJettyTestBase extends SolrTestCaseJ4{+ private static Logger log = LoggerFactory.getLogger(SolrJettyTestBase.class);+// Try not introduce a dependency on the example schema or config unless you need to.// using configs in the test directory allows more flexibility to change "example"// without breaking configs.-public String getSolrHome() { return ExternalPaths.EXAMPLE_HOME; }+ private static boolean manageSslProps = true;+ private static final File TEST_KEYSTORE = new File(ExternalPaths.SOURCE_HOME,+ "example/etc/solrtest.keystore");+ private static final Map<String,String> SSL_PROPS = new HashMap<String,String>();+ static {+ SSL_PROPS.put("tests.jettySsl","false");+ SSL_PROPS.put("tests.jettySsl.clientAuth","false");+ SSL_PROPS.put("javax.net.ssl.keyStore", TEST_KEYSTORE.getAbsolutePath());+ SSL_PROPS.put("javax.net.ssl.keyStorePassword","secret");+ SSL_PROPS.put("javax.net.ssl.trustStore", TEST_KEYSTORE.getAbsolutePath());+ SSL_PROPS.put("javax.net.ssl.trustStorePassword","secret");+ }++ @BeforeClass+ public static void beforeSolrJettyTestBase() throws Exception {++ // consume the same amount of random no matter what+ final boolean trySsl = random().nextBoolean();+ final boolean trySslClientAuth = random().nextBoolean();++ // only randomize SSL if none of the SSL_PROPS are already set+ final Map<Object,Object> sysprops = System.getProperties();+ for (String prop : SSL_PROPS.keySet()) {+ if (sysprops.containsKey(prop)) {+ log.info("System property explicitly set, so skipping randomized ssl properties: " + prop);+ manageSslProps = false;+ break;+ }+ }++ assertTrue("test keystore does not exist, can't be used for randomized " ++ "ssl testing: " + TEST_KEYSTORE.getAbsolutePath(),+ TEST_KEYSTORE.exists() );++ if (manageSslProps) {+ log.info("Randomized ssl ({}) and clientAuth ({})", trySsl, trySslClientAuth);+ for (String prop : SSL_PROPS.keySet()) {+ System.setProperty(prop, SSL_PROPS.get(prop));+ }+ // now explicitly re-set the two random values+ System.setProperty("tests.jettySsl", String.valueOf(trySsl));+ System.setProperty("tests.jettySsl.clientAuth", String.valueOf(trySslClientAuth));+ }+ }+public static JettySolrRunner jetty;public static int port;public static SolrServer server = null;@@ -64,6 +119,11 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4jetty = null;}server = null;+ if (manageSslProps) {+ for (String prop : SSL_PROPS.keySet()) {+ System.clearProperty(prop);+ }+ }}