From 26a914558bfdaf62666650694cb2379607e6ca27 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Mon, 5 Aug 2013 18:18:39 +0000 Subject: [PATCH] SOLR-2570: randomize more indexConfig settings in tests git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1510637 13f79535-47bb-0310-9956-ffa450edef68 --- .../solrconfig.snippet.randomindexconfig.xml | 14 +++++++++- .../test/org/apache/solr/core/TestConfig.java | 11 ++++---- .../java/org/apache/solr/SolrTestCaseJ4.java | 27 ++++++++++++++++++- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml index 845753825bd..944777515dd 100644 --- a/solr/core/src/test-files/solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml +++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml @@ -22,6 +22,18 @@ A solrconfig.xml snippet containing indexConfig settings for randomized testing. --> - ${useCompoundFile:false} + + + ${useCompoundFile:false} + + ${solr.tests.maxBufferedDocs} + ${solr.tests.maxIndexingThreads} + ${solr.tests.ramBufferSizeMB} + + + + 1000 + 10000 + single diff --git a/solr/core/src/test/org/apache/solr/core/TestConfig.java b/solr/core/src/test/org/apache/solr/core/TestConfig.java index ef4a5a98102..9ab41846801 100644 --- a/solr/core/src/test/org/apache/solr/core/TestConfig.java +++ b/solr/core/src/test/org/apache/solr/core/TestConfig.java @@ -129,14 +129,15 @@ public class TestConfig extends SolrTestCaseJ4 { // sanity check that sys propertis are working as expected public void testSanityCheckTestSysPropsAreUsed() throws Exception { - final boolean expectCFS - = Boolean.parseBoolean(System.getProperty("useCompoundFile")); SolrConfig sc = new SolrConfig(new SolrResourceLoader("solr/collection1"), "solrconfig-basic.xml", null); SolrIndexConfig sic = sc.indexConfig; - assertEquals("default ramBufferSizeMB", 100.0D, sic.ramBufferSizeMB, 0.0D); - assertEquals("default LockType", SolrIndexConfig.LOCK_TYPE_NATIVE, sic.lockType); - assertEquals("useCompoundFile sysprop", expectCFS, sic.useCompoundFile); + + assertEquals("ramBufferSizeMB sysprop", + Double.parseDouble(System.getProperty("solr.tests.ramBufferSizeMB")), + sic.ramBufferSizeMB, 0.0D); + assertEquals("useCompoundFile sysprop", + Boolean.parseBoolean(System.getProperty("useCompoundFile")), sic.useCompoundFile); } } diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java index 07acea1965d..9204ff6eeeb 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -21,8 +21,11 @@ import com.carrotsearch.randomizedtesting.RandomizedContext; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule; import org.apache.commons.io.FileUtils; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; import org.apache.lucene.util.QuickPatchThreadsFilter; import org.apache.solr.client.solrj.util.ClientUtils; import org.apache.solr.common.SolrException; @@ -112,13 +115,13 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase { private static void beforeClass() { System.setProperty("jetty.testMode", "true"); - System.setProperty("useCompoundFile", Boolean.toString(random().nextBoolean())); System.setProperty("enable.update.log", usually() ? "true" : "false"); System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong())); setupLogging(); startTrackingSearchers(); startTrackingZkClients(); ignoreException("ignore_exception"); + newRandomConfig(); } @AfterClass @@ -181,6 +184,28 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase { h = new TestHarness(loader, ConfigSolr.fromFile(loader, new File(solrHome, "solr.xml"))); lrf = h.getRequestFactory("standard", 0, 20, CommonParams.VERSION, "2.2"); } + + /** sets system properties based on + * {@link #newIndexWriterConfig(org.apache.lucene.util.Version, org.apache.lucene.analysis.Analyzer)} + * + * configs can use these system properties to vary the indexwriter settings + */ + public static void newRandomConfig() { + IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())); + + System.setProperty("useCompoundFile", String.valueOf(iwc.getUseCompoundFile())); + + System.setProperty("solr.tests.maxBufferedDocs", String.valueOf(iwc.getMaxBufferedDocs())); + System.setProperty("solr.tests.ramBufferSizeMB", String.valueOf(iwc.getRAMBufferSizeMB())); + System.setProperty("solr.tests.mergeScheduler", iwc.getMergeScheduler().getClass().getName()); + + // don't ask iwc.getMaxThreadStates(), sometimes newIWC uses + // RandomDocumentsWriterPerThreadPool and all hell breaks loose + int maxIndexingThreads = rarely(random()) + ? _TestUtil.nextInt(random(), 5, 20) // crazy value + : _TestUtil.nextInt(random(), 1, 4); // reasonable value + System.setProperty("solr.tests.maxIndexingThreads", String.valueOf(maxIndexingThreads)); + } @Override public void setUp() throws Exception {