You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2013/06/03 19:58:01 UTC
svn commit: r1489081 - in /lucene/dev/trunk/solr: ./
solrj/src/test/org/apache/solr/client/solrj/impl/
test-framework/src/java/org/apache/solr/
test-framework/src/java/org/apache/solr/util/
Author: hossman
Date: Mon Jun 3 17:58:01 2013
New Revision: 1489081
URL: http://svn.apache.org/r1489081
Log:
SOLR-4853: Fixed SolrJettyTestBase so it may be reused by end users
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java
lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1489081&r1=1489080&r2=1489081&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Jun 3 17:58:01 2013
@@ -223,6 +223,8 @@ Bug Fixes
* SOLR-4858: SolrCore reloading was broken when the UpdateLog
was enabled. (Hossman, Anshum Gupta, Alexey Serba, Mark Miller, yonik)
+* SOLR-4853: Fixed SolrJettyTestBase so it may be reused by end users
+ (hossman)
Other Changes
----------------------
Modified: lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java?rev=1489081&r1=1489080&r2=1489081&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java (original)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java Mon Jun 3 17:58:01 2013
@@ -495,6 +495,22 @@ public class BasicHttpSolrServerTest ext
client.getConnectionManager().shutdown();
}
+ /**
+ * A trivial test that verifies the example keystore used for SSL testing can be
+ * found using the base class. this helps future-proof against hte possibility of
+ * something moving/breaking thekeystore path in a way that results in the SSL
+ * randomization logic being forced to silently never use SSL. (We can't enforce
+ * this type of check in the base class because then it would not be usable by client
+ * code depending on the test framework
+ */
+ public void testExampleKeystorePath() {
+ assertNotNull("Example keystore is null, meaning that something has changed in the " +
+ "structure of the example configs and/or ExternalPaths.java - " +
+ "SSL randomization is broken",
+ getExampleKeystoreFile());
+ }
+
+
private int findUnusedPort() {
for (int port = 0; port < 65535; port++) {
Socket s = new Socket();
Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java?rev=1489081&r1=1489080&r2=1489081&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java Mon Jun 3 17:58:01 2013
@@ -44,18 +44,32 @@ abstract public class SolrJettyTestBase
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 File TEST_KEYSTORE;
private static final Map<String,String> SSL_PROPS = new HashMap<String,String>();
static {
+ TEST_KEYSTORE = (null == ExternalPaths.SOURCE_HOME)
+ ? null : new File(ExternalPaths.SOURCE_HOME, "example/etc/solrtest.keystore");
+ String keystorePath = null == TEST_KEYSTORE ? null : TEST_KEYSTORE.getAbsolutePath();
+
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.keyStore", keystorePath);
SSL_PROPS.put("javax.net.ssl.keyStorePassword","secret");
- SSL_PROPS.put("javax.net.ssl.trustStore", TEST_KEYSTORE.getAbsolutePath());
+ SSL_PROPS.put("javax.net.ssl.trustStore", keystorePath);
SSL_PROPS.put("javax.net.ssl.trustStorePassword","secret");
}
+ /**
+ * Returns the File object for the example keystore used when this baseclass randomly
+ * uses SSL. May be null ifthis test does not appear to be running as part of the
+ * standard solr distribution and does not have access to the example configs.
+ *
+ * @lucene.internal
+ */
+ protected static File getExampleKeystoreFile() {
+ return TEST_KEYSTORE;
+ }
+
@BeforeClass
public static void beforeSolrJettyTestBase() throws Exception {
@@ -63,20 +77,27 @@ abstract public class SolrJettyTestBase
final boolean trySsl = random().nextBoolean();
final boolean trySslClientAuth = random().nextBoolean();
+ // only randomize SSL if we are a solr test with access to the example keystore
+ if (null == getExampleKeystoreFile()) {
+ log.info("Solr's example keystore not defined (not a solr test?) skipping SSL randomization");
+ manageSslProps = false;
+ return;
+ }
+
+ assertTrue("test keystore does not exist, randomized ssl testing broken: " +
+ getExampleKeystoreFile().getAbsolutePath(),
+ getExampleKeystoreFile().exists() );
+
// 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;
+ return;
}
}
- 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()) {
Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java?rev=1489081&r1=1489080&r2=1489081&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java Mon Jun 3 17:58:01 2013
@@ -25,30 +25,55 @@ import java.io.File;
* @lucene.internal
*/
public class ExternalPaths {
+
+ /**
+ * <p>
+ * The main directory path for the solr source being built if it can be determined. If it
+ * can not be determined -- possily because the current context is a client code base
+ * using hte test frameowrk -- then this variable will be null.
+ * </p>
+ * <p>
+ * Note that all other static paths available in this class are derived from the source
+ * home, and if it is null, those paths will just be relative to 'null' and may not be
+ * meaningful.
+ */
public static final String SOURCE_HOME = determineSourceHome();
+ /* @see #SOURCE_HOME */
public static String WEBAPP_HOME = new File(SOURCE_HOME, "webapp/web").getAbsolutePath();
+ /* @see #SOURCE_HOME */
public static String EXAMPLE_HOME = new File(SOURCE_HOME, "example/solr").getAbsolutePath();
+ /* @see #SOURCE_HOME */
public static String EXAMPLE_MULTICORE_HOME = new File(SOURCE_HOME, "example/multicore").getAbsolutePath();
+ /* @see #SOURCE_HOME */
public static String EXAMPLE_SCHEMA=EXAMPLE_HOME+"/collection1/conf/schema.xml";
+ /* @see #SOURCE_HOME */
public static String EXAMPLE_CONFIG=EXAMPLE_HOME+"/collection1/conf/solrconfig.xml";
+ /**
+ * Ugly, ugly hack to determine the example home without depending on the CWD
+ * this is needed for example/multicore tests which reside outside the classpath.
+ * if the source home can't be determined, this method returns null.
+ */
static String determineSourceHome() {
- // ugly, ugly hack to determine the example home without depending on the CWD
- // this is needed for example/multicore tests which reside outside the classpath
- File file;
try {
- file = new File("solr/conf");
- if (!file.exists()) {
- file = new File(Thread.currentThread().getContextClassLoader().getResource("solr/conf").toURI());
+ File file;
+ try {
+ file = new File("solr/conf");
+ if (!file.exists()) {
+ file = new File(Thread.currentThread().getContextClassLoader().getResource("solr/conf").toURI());
+ }
+ } catch (Exception e) {
+ // If there is no "solr/conf" in the classpath, fall back to searching from the current directory.
+ file = new File(".");
}
- } catch (Exception e) {
- // If there is no "solr/conf" in the classpath, fall back to searching from the current directory.
- file = new File(".");
- }
- File base = file.getAbsoluteFile();
- while (!new File(base, "solr/CHANGES.txt").exists()) {
- base = base.getParentFile();
+ File base = file.getAbsoluteFile();
+ while (!(new File(base, "solr/CHANGES.txt").exists()) && null != base) {
+ base = base.getParentFile();
+ }
+ return (null == base) ? null : new File(base, "solr/").getAbsolutePath();
+ } catch (RuntimeException e) {
+ // all bets are off
+ return null;
}
- return new File(base, "solr/").getAbsolutePath();
}
}