Apache Solr open-source search software
SOLR-3854: Cleans up a lot of the tests by using a common function to build a consistent schemed URL (fixes SSL for SolrCmdDistributorTest) + disabled the "useClientAuth" property for OSX clients.
Mark Robert Miller98810d1f5495
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.javaindex cd101fb926e..665471a2667 100644--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java@@ -69,8 +69,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCaparams.set("command", "full-import");params.set("clean", "false");req.setParams(params);- String url = "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:" + jetty.getLocalPort() + "/solr";- HttpSolrServer solrServer = new HttpSolrServer(url);+ HttpSolrServer solrServer = new HttpSolrServer(buildUrl(jetty.getLocalPort(), "/solr"));solrServer.request(req);ModifiableSolrParams qparams = new ModifiableSolrParams();qparams.add("q", "*:*");@@ -89,8 +88,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa"clean", "false", UpdateParams.COMMIT, "false",UpdateParams.COMMIT_WITHIN, "1000");req.setParams(params);- String url = "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:" + jetty.getLocalPort() + "/solr";- HttpSolrServer solrServer = new HttpSolrServer(url);+ HttpSolrServer solrServer = new HttpSolrServer(buildUrl(jetty.getLocalPort(), "/solr"));solrServer.request(req);Thread.sleep(100);ModifiableSolrParams queryAll = params("q", "*");diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.javaindex dac92cfcab0..92a0b9c4011 100644--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java@@ -95,7 +95,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe}private String getSourceUrl() {- return "http" + (isSSLMode() ? "s" : "") +"://127.0.0.1:" + jetty.getLocalPort() + "/solr";+ return buildUrl(jetty.getLocalPort(), "/solr");}//TODO: fix this test to close its directoriesdiff --git a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.javaindex 0551eac1dbe..ba60c8af7ce 100644--- a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java@@ -138,7 +138,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {query.set("collection", "testalias");JettySolrRunner jetty = jettys.get(random().nextInt(jettys.size()));int port = jetty.getLocalPort();- HttpSolrServer server = new HttpSolrServer(getBaseUrl() + port + context + "/testalias");+ HttpSolrServer server = new HttpSolrServer(buildUrl(port) + "/testalias");res = server.query(query);assertEquals(3, res.getResults().getNumFound());@@ -146,7 +146,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {query = new SolrQuery("*:*");jetty = jettys.get(random().nextInt(jettys.size()));port = jetty.getLocalPort();- server = new HttpSolrServer(getBaseUrl() + port + context + "/testalias");+ server = new HttpSolrServer(buildUrl(port) + "/testalias");res = server.query(query);assertEquals(3, res.getResults().getNumFound());@@ -173,7 +173,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {query.set("collection", "testalias");jetty = jettys.get(random().nextInt(jettys.size()));port = jetty.getLocalPort();- server = new HttpSolrServer(getBaseUrl() + port + context + "/testalias");+ server = new HttpSolrServer(buildUrl(port) + "/testalias");res = server.query(query);assertEquals(5, res.getResults().getNumFound());@@ -181,7 +181,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {query = new SolrQuery("*:*");jetty = jettys.get(random().nextInt(jettys.size()));port = jetty.getLocalPort();- server = new HttpSolrServer(getBaseUrl() + port + context + "/testalias");+ server = new HttpSolrServer(buildUrl(port) + "/testalias");res = server.query(query);assertEquals(5, res.getResults().getNumFound());@@ -243,10 +243,6 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {assertTrue(sawException);}- private String getBaseUrl() {- return (isSSLMode() ? "https" : "http") + "://127.0.0.1:";- }-private void createAlias(String alias, String collections)throws SolrServerException, IOException {if (random().nextBoolean()) {diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.javaindex 13291a2ffd0..58186d9c332 100644--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java@@ -26,7 +26,6 @@ import java.util.regex.Pattern;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.BasicResponseHandler;-import org.apache.lucene.util.Constants;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrServer;import org.apache.solr.client.solrj.SolrServerException;@@ -45,7 +44,6 @@ import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.handler.ReplicationHandler;import org.apache.solr.util.AbstractSolrTestCase;-import org.junit.BeforeClass;/*** This test simply does a bunch of basic things in solrcloud mode and asserts things@@ -56,13 +54,6 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase {private static final String SHARD1 = "shard1";private static final String ONE_NODE_COLLECTION = "onenodecollection";- static {- if (Constants.MAC_OS_X) {- // disable while we look into mac test fail- ALLOW_SSL = false;- }- }-public BasicDistributedZk2Test() {super();fixShardCount = true;diff --git a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.javaindex f603fdf8048..e418fd418ee 100644--- a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java+++ b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java@@ -135,7 +135,7 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {private void getServers() throws Exception {jetty.start();- url = "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:" + jetty.getLocalPort() + "/solr/";+ url = buildUrl(jetty.getLocalPort(), "/solr/");// Mostly to keep annoying logging messages from being sent out all the time.diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.javaindex 0f7a0ff6edc..fc55861bcf8 100644--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java@@ -161,8 +161,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {private static SolrServer createNewSolrServer(int port) {try {// setup the server...- String url = "http://127.0.0.1:" + port + context;- HttpSolrServer s = new HttpSolrServer(url);+ HttpSolrServer s = new HttpSolrServer(buildUrl(port));s.setConnectionTimeout(15000);s.setSoTimeout(60000);s.setDefaultMaxConnectionsPerHost(100);@@ -495,7 +494,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {//jetty servers.private void invokeReplicationCommand(int pJettyPort, String pCommand) throws IOException{- String masterUrl = "http://127.0.0.1:" + pJettyPort + "/solr/replication?command=" + pCommand;+ String masterUrl = buildUrl(pJettyPort) + "/replication?command=" + pCommand;try {URL u = new URL(masterUrl);InputStream stream = u.openStream();@@ -648,7 +647,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {// todo: make SolrJ easier to pass arbitrary params to// TODO: precommit WILL screw with the rest of this test- String masterUrl = "http://127.0.0.1:" + masterJetty.getLocalPort() + "/solr/update?prepareCommit=true";+ String masterUrl = buildUrl(masterJetty.getLocalPort()) + "/update?prepareCommit=true";URL url = new URL(masterUrl);// InputStream stream = url.openStream();// try {@@ -664,8 +663,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {assertEquals(nDocs, masterQueryResult.getNumFound());// snappull- masterUrl = "http://127.0.0.1:" + slaveJetty.getLocalPort() + "/solr/replication?command=fetchindex&masterUrl=";- masterUrl += "http://127.0.0.1:" + masterJetty.getLocalPort() + "/solr/replication";+ masterUrl = buildUrl(slaveJetty.getLocalPort()) + "/replication?command=fetchindex&masterUrl=";+ masterUrl += buildUrl(masterJetty.getLocalPort()) + "/replication";url = new URL(masterUrl);InputStream stream = url.openStream();try {@@ -1012,10 +1011,9 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {String masterUrl;URL url;InputStream stream;- masterUrl = "http://127.0.0.1:" + to.getLocalPort()- + "/solr/replication?wait=true&command=fetchindex&masterUrl=";- masterUrl += "http://127.0.0.1:" + from.getLocalPort()- + "/solr/replication";+ masterUrl = buildUrl(to.getLocalPort())+ + "/replication?wait=true&command=fetchindex&masterUrl="+ + buildUrl(from.getLocalPort()) + "/replication";url = new URL(masterUrl);stream = url.openStream();try {@@ -1329,7 +1327,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {@Overridepublic void run() {String masterUrl =- "http://127.0.0.1:" + masterJetty.getLocalPort() + "/solr/replication?command=" + ReplicationHandler.CMD_BACKUP ++ buildUrl(masterJetty.getLocalPort()) + "/replication?command=" + ReplicationHandler.CMD_BACKUP +(addNumberToKeepInRequest ? "&" + backupKeepParamName + "=1" : "");URL url;InputStream stream = null;@@ -1359,7 +1357,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {}@Overridepublic void run() {- String masterUrl = "http://127.0.0.1:" + masterJetty.getLocalPort() + "/solr/replication?command=" + ReplicationHandler.CMD_DETAILS;+ String masterUrl = buildUrl(masterJetty.getLocalPort()) + "/replication?command=" + ReplicationHandler.CMD_DETAILS;URL url;InputStream stream = null;try {@@ -1525,6 +1523,10 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {fail("timed out waiting for collection1 startAt time to exceed: " + min);return min; // compilation neccessity}++ private static String buildUrl(int port) {+ return buildUrl(port, context);+ }private static class SolrInstance {diff --git a/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java b/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.javaindex dcd3311895b..05e1f8dc7cf 100644--- a/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java+++ b/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java@@ -60,11 +60,6 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {private AtomicInteger id = new AtomicInteger();- static {- // no ssl currently because distrib updates read scheme from zk and no zk in this test- ALLOW_SSL = false;- }-@BeforeClasspublic static void beforeClass() throws Exception {// we can't use the Randomized merge policy because the test depends on@@ -122,7 +117,7 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {getSchemaFile());jettys.add(j);clients.add(createNewSolrServer(j.getLocalPort()));- String shardStr = "127.0.0.1:" + j.getLocalPort() + context;+ String shardStr = buildUrl(j.getLocalPort());shardsArr[i] = shardStr;sb.append(shardStr);}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.javaindex f1541605596..6279df945b3 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java@@ -259,7 +259,7 @@ public class TestLBHttpSolrServer extends SolrTestCaseJ4 {}public String getUrl() {- return "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:" + port + "/solr";+ return buildUrl(port, "/solr");}public String getSchemaFile() {diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.javaindex e356a81bbfa..09567c3807c 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java@@ -93,7 +93,7 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {{try {// setup the server...- String url = "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:"+port+context+"/"+name;+ String url = buildUrl(port, context) + "/" + name;HttpSolrServer s = new HttpSolrServer( url );s.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);s.setDefaultMaxConnectionsPerHost(100);@@ -138,7 +138,7 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {assertEquals( 1, r.process( getSolrCore1() ).getResults().size() );// Distributed- String baseURL = "127.0.0.1:"+port+context+"/";+ String baseURL = buildUrl(port, context) + "/";q = new SolrQuery( "*:*" );q.set( ShardParams.SHARDS, baseURL+"core0,"+baseURL+"core1" );q.set( "fl", "id,s:[shard]" );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 fdc5a984286..b053b81d5b9 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,7 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {public void testConnectionRefused() throws MalformedURLException {int unusedPort = findUnusedPort(); // XXX even if fwe found an unused port// it might not be unused anymore- HttpSolrServer server = new HttpSolrServer("http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:" + unusedPort- + "/solr");+ HttpSolrServer server = new HttpSolrServer(buildUrl(unusedPort, "/solr"));server.setConnectionTimeout(500);SolrQuery q = new SolrQuery("*:*");try {diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.javaindex 6b4316e1754..954cdb90ee5 100644--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java@@ -307,7 +307,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {getSchemaFile());jettys.add(j);clients.add(createNewSolrServer(j.getLocalPort()));- String shardStr = "127.0.0.1:" + j.getLocalPort() + context;+ String shardStr = buildUrl(j.getLocalPort());shardsArr[i] = shardStr;sb.append(shardStr);}@@ -393,9 +393,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {protected SolrServer createNewSolrServer(int port) {try {// setup the server...- String urlScheme = isSSLMode() ? "https" : "http";- String url = urlScheme + "://127.0.0.1:" + port + context;- HttpSolrServer s = new HttpSolrServer(url);+ HttpSolrServer s = new HttpSolrServer(buildUrl(port));s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);s.setSoTimeout(60000);s.setDefaultMaxConnectionsPerHost(100);@@ -406,6 +404,10 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {throw new RuntimeException(ex);}}++ protected String buildUrl(int port) {+ return buildUrl(port, context);+ }protected void addFields(SolrInputDocument doc, Object... fields) {for (int i = 0; i < fields.length; i += 2) {diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex 4db6d80727e..67641a4018b 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -45,6 +45,7 @@ import org.apache.commons.io.FileUtils;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.analysis.MockTokenizer;import org.apache.lucene.index.IndexWriterConfig;+import org.apache.lucene.util.Constants;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.QuickPatchThreadsFilter;@@ -213,13 +214,20 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {}final boolean trySsl = random().nextBoolean();- final boolean trySslClientAuth = random().nextBoolean();+ boolean trySslClientAuth = random().nextBoolean();+ if (Constants.MAC_OS_X) {+ trySslClientAuth = false;+ }log.info("Randomized ssl ({}) and clientAuth ({})", trySsl,trySslClientAuth);return new SSLTestConfig(trySsl, trySslClientAuth);}++ protected static String buildUrl(final int port, final String context) {+ return (isSSLMode() ? "https" : "http") + "://127.0.0.1:" + port + context;+ }protected static MockTokenizer whitespaceMockTokenizer(Reader input) throws IOException {MockTokenizer mockTokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, false);diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.javaindex 44896a8ce25..225fa592fd7 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java@@ -107,7 +107,7 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTesJettySolrRunner j = createJetty(jettyHome, null, "shard" + (i + 2));jettys.add(j);clients.add(createNewSolrServer(j.getLocalPort()));- sb.append("127.0.0.1:").append(j.getLocalPort()).append(context);+ sb.append(buildUrl(j.getLocalPort()));}shards = sb.toString();diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.javaindex 2e97663cf49..2dc7a319019 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java@@ -407,8 +407,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTesJettySolrRunner j = this.jettys.get(i);JettySolrRunner j2 = this.jettys.get(i + (numJettys / 2 - 1));if (sb.length() > 0) sb.append(',');- sb.append("127.0.0.1:").append(j.getLocalPort()).append(context);- sb.append("|127.0.0.1:").append(j2.getLocalPort()).append(context);+ sb.append(buildUrl(j.getLocalPort()));+ sb.append("|").append(buildUrl(j2.getLocalPort()));}shards = sb.toString();@@ -1674,9 +1674,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTesprotected SolrServer createNewSolrServer(int port) {try {// setup the server...- String urlScheme = isSSLMode() ? "https" : "http";- String url = urlScheme + "://127.0.0.1:" + port + context +- (context.endsWith("/") ? "" : "/") + DEFAULT_COLLECTION;+ String baseUrl = buildUrl(port);+ String url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + DEFAULT_COLLECTION;HttpSolrServer s = new HttpSolrServer(url);s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);s.setSoTimeout(60000);