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.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1567643 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2014-02-12 15:11:24 +00:00
parent 9e2995ee01
commit 98810d1f54
14 changed files with 47 additions and 57 deletions

View File

@ -69,8 +69,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
params.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", "*");

View File

@ -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 directories

View File

@ -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()) {

View File

@ -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;

View File

@ -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.

View File

@ -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 {
@Override
public 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 {
}
@Override
public 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 {

View File

@ -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;
}
@BeforeClass
public 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);
}

View File

@ -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() {

View File

@ -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]" );

View File

@ -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 {

View File

@ -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) {

View File

@ -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);

View File

@ -107,7 +107,7 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
JettySolrRunner 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();

View File

@ -407,8 +407,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
JettySolrRunner 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 AbstractDistribZkTes
protected 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);