SOLR-4394: phase 2, promoted SSL randomization logic up to SolrJettyTestBase

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1447885 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2013-02-19 19:52:16 +00:00
parent dc070b4ab8
commit 881c0b21eb
9 changed files with 97 additions and 102 deletions

View File

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

View File

@ -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 bigger
static final int numdocs = 100; //1000 * 1000;

View File

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

View File

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

View File

@ -36,7 +36,7 @@ public class SolrExampleXMLTest extends SolrExampleTests {
@Override
public 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);

View File

@ -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");
}
@BeforeClass
public 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);
}
}
}
@Test
public void testBadSetup()
{

View File

@ -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 often
ConcurrentUpdateSolrServer s = new ConcurrentUpdateSolrServer( url, 2, 5 ) {
public Throwable lastError = null;
@ -79,7 +80,7 @@ public class SolrExampleStreamingTest extends SolrExampleTests {
// SOLR-3903
final List<Throwable> failures = new ArrayList<Throwable>();
ConcurrentUpdateSolrServer s = new ConcurrentUpdateSolrServer
("http://127.0.0.1:"+port+context, 2, 2) {
(jetty.getBaseUrl().toString(), 2, 2) {
@Override
public void handleError(Throwable ex) {
failures.add(ex);

View File

@ -147,8 +147,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {
@Test
public 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 {
@Test
public 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 {
@Test
public 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 {
@Test
public 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 {
@Test
public 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 = false
try {
@ -373,8 +373,8 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {
@Test
public 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 {
@Test
public 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 {
@Test
public 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");

View File

@ -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 SolrTestCaseJ4
jetty = null;
}
server = null;
if (manageSslProps) {
for (String prop : SSL_PROPS.keySet()) {
System.clearProperty(prop);
}
}
}