You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/10/29 15:55:07 UTC

svn commit: r1403336 [5/5] - in /lucene/dev/branches/lucene3846: ./ dev-tools/ dev-tools/eclipse/ dev-tools/idea/.idea/libraries/ dev-tools/idea/lucene/classification/ dev-tools/maven/ dev-tools/maven/lucene/classification/ dev-tools/maven/lucene/core/...

Modified: lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java (original)
+++ lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java Mon Oct 29 14:55:01 2012
@@ -19,13 +19,23 @@ package org.apache.solr.update;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexableField;
+import org.apache.lucene.index.AtomicReader;
+import org.apache.lucene.index.SlowCompositeReaderWrapper;
+import org.apache.lucene.search.similarities.DefaultSimilarity;
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.SolrInputField;
 import org.apache.solr.core.SolrCore;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.search.DocList;
 import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.response.ResultContext;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -208,7 +218,7 @@ public class DocumentBuilderTest extends
     assertNull(h.validateUpdate(add(xml, new String[0])));
   }
   
-  public void testMultiValuedFielAndDocBoosts() throws Exception {
+  public void testMultiValuedFieldAndDocBoosts() throws Exception {
     SolrCore core = h.getCore();
     IndexSchema schema = core.getSchema();
     SolrInputDocument doc = new SolrInputDocument();
@@ -234,11 +244,127 @@ public class DocumentBuilderTest extends
     
   }
 
+  public void testCopyFieldsAndFieldBoostsAndDocBoosts() throws Exception {
+    SolrCore core = h.getCore();
+    IndexSchema schema = core.getSchema();
+    SolrInputDocument doc = new SolrInputDocument();
+
+    final float DOC_BOOST = 3.0F;
+    doc.setDocumentBoost(DOC_BOOST);
+    doc.addField("id", "42");
+
+    SolrInputField inTitle = new SolrInputField( "title" );
+    inTitle.addValue( "titleA" , 2.0F ); 
+    inTitle.addValue( "titleB" , 7.0F ); 
+    final float TITLE_BOOST = 2.0F * 7.0F;
+    assertEquals(TITLE_BOOST, inTitle.getBoost(), 0.0F);
+    doc.put( inTitle.getName(), inTitle );
+    
+    SolrInputField inFoo = new SolrInputField( "foo_t" );
+    inFoo.addValue( "summer time" , 1.0F );
+    inFoo.addValue( "in the city" , 5.0F ); 
+    inFoo.addValue( "living is easy" , 11.0F );
+    final float FOO_BOOST = 1.0F * 5.0F * 11.0F;
+    assertEquals(FOO_BOOST, inFoo.getBoost(), 0.0F);
+    doc.put( inFoo.getName(), inFoo );
+
+    Document out = DocumentBuilder.toDocument( doc, core.getSchema() );
+
+    IndexableField[] outTitle = out.getFields( inTitle.getName() );
+    assertEquals("wrong number of title values",
+                 2, outTitle.length);
+
+    IndexableField[] outNoNorms = out.getFields( "title_stringNoNorms" );
+    assertEquals("wrong number of nonorms values",
+                 2, outNoNorms.length);
+
+    IndexableField[] outFoo = out.getFields( inFoo.getName() );
+    assertEquals("wrong number of foo values",
+                 3, outFoo.length);
+
+    IndexableField[] outText = out.getFields( "text" );
+    assertEquals("wrong number of text values",
+                 5, outText.length);
+
+    // since Lucene no longer has native document boosts, we should find
+    // the doc boost multiplied into the boost on the first field value
+    // of each field.  All other field values should be 1.0f
+    // (lucene will multiply all of the field value boosts later)
+    assertEquals(TITLE_BOOST * DOC_BOOST, outTitle[0].boost(), 0.0F);
+    assertEquals(1.0F,                    outTitle[1].boost(), 0.0F);
+    //
+    assertEquals(FOO_BOOST * DOC_BOOST,   outFoo[0].boost(), 0.0F);
+    assertEquals(1.0F,                    outFoo[1].boost(), 0.0F);
+    assertEquals(1.0F,                    outFoo[2].boost(), 0.0F);
+    //
+    assertEquals(TITLE_BOOST * DOC_BOOST, outText[0].boost(), 0.0F);
+    assertEquals(1.0F,                    outText[1].boost(), 0.0F);
+    assertEquals(FOO_BOOST,               outText[2].boost(), 0.0F);
+    assertEquals(1.0F,                    outText[3].boost(), 0.0F);
+    assertEquals(1.0F,                    outText[4].boost(), 0.0F);
+    
+    // copyField dest with no norms should not have recieved any boost
+    assertEquals(1.0F, outNoNorms[0].boost(), 0.0F);
+    assertEquals(1.0F, outNoNorms[1].boost(), 0.0F);
+    
+    // now index that SolrInputDocument to check the computed norms
+
+    assertU(adoc(doc));
+    assertU(commit());
+
+    SolrQueryRequest req = req("q", "id:42");
+    try {
+      // very hack-ish
+
+      SolrQueryResponse rsp = new SolrQueryResponse();
+      core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
+
+      DocList dl = ((ResultContext) rsp.getValues().get("response")).docs;
+      assertTrue("can't find the doc we just added", 1 == dl.size());
+      int docid = dl.iterator().nextDoc();
+
+      SolrIndexSearcher searcher = req.getSearcher();
+      AtomicReader reader = SlowCompositeReaderWrapper.wrap(searcher.getTopReaderContext().reader());
+
+      assertTrue("similarity doesn't extend DefaultSimilarity, " + 
+                 "config or defaults have changed since test was written",
+                 searcher.getSimilarity() instanceof DefaultSimilarity);
+
+      DefaultSimilarity sim = (DefaultSimilarity) searcher.getSimilarity();
+      
+      byte[] titleNorms = (byte[]) reader.normValues("title").getSource().getArray();
+      byte[] fooNorms = (byte[]) reader.normValues("foo_t").getSource().getArray();
+      byte[] textNorms = (byte[]) reader.normValues("text").getSource().getArray();
+
+      assertEquals(expectedNorm(sim, 2, TITLE_BOOST * DOC_BOOST),
+                   titleNorms[docid]);
+
+      assertEquals(expectedNorm(sim, 8-3, FOO_BOOST * DOC_BOOST),
+                   fooNorms[docid]);
+
+      assertEquals(expectedNorm(sim, 2 + 8-3, 
+                                TITLE_BOOST * FOO_BOOST * DOC_BOOST),
+                   textNorms[docid]);
+
+    } finally {
+      req.close();
+    }
+  }
+
   /**
-   * Its not ok to boost a field if it omits norms
+   * Given a length, and boost returns the expected encoded norm 
    */
+  private static byte expectedNorm(final DefaultSimilarity sim,
+                                   final int length, final float boost) {
+    
+    return sim.encodeNormValue(boost / ((float) Math.sqrt(length)));
+
+  }
+    
+
   public void testBoostOmitNorms() throws Exception {
     XmlDoc xml = new XmlDoc();
+    // explicitly boosting a field if that omits norms is not ok
     xml.xml = "<doc>"
         + "<field name=\"id\">ignore_exception</field>"
         + "<field name=\"title_stringNoNorms\" boost=\"3.0\">mytitle</field>"
@@ -249,6 +375,12 @@ public class DocumentBuilderTest extends
     } catch (SolrException expected) {
       // expected exception
     }
+    // boosting a field that is copied to another field that omits norms is ok
+    xml.xml = "<doc>"
+      + "<field name=\"id\">42</field>"
+      + "<field name=\"title\" boost=\"3.0\">mytitle</field>"
+      + "</doc>";
+    assertNull(h.validateUpdate(add(xml, new String[0])));
   }
   
   /**

Modified: lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java (original)
+++ lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/SoftAutoCommitTest.java Mon Oct 29 14:55:01 2012
@@ -32,6 +32,7 @@ import org.apache.solr.core.SolrEventLis
 import org.apache.solr.search.SolrIndexSearcher;
 import org.apache.solr.util.AbstractSolrTestCase;
 import org.junit.Before;
+import org.junit.BeforeClass;
 
 /**
  * Test auto commit functionality in a way that doesn't suck.
@@ -55,10 +56,11 @@ import org.junit.Before;
 @Slow
 public class SoftAutoCommitTest extends AbstractSolrTestCase {
 
-  @Override
-  public String getSchemaFile() { return "schema.xml"; }
-  @Override
-  public String getSolrConfigFile() { return "solrconfig.xml"; }
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    initCore("solrconfig.xml", "schema.xml");
+  }
 
   private MockEventListener monitor;
   private DirectUpdateHandler2 updater;
@@ -77,6 +79,13 @@ public class SoftAutoCommitTest extends 
     updater.registerSoftCommitCallback(monitor);
     updater.registerCommitCallback(monitor);
   }
+  
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    // reset stats
+    h.getCoreContainer().reload("collection1");
+  }
 
   public void testSoftAndHardCommitMaxTimeMixedAdds() throws Exception {
 
@@ -179,7 +188,7 @@ public class SoftAutoCommitTest extends 
   }
 
   public void testSoftAndHardCommitMaxTimeDelete() throws Exception {
-
+    
     final int softCommitWaitMillis = 500;
     final int hardCommitWaitMillis = 1200;
 

Modified: lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java (original)
+++ lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java Mon Oct 29 14:55:01 2012
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.solr.BaseDistributedSearchTestCase;
 import org.apache.solr.client.solrj.SolrQuery;
@@ -38,9 +39,15 @@ import org.apache.solr.common.cloud.ZkSt
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.util.ExecutorUtil;
 import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.core.SolrEventListener;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.servlet.SolrDispatchFilter;
 import org.apache.solr.update.SolrCmdDistributor.Node;
 import org.apache.solr.update.SolrCmdDistributor.Response;
 import org.apache.solr.update.SolrCmdDistributor.StdNode;
+import org.apache.solr.update.processor.DistributedUpdateProcessor;
 import org.apache.solr.util.DefaultSolrThreadFactory;
 
 public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
@@ -92,6 +99,7 @@ public class SolrCmdDistributorTest exte
     SolrCmdDistributor cmdDistrib = new SolrCmdDistributor(5, executor);
     
     ModifiableSolrParams params = new ModifiableSolrParams();
+
     List<Node> nodes = new ArrayList<Node>();
 
     ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP,
@@ -103,12 +111,17 @@ public class SolrCmdDistributorTest exte
     
     AddUpdateCommand cmd = new AddUpdateCommand(null);
     cmd.solrDoc = sdoc("id", 1);
+    params = new ModifiableSolrParams();
+
     cmdDistrib.distribAdd(cmd, nodes, params);
     
     CommitUpdateCommand ccmd = new CommitUpdateCommand(null, false);
+    params = new ModifiableSolrParams();
+    params.set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
     cmdDistrib.distribCommit(ccmd, nodes, params);
     cmdDistrib.finish();
 
+    
     Response response = cmdDistrib.getResponse();
     
     assertEquals(response.errors.toString(), 0, response.errors.size());
@@ -125,18 +138,26 @@ public class SolrCmdDistributorTest exte
     // add another 2 docs to control and 3 to client
     cmdDistrib = new SolrCmdDistributor(5, executor);
     cmd.solrDoc = sdoc("id", 2);
+    params = new ModifiableSolrParams();
+    params.set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
     cmdDistrib.distribAdd(cmd, nodes, params);
     
     AddUpdateCommand cmd2 = new AddUpdateCommand(null);
     cmd2.solrDoc = sdoc("id", 3);
 
+    params = new ModifiableSolrParams();
+    params.set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
     cmdDistrib.distribAdd(cmd2, nodes, params);
     
     AddUpdateCommand cmd3 = new AddUpdateCommand(null);
     cmd3.solrDoc = sdoc("id", 4);
     
+    params = new ModifiableSolrParams();
+    params.set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
     cmdDistrib.distribAdd(cmd3, Collections.singletonList(nodes.get(1)), params);
     
+    params = new ModifiableSolrParams();
+    params.set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
     cmdDistrib.distribCommit(ccmd, nodes, params);
     cmdDistrib.finish();
     response = cmdDistrib.getResponse();
@@ -156,9 +177,18 @@ public class SolrCmdDistributorTest exte
     DeleteUpdateCommand dcmd = new DeleteUpdateCommand(null);
     dcmd.id = "2";
     
+    
+
     cmdDistrib = new SolrCmdDistributor(5, executor);
+    
+    params = new ModifiableSolrParams();
+    params.set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
+    
     cmdDistrib.distribDelete(dcmd, nodes, params);
     
+    params = new ModifiableSolrParams();
+    params.set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
+    
     cmdDistrib.distribCommit(ccmd, nodes, params);
     cmdDistrib.finish();
 
@@ -184,7 +214,7 @@ public class SolrCmdDistributorTest exte
     
     cmdDistrib = new SolrCmdDistributor(5, executor);
     
-    int cnt = atLeast(201);
+    int cnt = atLeast(303);
     for (int i = 0; i < cnt; i++) {
       nodes.clear();
       for (SolrServer c : clients) {
@@ -194,13 +224,13 @@ public class SolrCmdDistributorTest exte
         HttpSolrServer httpClient = (HttpSolrServer) c;
         nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP,
             httpClient.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
-        System.out.println("node props:" + nodeProps);
         nodes.add(new StdNode(new ZkCoreNodeProps(nodeProps)));
 
       }
       AddUpdateCommand c = new AddUpdateCommand(null);
       c.solrDoc = sdoc("id", id++);
       if (nodes.size() > 0) {
+        params = new ModifiableSolrParams();
         cmdDistrib.distribAdd(c, nodes, params);
       }
     }
@@ -214,11 +244,37 @@ public class SolrCmdDistributorTest exte
       
       nodes.add(new StdNode(new ZkCoreNodeProps(nodeProps)));
     }
+    
+    final AtomicInteger commits = new AtomicInteger();
+    for(JettySolrRunner jetty : jettys) {
+      CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter().getFilter()).getCores();
+      SolrCore core = cores.getCore("collection1");
+      try {
+        core.getUpdateHandler().registerCommitCallback(new SolrEventListener() {
+          @Override
+          public void init(NamedList args) {}
+          @Override
+          public void postSoftCommit() {}
+          @Override
+          public void postCommit() {
+            commits.incrementAndGet();
+          }
+          @Override
+          public void newSearcher(SolrIndexSearcher newSearcher,
+              SolrIndexSearcher currentSearcher) {}
+        });
+      } finally {
+        core.close();
+      }
+    }
+    params = new ModifiableSolrParams();
+    params.set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
 
     cmdDistrib.distribCommit(ccmd, nodes, params);
     
-    
     cmdDistrib.finish();
+
+    assertEquals(shardCount, commits.get());
     
     for (SolrServer c : clients) {
       NamedList<Object> resp = c.request(new LukeRequest());

Modified: lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/TestIndexingPerformance.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/TestIndexingPerformance.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/TestIndexingPerformance.java (original)
+++ lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/TestIndexingPerformance.java Mon Oct 29 14:55:01 2012
@@ -17,6 +17,7 @@
 
 package org.apache.solr.update;
 
+import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.schema.IndexSchema;
@@ -41,9 +42,11 @@ public class TestIndexingPerformance ext
   // TODO: fix this test to not require FSDirectory
   static String savedFactory;
   @BeforeClass
-  public static void beforeClass() {
+  public static void beforeClass() throws Exception {
     savedFactory = System.getProperty("solr.DirectoryFactory");
     System.setProperty("solr.directoryFactory", "org.apache.solr.core.MockFSDirectoryFactory");
+
+    initCore("solrconfig_perf.xml", "schema12.xml");
   }
   @AfterClass
   public static void afterClass() {
@@ -56,11 +59,7 @@ public class TestIndexingPerformance ext
 
   public static final Logger log 
     = LoggerFactory.getLogger(TestIndexingPerformance.class);
-
-  @Override
-  public String getSchemaFile() { return "schema12.xml"; }
-  @Override
-  public String getSolrConfigFile() { return "solrconfig_perf.xml"; }
+  
 
   public void testIndexingPerf() throws IOException {
     int iter=1000;

Modified: lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/TestUpdate.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/TestUpdate.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/TestUpdate.java (original)
+++ lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/TestUpdate.java Mon Oct 29 14:55:01 2012
@@ -16,34 +16,12 @@
  */
 package org.apache.solr.update;
 
-
-import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.document.FieldType;
-import org.apache.lucene.index.*;
-import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
-import org.apache.noggit.ObjectBuilder;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrInputDocument;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.util.TestHarness;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import java.io.IOException;
-import java.util.*;
-import java.util.concurrent.*;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import static org.apache.solr.core.SolrCore.verbose;
+import java.util.concurrent.Callable;
 
 public class TestUpdate extends SolrTestCaseJ4 {
   @BeforeClass
@@ -220,6 +198,49 @@ public class TestUpdate extends SolrTest
         ,"=={'doc':{'id':'1', 'val_i':5, 'val_is':[1999999996], 'val2_i':-2000000004, 'val2_f':1.0E20, 'val2_d':-1.2345678901e+100, 'val2_l':4999999996}}"
     );
 
+
+    // remove some fields
+    version = addAndGetVersion(sdoc(
+        "id", "1",
+        "val_is", map("set",null),
+        "val2_f", map("set",null)
+    ),
+        null);
+
+    afterUpdate.call();
+
+    assertJQ(req("qt","/get", "id","1", "fl","id,val*")
+        ,"=={'doc':{'id':'1', 'val_i':5, 'val2_i':-2000000004, 'val2_d':-1.2345678901e+100, 'val2_l':4999999996}}"
+    );
+
+    // test that updating a unique id results in failure.
+    try {
+      ignoreException("Invalid update of id field");
+      version = addAndGetVersion(sdoc(
+          "id", map("set","1"),
+          "val_is", map("inc","2000000000")
+      ),
+          null);
+
+      fail();
+    } catch (SolrException se) {
+      resetExceptionIgnores();
+      assertEquals(400, se.code());
+      assertTrue(se.getMessage().indexOf("Invalid update of id field") >= 0);
+    }
+
+    afterUpdate.call();
+
+    assertJQ(req("qt","/get", "id","1", "fl","id,val*")
+        ,"=={'doc':{'id':'1', 'val_i':5, 'val2_i':-2000000004, 'val2_d':-1.2345678901e+100, 'val2_l':4999999996}}"
+    );
+
+   // nothing should have changed - check with a normal query that we didn't create a duplicate
+    assertU(commit("softCommit","false"));
+    assertJQ(req("q","id:1", "fl","id")
+        ,"/response/numFound==1"
+    );
+
   }
 
 }

Modified: lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/UpdateParamsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/UpdateParamsTest.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/UpdateParamsTest.java (original)
+++ lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/UpdateParamsTest.java Mon Oct 29 14:55:01 2012
@@ -21,21 +21,22 @@ import java.util.HashMap;
 
 import org.apache.solr.common.params.MapSolrParams;
 import org.apache.solr.common.params.UpdateParams;
-import org.apache.solr.core.*;
+import org.apache.solr.core.SolrCore;
 import org.apache.solr.handler.UpdateRequestHandler;
 import org.apache.solr.request.SolrQueryRequestBase;
 import org.apache.solr.response.SolrQueryResponse;
 import org.apache.solr.util.AbstractSolrTestCase;
+import org.junit.BeforeClass;
 
 
 
 public class UpdateParamsTest extends AbstractSolrTestCase {
 
-  @Override
-  public String getSchemaFile() { return "schema.xml"; }
-  @Override
-  public String getSolrConfigFile() { return "solrconfig.xml"; }
-
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    initCore("solrconfig.xml", "schema.xml");
+  }
+  
   /**
    * Tests that only update.chain and not update.processor works (SOLR-2105)
    */

Modified: lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/processor/UpdateRequestProcessorFactoryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/processor/UpdateRequestProcessorFactoryTest.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/processor/UpdateRequestProcessorFactoryTest.java (original)
+++ lucene/dev/branches/lucene3846/solr/core/src/test/org/apache/solr/update/processor/UpdateRequestProcessorFactoryTest.java Mon Oct 29 14:55:01 2012
@@ -17,23 +17,24 @@
 
 package org.apache.solr.update.processor;
 
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.update.processor.UpdateRequestProcessorChain;
-import org.apache.solr.update.processor.CustomUpdateRequestProcessor;
-import org.apache.solr.util.AbstractSolrTestCase;
+import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM;
 
 import java.util.Arrays;
 
-import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.util.AbstractSolrTestCase;
+import org.junit.BeforeClass;
 
 /**
  * 
  */
 public class UpdateRequestProcessorFactoryTest extends AbstractSolrTestCase {
-
-  @Override public String getSchemaFile()     { return "schema.xml"; }
-  @Override public String getSolrConfigFile() { return "solrconfig-transformers.xml"; }
+  
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    initCore("solrconfig-transformers.xml", "schema.xml");
+  }
   
 
   public void testConfiguration() throws Exception 

Modified: lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java (original)
+++ lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java Mon Oct 29 14:55:01 2012
@@ -63,11 +63,12 @@ public class CloudSolrServer extends Sol
   private HttpClient myClient;
   Random rand = new Random();
   
+  private Object cachLock = new Object();
   // since the state shouldn't change often, should be very cheap reads
-  private volatile List<String> urlList;
-  
-  private volatile List<String> leaderUrlList;
-  private volatile List<String> replicasList;
+  private Map<String,List<String>> urlLists = new HashMap<String,List<String>>();
+  private Map<String,List<String>> leaderUrlLists = new HashMap<String,List<String>>();
+
+  private Map<String,List<String>> replicasLists = new HashMap<String,List<String>>();
   
   private volatile int lastClusterStateHashCode;
   
@@ -201,54 +202,65 @@ public class CloudSolrServer extends Sol
 
     Set<String> liveNodes = clusterState.getLiveNodes();
 
-    if (sendToLeaders && leaderUrlList == null || !sendToLeaders && urlList == null || clusterState.hashCode() != this.lastClusterStateHashCode) {
-    
-      // build a map of unique nodes
-      // TODO: allow filtering by group, role, etc
-      Map<String,ZkNodeProps> nodes = new HashMap<String,ZkNodeProps>();
-      List<String> urlList = new ArrayList<String>();
-      for (Slice slice : slices.values()) {
-        for (ZkNodeProps nodeProps : slice.getReplicasMap().values()) {
-          ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(nodeProps);
-          String node = coreNodeProps.getNodeName();
-          if (!liveNodes.contains(coreNodeProps.getNodeName())
-              || !coreNodeProps.getState().equals(ZkStateReader.ACTIVE)) continue;
-          if (nodes.put(node, nodeProps) == null) {
-            if (!sendToLeaders || (sendToLeaders && coreNodeProps.isLeader())) {
-              String url = coreNodeProps.getCoreUrl();
-              urlList.add(url);
-            } else if (sendToLeaders) {
-              String url = coreNodeProps.getCoreUrl();
-              replicas.add(url);
+    List<String> theUrlList;
+    synchronized (cachLock) {
+      List<String> leaderUrlList = leaderUrlLists.get(collection);
+      List<String> urlList = urlLists.get(collection);
+      List<String> replicasList = replicasLists.get(collection);
+
+      if ((sendToLeaders && leaderUrlList == null) || (!sendToLeaders
+          && urlList == null)
+          || clusterState.hashCode() != this.lastClusterStateHashCode) {
+        // build a map of unique nodes
+        // TODO: allow filtering by group, role, etc
+        Map<String,ZkNodeProps> nodes = new HashMap<String,ZkNodeProps>();
+        List<String> urlList2 = new ArrayList<String>();
+        for (Slice slice : slices.values()) {
+          for (ZkNodeProps nodeProps : slice.getReplicasMap().values()) {
+            ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(nodeProps);
+            String node = coreNodeProps.getNodeName();
+            if (!liveNodes.contains(coreNodeProps.getNodeName())
+                || !coreNodeProps.getState().equals(ZkStateReader.ACTIVE)) continue;
+            if (nodes.put(node, nodeProps) == null) {
+              if (!sendToLeaders || (sendToLeaders && coreNodeProps.isLeader())) {
+                String url = coreNodeProps.getCoreUrl();
+                urlList2.add(url);
+              } else if (sendToLeaders) {
+                String url = coreNodeProps.getCoreUrl();
+                replicas.add(url);
+              }
             }
           }
         }
+        if (sendToLeaders) {
+          this.leaderUrlLists.put(collection, urlList2);
+          leaderUrlList = urlList2;
+          this.replicasLists.put(collection, replicas);
+          replicasList = replicas;
+        } else {
+          this.urlLists.put(collection, urlList2);
+          urlList = urlList2;
+        }
+        this.lastClusterStateHashCode = clusterState.hashCode();
       }
+      
       if (sendToLeaders) {
-        this.leaderUrlList = urlList; 
-        this.replicasList = replicas;
+        theUrlList = new ArrayList<String>(leaderUrlList.size());
+        theUrlList.addAll(leaderUrlList);
       } else {
-        this.urlList = urlList;
+        theUrlList = new ArrayList<String>(urlList.size());
+        theUrlList.addAll(urlList);
+      }
+      Collections.shuffle(theUrlList, rand);
+      if (sendToLeaders) {
+        ArrayList<String> theReplicas = new ArrayList<String>(
+            replicasList.size());
+        theReplicas.addAll(replicasList);
+        Collections.shuffle(theReplicas, rand);
+        // System.out.println("leaders:" + theUrlList);
+        // System.out.println("replicas:" + theReplicas);
+        theUrlList.addAll(theReplicas);
       }
-      this.lastClusterStateHashCode = clusterState.hashCode();
-    }
-    
-    List<String> theUrlList;
-    if (sendToLeaders) {
-      theUrlList = new ArrayList<String>(leaderUrlList.size());
-      theUrlList.addAll(leaderUrlList);
-    } else {
-      theUrlList = new ArrayList<String>(urlList.size());
-      theUrlList.addAll(urlList);
-    }
-    Collections.shuffle(theUrlList, rand);
-    if (sendToLeaders) {
-      ArrayList<String> theReplicas = new ArrayList<String>(replicasList.size());
-      theReplicas.addAll(replicasList);
-      Collections.shuffle(theReplicas, rand);
-    //  System.out.println("leaders:" + theUrlList);
-    //  System.out.println("replicas:" + theReplicas);
-      theUrlList.addAll(theReplicas);
     }
  
    // System.out.println("########################## MAKING REQUEST TO " + theUrlList);
@@ -276,15 +288,19 @@ public class CloudSolrServer extends Sol
     return lbServer;
   }
 
-  List<String> getUrlList() {
-    return urlList;
+  // for tests
+  Map<String,List<String>> getUrlLists() {
+    return urlLists;
   }
 
-  List<String> getLeaderUrlList() {
-    return leaderUrlList;
+  //for tests
+  Map<String,List<String>> getLeaderUrlLists() {
+    return leaderUrlLists;
   }
 
-  List<String> getReplicasList() {
-    return replicasList;
+  //for tests
+  Map<String,List<String>> getReplicasLists() {
+    return replicasLists;
   }
+
 }

Modified: lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java (original)
+++ lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java Mon Oct 29 14:55:01 2012
@@ -17,18 +17,20 @@
 
 package org.apache.solr.client.solrj.request;
 
-import java.io.IOException;
-import java.util.Collection;
-
+import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.response.SolrPingResponse;
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.util.ContentStream;
 
+import java.io.IOException;
+import java.util.Collection;
+
 /**
- * 
+ * Verify that there is a working Solr core at the URL of a {@link SolrServer}.
+ * To use this class, the solrconfig.xml for the relevant core must include the
+ * request handler for <code>/admin/ping</code>.
  *
  * @since solr 1.3
  */

Modified: lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java (original)
+++ lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java Mon Oct 29 14:55:01 2012
@@ -70,6 +70,7 @@ public class ClusterState implements JSO
    */
   public ClusterState(Integer zkClusterStateVersion, Set<String> liveNodes,
       Map<String, Map<String,Slice>> collectionStates) {
+    this.zkClusterStateVersion = zkClusterStateVersion;
     this.liveNodes = new HashSet<String>(liveNodes.size());
     this.liveNodes.addAll(liveNodes);
     this.collectionStates = new HashMap<String, Map<String,Slice>>(collectionStates.size());
@@ -117,6 +118,7 @@ public class ClusterState implements JSO
    */
   public Replica getShardProps(final String collection, final String coreNodeName) {
     Map<String, Slice> slices = getSlices(collection);
+    if (slices == null) return null;
     for(Slice slice: slices.values()) {
       if(slice.getReplicasMap().get(coreNodeName)!=null) {
         return slice.getReplicasMap().get(coreNodeName);

Modified: lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java (original)
+++ lucene/dev/branches/lucene3846/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java Mon Oct 29 14:55:01 2012
@@ -186,7 +186,7 @@ public class ZkStateReader {
           if (EventType.None.equals(event.getType())) {
             return;
           }
-          log.info("A cluster state change has occurred - updating...");
+          log.info("A cluster state change has occurred - updating... ({})", ZkStateReader.this.clusterState.getLiveNodes().size());
           try {
             
             // delayed approach
@@ -197,9 +197,13 @@ public class ZkStateReader {
               Stat stat = new Stat();
               byte[] data = zkClient.getData(CLUSTER_STATE, thisWatch, stat ,
                   true);
-              
-              ClusterState clusterState = ClusterState.load(stat.getVersion(), data,
-                  ZkStateReader.this.clusterState.getLiveNodes());
+              List<String> liveNodes = zkClient.getChildren(
+                  LIVE_NODES_ZKNODE, this, true);
+     
+              Set<String> liveNodesSet = new HashSet<String>();
+              liveNodesSet.addAll(liveNodes);
+              Set<String> ln = ZkStateReader.this.clusterState.getLiveNodes();
+              ClusterState clusterState = ClusterState.load(stat.getVersion(), data, ln);
               // update volatile
               ZkStateReader.this.clusterState = clusterState;
             }
@@ -235,13 +239,13 @@ public class ZkStateReader {
               if (EventType.None.equals(event.getType())) {
                 return;
               }
-              log.info("Updating live nodes");
               try {
                 // delayed approach
                 // ZkStateReader.this.updateClusterState(false, true);
                 synchronized (ZkStateReader.this.getUpdateLock()) {
                   List<String> liveNodes = zkClient.getChildren(
                       LIVE_NODES_ZKNODE, this, true);
+                  log.info("Updating live nodes... ({})", liveNodes.size());
                   Set<String> liveNodesSet = new HashSet<String>();
                   liveNodesSet.addAll(liveNodes);
                   ClusterState clusterState = new ClusterState(
@@ -296,14 +300,14 @@ public class ZkStateReader {
           
           clusterState = ClusterState.load(zkClient, liveNodesSet);
         } else {
-          log.info("Updating live nodes from ZooKeeper... ");
+          log.info("Updating live nodes from ZooKeeper... ({})", liveNodesSet.size());
           clusterState = new ClusterState(
               ZkStateReader.this.clusterState.getZkClusterStateVersion(), liveNodesSet,
               ZkStateReader.this.clusterState.getCollectionStates());
         }
+        this.clusterState = clusterState;
       }
 
-      this.clusterState = clusterState;
     } else {
       if (clusterStateUpdateScheduled) {
         log.info("Cloud state update for ZooKeeper already scheduled");
@@ -330,7 +334,7 @@ public class ZkStateReader {
                 clusterState = ClusterState.load(zkClient, liveNodesSet);
               } else {
                 log.info("Updating live nodes from ZooKeeper... ");
-                clusterState = new ClusterState(ZkStateReader.this.clusterState .getZkClusterStateVersion(), liveNodesSet, ZkStateReader.this.clusterState.getCollectionStates());
+                clusterState = new ClusterState(ZkStateReader.this.clusterState.getZkClusterStateVersion(), liveNodesSet, ZkStateReader.this.clusterState.getCollectionStates());
               }
               
               ZkStateReader.this.clusterState = clusterState;

Modified: lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java (original)
+++ lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java Mon Oct 29 14:55:01 2012
@@ -20,6 +20,7 @@ package org.apache.solr.client.solrj;
 import java.io.File;
 import java.io.IOException;
 
+import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
 import org.apache.solr.client.solrj.request.CoreAdminRequest;
 import org.apache.solr.client.solrj.request.QueryRequest;
@@ -28,6 +29,8 @@ import org.apache.solr.common.SolrInputD
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.util.ExternalPaths;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 
 /**
  * Abstract base class for testing merge indexes command
@@ -36,7 +39,6 @@ import org.apache.solr.util.ExternalPath
  *
  */
 public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
-  // protected static final CoreContainer cores = new CoreContainer();
   protected static CoreContainer cores;
   private String saveProp;
   private File dataDir2;
@@ -46,28 +48,30 @@ public abstract class MergeIndexesExampl
     return ExternalPaths.EXAMPLE_MULTICORE_HOME;
   }
 
-  @Override
-  public String getSchemaFile() {
-    return getSolrHome() + "/core0/conf/schema.xml";
+  @BeforeClass
+  public static void beforeClass2() throws Exception {
+    if (dataDir == null) {
+      createTempDir();
+    }
+    cores = new CoreContainer();
   }
-
-  @Override
-  public String getSolrConfigFile() {
-    return getSolrHome() + "/core0/conf/solrconfig.xml";
+  
+  @AfterClass
+  public static void afterClass() {
+    cores.shutdown();
   }
-
+  
   @Override
   public void setUp() throws Exception {
     saveProp = System.getProperty("solr.directoryFactory");
     System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
     super.setUp();
 
-    cores = h.getCoreContainer();
     SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
     cores.setPersistent(false);
     
     // setup datadirs
-    System.setProperty( "solr.core0.data.dir", this.dataDir.getCanonicalPath() ); 
+    System.setProperty( "solr.core0.data.dir", SolrTestCaseJ4.dataDir.getCanonicalPath() ); 
     
     dataDir2 = new File(TEMP_DIR, getClass().getName() + "-"
         + System.currentTimeMillis());
@@ -82,10 +86,10 @@ public abstract class MergeIndexesExampl
     
     String skip = System.getProperty("solr.test.leavedatadir");
     if (null != skip && 0 != skip.trim().length()) {
-      System.err.println("NOTE: per solr.test.leavedatadir, dataDir will not be removed: " + dataDir.getAbsolutePath());
+      System.err.println("NOTE: per solr.test.leavedatadir, dataDir will not be removed: " + dataDir2.getAbsolutePath());
     } else {
-      if (!recurseDelete(dataDir)) {
-        System.err.println("!!!! WARNING: best effort to remove " + dataDir.getAbsolutePath() + " FAILED !!!!!");
+      if (!recurseDelete(dataDir2)) {
+        System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
       }
     }
     

Modified: lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java (original)
+++ lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java Mon Oct 29 14:55:01 2012
@@ -19,16 +19,19 @@ package org.apache.solr.client.solrj;
 
 import java.io.File;
 
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
 import org.apache.solr.client.solrj.request.CoreAdminRequest;
 import org.apache.solr.client.solrj.request.QueryRequest;
 import org.apache.solr.client.solrj.request.UpdateRequest;
-import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
 import org.apache.solr.client.solrj.response.CoreAdminResponse;
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.util.ExternalPaths;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 
@@ -38,18 +41,26 @@ import org.junit.Test;
  */
 public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase 
 {
-  // protected static final CoreContainer cores = new CoreContainer();
-  protected CoreContainer cores;
+  protected static CoreContainer cores;
+
   private File dataDir2;
 
   @Override public String getSolrHome() { return ExternalPaths.EXAMPLE_MULTICORE_HOME; }
+
   
-  @Override public String getSchemaFile()     { return getSolrHome()+"/core0/conf/schema.xml";     }
-  @Override public String getSolrConfigFile() { return getSolrHome()+"/core0/conf/solrconfig.xml"; }
+  @BeforeClass
+  public static void beforeThisClass2() throws Exception {
+    cores = new CoreContainer();
+  }
+  
+  @AfterClass
+  public static void afterClass() {
+    cores.shutdown();
+  }
   
   @Override public void setUp() throws Exception {
     super.setUp();
-    cores = h.getCoreContainer();
+
     SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
     cores.setPersistent(false);
     
@@ -57,7 +68,7 @@ public abstract class MultiCoreExampleTe
         + System.currentTimeMillis());
     dataDir2.mkdirs();
     
-    System.setProperty( "solr.core0.data.dir", this.dataDir.getCanonicalPath() ); 
+    System.setProperty( "solr.core0.data.dir", SolrTestCaseJ4.dataDir.getCanonicalPath() ); 
     System.setProperty( "solr.core1.data.dir", this.dataDir2.getCanonicalPath() ); 
   }
   
@@ -73,8 +84,6 @@ public abstract class MultiCoreExampleTe
         System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
       }
     }
-    
-    cores = null;
   }
 
   @Override
@@ -208,6 +217,12 @@ public abstract class MultiCoreExampleTe
     NamedList<Object> response = getSolrCore("corefoo").query(new SolrQuery().setRequestHandler("/admin/system")).getResponse();
     NamedList<Object> coreInfo = (NamedList<Object>) response.get("core");
     String indexDir = (String) ((NamedList<Object>) coreInfo.get("directory")).get("index");
+    
+    
+
+    System.out.println( (String) ((NamedList<Object>) coreInfo.get("directory")).get("dirimpl"));
+
+    
     // test delete index on core
     CoreAdminRequest.unloadCore("corefoo", true, coreadmin);
     File dir = new File(indexDir);

Modified: lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTestBase.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTestBase.java (original)
+++ lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTestBase.java Mon Oct 29 14:55:01 2012
@@ -19,6 +19,7 @@ package org.apache.solr.client.solrj;
 
 
 import org.apache.solr.util.AbstractSolrTestCase;
+import org.junit.BeforeClass;
 
 /**
  * This should include tests against the example solr config
@@ -32,9 +33,13 @@ abstract public class SolrExampleTestBas
 {
   @Override
   public String getSolrHome() { return "../../../example/solr/"; }
-  
-  @Override public String getSchemaFile()     { return getSolrHome()+"conf/schema.xml";     }
-  @Override public String getSolrConfigFile() { return getSolrHome()+"conf/solrconfig.xml"; }
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    if (dataDir == null) {
+      createTempDir();
+    }
+  }
  
   @Override
   public void setUp() throws Exception

Modified: lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java (original)
+++ lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java Mon Oct 29 14:55:01 2012
@@ -56,7 +56,7 @@ public class MultiCoreExampleJettyTest e
     jetty.start(false);
     port = jetty.getLocalPort();
 
-    h.getCoreContainer().setPersistent(false);    
+    cores.setPersistent(false);    
   }
 
   @Override public void tearDown() throws Exception 

Modified: lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrServerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrServerTest.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrServerTest.java (original)
+++ lucene/dev/branches/lucene3846/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrServerTest.java Mon Oct 29 14:55:01 2012
@@ -25,6 +25,7 @@ import java.util.Set;
 import org.apache.lucene.util.LuceneTestCase.Slow;
 import org.apache.solr.cloud.AbstractFullDistribZkTestBase;
 import org.apache.solr.cloud.AbstractZkTestCase;
+import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.util.ExternalPaths;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -85,12 +86,13 @@ public class CloudSolrServerTest extends
   
   @Override
   public void doTest() throws Exception {
+    assertNotNull(cloudClient);
     
     handle.clear();
     handle.put("QTime", SKIPVAL);
     handle.put("timestamp", SKIPVAL);
     
-    waitForThingsToLevelOut(15);
+    waitForThingsToLevelOut(30);
 
     del("*:*");
 
@@ -99,9 +101,9 @@ public class CloudSolrServerTest extends
     // compare leaders list
     CloudJettyRunner shard1Leader = shardToLeaderJetty.get("shard1");
     CloudJettyRunner shard2Leader = shardToLeaderJetty.get("shard2");
-    assertEquals(2, cloudClient.getLeaderUrlList().size());
+    assertEquals(2, cloudClient.getLeaderUrlLists().get("collection1").size());
     HashSet<String> leaderUrlSet = new HashSet<String>();
-    leaderUrlSet.addAll(cloudClient.getLeaderUrlList());
+    leaderUrlSet.addAll(cloudClient.getLeaderUrlLists().get("collection1"));
     assertTrue("fail check for leader:" + shard1Leader.url + " in "
         + leaderUrlSet, leaderUrlSet.contains(shard1Leader.url + "/"));
     assertTrue("fail check for leader:" + shard2Leader.url + " in "
@@ -120,9 +122,9 @@ public class CloudSolrServerTest extends
     replicas.remove(shard1Leader.url);
     replicas.remove(shard2Leader.url);
     
-    assertEquals(replicas.size(), cloudClient.getReplicasList().size());
+    assertEquals(replicas.size(), cloudClient.getReplicasLists().get("collection1").size());
     
-    for (String url : cloudClient.getReplicasList()) {
+    for (String url : cloudClient.getReplicasLists().get("collection1")) {
       assertTrue("fail check for replica:" + url + " in " + replicas,
           replicas.contains(stripTrailingSlash(url)));
     }
@@ -135,5 +137,17 @@ public class CloudSolrServerTest extends
     }
     return url;
   }
+  
+  
+  protected void indexr(Object... fields) throws Exception {
+    SolrInputDocument doc = getDoc(fields);
+    indexDoc(doc);
+  }
+
+  SolrInputDocument getDoc(Object... fields) throws Exception {
+    SolrInputDocument doc = new SolrInputDocument();
+    addFields(doc, fields);
+    return doc;
+  }
 
 }

Modified: lucene/dev/branches/lucene3846/solr/test-framework/ivy.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/test-framework/ivy.xml?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/test-framework/ivy.xml (original)
+++ lucene/dev/branches/lucene3846/solr/test-framework/ivy.xml Mon Oct 29 14:55:01 2012
@@ -32,8 +32,8 @@
       <dependency org="org.apache.ant" name="ant" rev="1.8.2" transitive="false" />
 
       <dependency org="junit" name="junit" rev="4.10" transitive="false" conf="default->*;junit4-stdalone->*" />
-      <dependency org="com.carrotsearch.randomizedtesting" name="junit4-ant" rev="2.0.3" transitive="false" conf="default->*;junit4-stdalone->*" />
-      <dependency org="com.carrotsearch.randomizedtesting" name="randomizedtesting-runner" rev="2.0.3" transitive="false" conf="default->*;junit4-stdalone->*" />
+      <dependency org="com.carrotsearch.randomizedtesting" name="junit4-ant" rev="2.0.4" transitive="false" conf="default->*;junit4-stdalone->*" />
+      <dependency org="com.carrotsearch.randomizedtesting" name="randomizedtesting-runner" rev="2.0.4" transitive="false" conf="default->*;junit4-stdalone->*" />
 
       <exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/> 
     </dependencies>

Modified: lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java Mon Oct 29 14:55:01 2012
@@ -27,6 +27,7 @@ import org.apache.lucene.util.Constants;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.QuickPatchThreadsFilter;
 import org.apache.noggit.*;
+import org.apache.solr.client.solrj.util.ClientUtils;
 import org.apache.solr.common.*;
 import org.apache.solr.common.cloud.SolrZkClient;
 import org.apache.solr.common.params.*;
@@ -177,6 +178,7 @@ public abstract class SolrTestCaseJ4 ext
   /** Call initCore in @BeforeClass to instantiate a solr core in your test class.
    * deleteCore will be called for you via SolrTestCaseJ4 @AfterClass */
   public static void initCore(String config, String schema, String solrHome) throws Exception {
+    assertNotNull(solrHome);
     configString = config;
     schemaString = schema;
     testSolrHome = solrHome;
@@ -234,8 +236,8 @@ public abstract class SolrTestCaseJ4 ext
      if (endNumOpens-numOpens != endNumCloses-numCloses) {
        String msg = "ERROR: SolrIndexSearcher opens=" + (endNumOpens-numOpens) + " closes=" + (endNumCloses-numCloses);
        log.error(msg);
-       // if its TestReplicationHandler on freebsd, ignore it
-       if ("FreeBSD".equals(Constants.OS_NAME) && "TestReplicationHandler".equals(RandomizedContext.current().getTargetClass().getSimpleName())) {
+       // if its TestReplicationHandler, ignore it. the test is broken and gets no love
+       if ("TestReplicationHandler".equals(RandomizedContext.current().getTargetClass().getSimpleName())) {
          log.warn("TestReplicationHandler wants to fail!: " + msg);
        } else {
          fail(msg);
@@ -377,6 +379,7 @@ public abstract class SolrTestCaseJ4 ext
   }
 
   public static void createCore() {
+    assertNotNull(testSolrHome);
     solrConfig = TestHarness.createConfig(testSolrHome, coreName, getSolrConfigFile());
     h = new TestHarness( dataDir.getAbsolutePath(),
             solrConfig,
@@ -667,14 +670,15 @@ public abstract class SolrTestCaseJ4 ext
    * Generates a simple &lt;add&gt;&lt;doc&gt;... XML String with no options
    */
   public static String adoc(SolrInputDocument sdoc) {
-    List<String> fields = new ArrayList<String>();
-    for (SolrInputField sf : sdoc) {
-      for (Object o : sf.getValues()) {
-        fields.add(sf.getName());
-        fields.add(o.toString());
-      }
+    StringWriter out = new StringWriter(512);
+    try {
+      out.append("<add>");
+      ClientUtils.writeXML(sdoc, out);
+      out.append("</add>");
+    } catch (IOException e) {
+      throw new RuntimeException("Inexplicable IO error from StringWriter", e);
     }
-    return adoc(fields.toArray(new String[fields.size()]));
+    return out.toString();
   }
 
 

Modified: lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java (original)
+++ lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java Mon Oct 29 14:55:01 2012
@@ -44,7 +44,8 @@ public abstract class AbstractDistribZkT
 
   @BeforeClass
   public static void beforeThisClass() throws Exception {
-    useFactory(null);
+    // Only For Manual Testing: this will force an fs based dir factory
+    //useFactory(null);
   }
 
 
@@ -112,7 +113,7 @@ public abstract class AbstractDistribZkT
   
   protected void waitForRecoveriesToFinish(String collection, ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout)
       throws Exception {
-    waitForRecoveriesToFinish(collection, zkStateReader, verbose, failOnTimeout, 600 * (TEST_NIGHTLY ? 2 : 1) * RANDOM_MULTIPLIER);
+    waitForRecoveriesToFinish(collection, zkStateReader, verbose, failOnTimeout, 180 * (TEST_NIGHTLY ? 2 : 1) * RANDOM_MULTIPLIER);
   }
   
   protected void waitForRecoveriesToFinish(String collection,
@@ -150,13 +151,22 @@ public abstract class AbstractDistribZkT
         if (!sawLiveRecovering) {
           if (verbose) System.out.println("no one is recoverying");
         } else {
+          if (verbose) System.out
+          .println("Gave up waiting for recovery to finish..");
           if (failOnTimeout) {
-            fail("There are still nodes recoverying");
+            Map<Thread,StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
+            for (Map.Entry<Thread,StackTraceElement[]>  entry : stackTraces.entrySet()) {
+              System.out.println("");
+              System.out.println(entry.getKey().toString());
+              for (StackTraceElement st : entry.getValue()) {
+                System.out.println(st);
+              }
+            }
             printLayout();
+            fail("There are still nodes recoverying - waited for " + timeoutSeconds + " seconds");
+            // won't get here
             return;
           }
-          if (verbose) System.out
-              .println("gave up waiting for recovery to finish..");
         }
         cont = false;
       } else {

Modified: lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java (original)
+++ lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java Mon Oct 29 14:55:01 2012
@@ -32,6 +32,7 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.lucene.util.LuceneTestCase.Slow;
+import org.apache.solr.BaseDistributedSearchTestCase.RandVal;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
@@ -51,10 +52,12 @@ import org.apache.solr.common.cloud.ZkCo
 import org.apache.solr.common.cloud.ZkNodeProps;
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.zookeeper.KeeperException;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -101,9 +104,9 @@ public abstract class AbstractFullDistri
   protected Map<String,List<CloudJettyRunner>> shardToJetty = new HashMap<String,List<CloudJettyRunner>>();
   private AtomicInteger jettyIntCntr = new AtomicInteger(0);
   protected ChaosMonkey chaosMonkey;
-  protected volatile ZkStateReader zkStateReader;
   
   protected Map<String,CloudJettyRunner> shardToLeaderJetty = new HashMap<String,CloudJettyRunner>();
+  private boolean cloudInit;
   
   public static class CloudJettyRunner {
     public JettySolrRunner jetty;
@@ -195,61 +198,28 @@ public abstract class AbstractFullDistri
   }
   
   protected void initCloud() throws Exception {
-    if (zkStateReader == null) {
-      synchronized (this) {
-        if (zkStateReader != null) {
-          return;
-        }
-        zkStateReader = new ZkStateReader(zkServer.getZkAddress(), 10000,
-            AbstractZkTestCase.TIMEOUT);
-        
-        zkStateReader.createClusterStateWatchersAndUpdate();
-      }
+    assert(cloudInit == false);
+    cloudInit = true;
+    try {
+      CloudSolrServer server = new CloudSolrServer(zkServer.getZkAddress());
+      server.setDefaultCollection(DEFAULT_COLLECTION);
+      server.getLbServer().getHttpClient().getParams()
+          .setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
+      server.getLbServer().getHttpClient().getParams()
+          .setParameter(CoreConnectionPNames.SO_TIMEOUT, 20000);
+      cloudClient = server;
       
-      chaosMonkey = new ChaosMonkey(zkServer, zkStateReader,
-          DEFAULT_COLLECTION, shardToJetty,
-          shardToLeaderJetty);
+      cloudClient.connect();
+    } catch (MalformedURLException e) {
+      throw new RuntimeException(e);
     }
     
-    // wait until shards have started registering...
-    int cnt = 30;
-    while (!zkStateReader.getClusterState().getCollections()
-        .contains(DEFAULT_COLLECTION)) {
-      if (cnt == 0) {
-        throw new RuntimeException("timeout waiting for collection1 in cluster state");
-      }
-      cnt--;
-      Thread.sleep(500);
-    }
-    cnt = 30;
-    while (zkStateReader.getClusterState().getSlices(DEFAULT_COLLECTION).size() != sliceCount) {
-      if (cnt == 0) {
-        throw new RuntimeException("timeout waiting for collection shards to come up");
-      }
-      cnt--;
-      Thread.sleep(500);
-    }
+    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
     
-    // use the distributed solrj client
-    if (cloudClient == null) {
-      synchronized (this) {
-        if (cloudClient != null) {
-          return;
-        }
-        try {
-          CloudSolrServer server = new CloudSolrServer(zkServer.getZkAddress());
-          server.setDefaultCollection(DEFAULT_COLLECTION);
-          server.getLbServer().getHttpClient().getParams()
-              .setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
-          server.getLbServer().getHttpClient().getParams()
-              .setParameter(CoreConnectionPNames.SO_TIMEOUT, 20000);
-          cloudClient = server;
-        } catch (MalformedURLException e) {
-          throw new RuntimeException(e);
-        }
-      }
-    }
+    chaosMonkey = new ChaosMonkey(zkServer, zkStateReader, DEFAULT_COLLECTION,
+        shardToJetty, shardToLeaderJetty);
   }
+
   
   @Override
   protected void createServers(int numServers) throws Exception {
@@ -270,8 +240,31 @@ public abstract class AbstractFullDistri
     } 
     controlClient = createNewSolrServer(controlJetty.getLocalPort());
     
+    initCloud();
+    
     createJettys(numServers, true);
     
+    // wait until shards have started registering...
+    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
+    int cnt = 30;
+    while (!zkStateReader.getClusterState().getCollections()
+        .contains(DEFAULT_COLLECTION)) {
+      if (cnt == 0) {
+        throw new RuntimeException(
+            "timeout waiting for collection1 in cluster state");
+      }
+      cnt--;
+      Thread.sleep(500);
+    }
+    cnt = 30;
+    while (zkStateReader.getClusterState().getSlices(DEFAULT_COLLECTION).size() != sliceCount) {
+      if (cnt == 0) {
+        throw new RuntimeException(
+            "timeout waiting for collection shards to come up");
+      }
+      cnt--;
+      Thread.sleep(500);
+    }
   }
   
   protected List<JettySolrRunner> createJettys(int numJettys) throws Exception {
@@ -302,9 +295,7 @@ public abstract class AbstractFullDistri
       SolrServer client = createNewSolrServer(j.getLocalPort());
       clients.add(client);
     }
-    
-    initCloud();
-    
+  
     this.jettys.addAll(jettys);
     this.clients.addAll(clients);
     
@@ -324,6 +315,7 @@ public abstract class AbstractFullDistri
         Thread.sleep(500);
       }
 
+      ZkStateReader zkStateReader = cloudClient.getZkStateReader();
       // also make sure we have a leader for each shard
       for (int i = 1; i <= sliceCount; i++) {
         zkStateReader.getLeaderProps(DEFAULT_COLLECTION, "shard" + i, 10000);
@@ -346,7 +338,8 @@ public abstract class AbstractFullDistri
   }
 
   protected int getNumShards(String defaultCollection) {
-    Map<String,Slice> slices = this.zkStateReader.getClusterState().getSlices(defaultCollection);
+    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
+    Map<String,Slice> slices = zkStateReader.getClusterState().getSlices(defaultCollection);
     int cnt = 0;
     for (Map.Entry<String,Slice> entry : slices.entrySet()) {
       cnt += entry.getValue().getReplicasMap().size();
@@ -369,6 +362,7 @@ public abstract class AbstractFullDistri
   
   protected void updateMappingsFromZk(List<JettySolrRunner> jettys,
       List<SolrServer> clients) throws Exception {
+    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
     zkStateReader.updateClusterState(true);
     cloudJettys.clear();
     shardToJetty.clear();
@@ -555,11 +549,13 @@ public abstract class AbstractFullDistri
   
   protected void waitForRecoveriesToFinish(boolean verbose)
       throws Exception {
+    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
     super.waitForRecoveriesToFinish(DEFAULT_COLLECTION, zkStateReader, verbose);
   }
   
   protected void waitForRecoveriesToFinish(boolean verbose, int timeoutSeconds)
       throws Exception {
+    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
     super.waitForRecoveriesToFinish(DEFAULT_COLLECTION, zkStateReader, verbose, true, timeoutSeconds);
   }
   
@@ -756,7 +752,7 @@ public abstract class AbstractFullDistri
     String failMessage = null;
     if (verbose) System.err.println("check const of " + shard);
     int cnt = 0;
-    
+    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
     assertEquals(
         "The client count does not match up with the shard count for slice:"
             + shard,
@@ -968,7 +964,7 @@ public abstract class AbstractFullDistri
           }
         }
       }
-      
+      ZkStateReader zkStateReader = cloudClient.getZkStateReader();
       long count = 0;
       String currentState = cjetty.info.getStr(ZkStateReader.STATE_PROP);
       if (currentState != null
@@ -1167,13 +1163,12 @@ public abstract class AbstractFullDistri
     if (VERBOSE || printLayoutOnTearDown) {
       super.printLayout();
     }
-    ((HttpSolrServer) controlClient).shutdown();
+    if (controlClient != null) {
+      ((HttpSolrServer) controlClient).shutdown();
+    }
     if (cloudClient != null) {
       cloudClient.shutdown();
     }
-    if (zkStateReader != null) {
-      zkStateReader.close();
-    }
     super.tearDown();
     
     System.clearProperty("zkHost");
@@ -1186,7 +1181,9 @@ public abstract class AbstractFullDistri
   }
   
   protected void destroyServers() throws Exception {
-    ChaosMonkey.stop(controlJetty);
+    if (controlJetty != null) {
+      ChaosMonkey.stop(controlJetty);
+    }
     for (JettySolrRunner jetty : jettys) {
       try {
         ChaosMonkey.stop(jetty);
@@ -1216,13 +1213,25 @@ public abstract class AbstractFullDistri
   
   protected void waitToSeeNotLive(ZkStateReader zkStateReader,
       CloudJettyRunner cjetty) throws InterruptedException {
+    waitToSeeNotLive(zkStateReader, cjetty, 0);
+  }
+  
+  protected void waitToSeeNotLive(ZkStateReader zkStateReader,
+      CloudJettyRunner cjetty, int cnt) throws InterruptedException {
     int tries = 0;
-    while (zkStateReader.getClusterState()
-        .liveNodesContain(cjetty.info.getStr(ZkStateReader.NODE_NAME_PROP))) {
-      if (tries++ == 220) {
-        fail("Shard still reported as live in zk");
+    ClusterState clusterState = zkStateReader.getClusterState();
+    while (clusterState.liveNodesContain(cjetty.info
+        .getStr(ZkStateReader.NODE_NAME_PROP))) {
+      System.out.println("scs:"
+          + zkStateReader.getClusterState().getZkClusterStateVersion() + " "
+          + zkStateReader.getClusterState().getLiveNodes());
+      System.out.println("see live nodes:"
+          + zkStateReader.getClusterState().getLiveNodes());
+      if (tries++ == 30) {
+        fail("Shard still reported as live in zk - " + cnt + " jetty");
       }
       Thread.sleep(1000);
+      clusterState = zkStateReader.getClusterState();
     }
   }
 }

Modified: lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java (original)
+++ lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java Mon Oct 29 14:55:01 2012
@@ -189,7 +189,7 @@ public class ChaosMonkey {
   }
   
   private static void stopJettySolrRunner(JettySolrRunner jetty) throws Exception {
-    
+    assert(jetty != null);
     monkeyLog("stop shard! " + jetty.getLocalPort());
     // get a clean shutdown so that no dirs are left open...
     FilterHolder fh = jetty.getDispatchFilter();

Modified: lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java (original)
+++ lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java Mon Oct 29 14:55:01 2012
@@ -17,7 +17,6 @@ package org.apache.solr.core;
  * limitations under the License.
  */
 
-import java.io.File;
 import java.io.IOException;
 
 import org.apache.lucene.store.Directory;
@@ -27,7 +26,7 @@ import org.apache.lucene.util.LuceneTest
 /**
  * Opens a directory with {@link LuceneTestCase#newDirectory()}
  */
-public class MockDirectoryFactory extends CachingDirectoryFactory {
+public class MockDirectoryFactory extends EphemeralDirectoryFactory {
 
   @Override
   protected Directory create(String path) throws IOException {
@@ -41,23 +40,13 @@ public class MockDirectoryFactory extend
     if (dir instanceof MockDirectoryWrapper) {
       ((MockDirectoryWrapper)dir).setAssertNoUnrefencedFilesOnClose(false);
     }
-    return dir;
-  }
-  
-  @Override
-  public boolean exists(String path) {
-    String fullPath = new File(path).getAbsolutePath();
-    synchronized (this) {
-      CacheValue cacheValue = byPathCache.get(fullPath);
-      Directory directory = null;
-      if (cacheValue != null) {
-        directory = cacheValue.directory;
-      }
-      if (directory == null) {
-        return false;
-      } else {
-        return true;
-      }
+    
+    // ram dirs in cores that are restarted end up empty
+    // and check index fails
+    if (dir instanceof MockDirectoryWrapper) {
+      ((MockDirectoryWrapper)dir).setCheckIndexOnClose(false);
     }
+    return dir;
   }
+
 }

Modified: lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java (original)
+++ lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java Mon Oct 29 14:55:01 2012
@@ -27,7 +27,7 @@ import org.apache.lucene.util.LuceneTest
 /**
  * Opens a directory with {@link LuceneTestCase#newFSDirectory(File)}
  */
-public class MockFSDirectoryFactory extends CachingDirectoryFactory {
+public class MockFSDirectoryFactory extends StandardDirectoryFactory {
 
   @Override
   public Directory create(String path) throws IOException {

Modified: lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/util/AbstractSolrTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/util/AbstractSolrTestCase.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/util/AbstractSolrTestCase.java (original)
+++ lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/util/AbstractSolrTestCase.java Mon Oct 29 14:55:01 2012
@@ -19,29 +19,18 @@
 package org.apache.solr.util;
 
 
-import java.io.*;
-import java.util.*;
+import java.io.File;
+import java.util.HashSet;
 
-import javax.xml.xpath.XPathExpressionException;
-
-import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.QuickPatchThreadsFilter;
 import org.apache.solr.SolrIgnoredThreadsFilter;
 import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.common.*;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.util.XML;
+import org.apache.solr.common.SolrException;
 import org.apache.solr.core.SolrConfig;
-import org.apache.solr.request.SolrQueryRequest;
-import org.junit.*;
-import org.junit.rules.RuleChain;
-import org.junit.rules.TestRule;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.xml.sax.SAXException;
 
 import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
 
 /**
  * An Abstract base class that makes writing Solr JUnit tests "easier"
@@ -60,39 +49,9 @@ import com.carrotsearch.randomizedtestin
     SolrIgnoredThreadsFilter.class,
     QuickPatchThreadsFilter.class
 })
-public abstract class AbstractSolrTestCase extends LuceneTestCase {
+public abstract class AbstractSolrTestCase extends SolrTestCaseJ4 {
   protected SolrConfig solrConfig;
 
-  /**
-   * Harness initialized by initTestHarness.
-   *
-   * <p>
-   * For use in test methods as needed.
-   * </p>
-   */
-  protected TestHarness h;
-
-  /**
-   * LocalRequestFactory initialized by initTestHarness using sensible
-   * defaults.
-   *
-   * <p>
-   * For use in test methods as needed.
-   * </p>
-   */
-  protected TestHarness.LocalRequestFactory lrf;
-    
-  /**
-   * Subclasses must define this method to return the name of the
-   * schema.xml they wish to use.
-   */
-  public abstract String getSchemaFile();
-    
-  /**
-   * Subclasses must define this method to return the name of the
-   * solrconfig.xml they wish to use.
-   */
-  public abstract String getSolrConfigFile();
 
   /**
    * Subclasses can override this to change a test's solr home
@@ -101,69 +60,9 @@ public abstract class AbstractSolrTestCa
   public String getSolrHome() {
     return SolrTestCaseJ4.TEST_HOME();
   }
-  
-  @ClassRule
-  public static TestRule solrClassRules = 
-    RuleChain.outerRule(new SystemPropertiesRestoreRule())
-             .around(new RevertDefaultThreadHandlerRule());
-
-  @Rule
-  public TestRule solrTestRules = 
-    RuleChain.outerRule(new SystemPropertiesRestoreRule());
-  
-  @BeforeClass
-  public static void beforeClassAbstractSolrTestCase() {
-    SolrTestCaseJ4.startTrackingSearchers();
-  }
-  
-  @AfterClass
-  public static void afterClassAbstractSolrTestCase() {
-    SolrTestCaseJ4.endTrackingSearchers();
-  }
-  
-  /**
-   * The directory used to story the index managed by the TestHarness h
-   */
-  protected File dataDir;
 
   public static Logger log = LoggerFactory.getLogger(AbstractSolrTestCase.class);
 
-  private String factoryProp;
-
-  /**
-   * Initializes things your test might need
-   *
-   * <ul>
-   * <li>Creates a dataDir in the "java.io.tmpdir"</li>
-   * <li>initializes the TestHarness h using this data directory, and getSchemaPath()</li>
-   * <li>initializes the LocalRequestFactory lrf using sensible defaults.</li>
-   * </ul>
-   */
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
-    log.info("####SETUP_START " + getTestName());
-    ignoreException("ignore_exception");
-    factoryProp = System.getProperty("solr.directoryFactory");
-    if (factoryProp == null) {
-      System.setProperty("solr.directoryFactory","solr.RAMDirectoryFactory");
-    }
-    dataDir = new File(TEMP_DIR,
-            getClass().getName() + "-" + System.currentTimeMillis());
-    dataDir.mkdirs();
-    String configFile = getSolrConfigFile();
-    System.setProperty("solr.solr.home", getSolrHome());
-    if (configFile != null) {
-
-      solrConfig = TestHarness.createConfig(getSolrHome(), getSolrConfigFile());
-      h = new TestHarness( dataDir.getAbsolutePath(),
-              solrConfig,
-              getSchemaFile());
-      lrf = h.getRequestFactory
-              ("standard",0,20,CommonParams.VERSION,"2.2");
-    }
-    log.info("####SETUP_END " + getTestName());
-  }
 
     /** Causes an exception matching the regex pattern to not be logged. */
   public static void ignoreException(String pattern) {
@@ -194,146 +93,8 @@ public abstract class AbstractSolrTestCa
     log.info("####PRETEARDOWN " + getTestName());      
   }
 
-  /**
-   * Shuts down the test harness, and makes the best attempt possible
-   * to delete dataDir, unless the system property "solr.test.leavedatadir"
-   * is set.
-   */
-  @Override
-  public void tearDown() throws Exception {
-    log.info("####TEARDOWN_START " + getTestName());
-    if (factoryProp == null) {
-      System.clearProperty("solr.directoryFactory");
-    }
-
-    if (h != null) { h.close(); }
-    String skip = System.getProperty("solr.test.leavedatadir");
-    if (null != skip && 0 != skip.trim().length()) {
-      System.err.println("NOTE: per solr.test.leavedatadir, dataDir will not be removed: " + dataDir.getAbsolutePath());
-    } else {
-      if (!recurseDelete(dataDir)) {
-        System.err.println("!!!! WARNING: best effort to remove " + dataDir.getAbsolutePath() + " FAILED !!!!!");
-      }
-    }
-
-    resetExceptionIgnores();  
-    super.tearDown();
-  }
-
-  /** Validates an update XML String is successful
-   */
-  public void assertU(String update) {
-    assertU(null, update);
-  }
-
-  /** Validates an update XML String is successful
-   */
-  public void assertU(String message, String update) {
-    checkUpdateU(message, update, true);
-  }
-
-  /** Validates an update XML String failed
-   */
-  public void assertFailedU(String update) {
-    assertFailedU(null, update);
-  }
-
-  /** Validates an update XML String failed
-   */
-  public void assertFailedU(String message, String update) {
-    checkUpdateU(message, update, false);
-  }
-
-  /** Checks the success or failure of an update message
-   */
-  private void checkUpdateU(String message, String update, boolean shouldSucceed) {
-    try {
-      String m = (null == message) ? "" : message + " ";
-      if (shouldSucceed) {
-           String res = h.validateUpdate(update);
-         if (res != null) fail(m + "update was not successful: " + res);
-      } else {
-           String res = h.validateErrorUpdate(update);
-         if (res != null) fail(m + "update succeeded, but should have failed: " + res);        
-      }
-    } catch (SAXException e) {
-      throw new RuntimeException("Invalid XML", e);
-    }
-  }
-
-  /** Validates a query matches some XPath test expressions and closes the query */
-  public void assertQ(SolrQueryRequest req, String... tests) {
-    assertQ(null, req, tests);
-  }
-  
-  /** Validates a query matches some XPath test expressions and closes the query */
-  public void assertQ(String message, SolrQueryRequest req, String... tests) {
-    try {
-      String m = (null == message) ? "" : message + " ";
-      String response = h.query(req);
-      String results = h.validateXPath(response, tests);
-      if (null != results) {
-        fail(m + "query failed XPath: " + results +
-             "\n xml response was: " + response +
-             "\n request was: " + req.getParamString());
-      }
-    } catch (XPathExpressionException e1) {
-      throw new RuntimeException("XPath is invalid", e1);
-    } catch (Exception e2) {
-      throw new RuntimeException("Exception during query", e2);
-    }
-  }
-
-  /** Makes sure a query throws a SolrException with the listed response code */
-  public void assertQEx(String message, SolrQueryRequest req, int code ) {
-    try {
-      h.query(req);
-      fail( message );
-    } catch (SolrException sex) {
-      assertEquals( code, sex.code() );
-    } catch (Exception e2) {
-      throw new RuntimeException("Exception during query", e2);
-    }
-  }
-
-  public void assertQEx(String message, SolrQueryRequest req, SolrException.ErrorCode code ) {
-    try {
-      h.query(req);
-      fail( message );
-    } catch (SolrException e) {
-      assertEquals( code.code, e.code() );
-    } catch (Exception e2) {
-      throw new RuntimeException("Exception during query", e2);
-    }
-  }
-
-  
-  /**
-   * @see TestHarness#optimize
-   */
-  public String optimize(String... args) {
-    return TestHarness.optimize(args);
-  }
-  /**
-   * @see TestHarness#commit
-   */
-  public String commit(String... args) {
-    return TestHarness.commit(args);
-  }
 
   /**
-   * Generates a simple &lt;add&gt;&lt;doc&gt;... XML String with no options
-   *
-   * @param fieldsAndValues 0th and Even numbered args are fields names odds are field values.
-   * @see #add
-   * @see #doc
-   */
-  public String adoc(String... fieldsAndValues) {
-    Doc d = doc(fieldsAndValues);
-    return add(d);
-  }
-  
-  /**
    * Generates a simple &lt;add&gt;&lt;doc&gt;... XML String with the
    * commitWithin attribute.
    *
@@ -343,53 +104,10 @@ public abstract class AbstractSolrTestCa
    * @see #doc
    */
   public String adoc(int commitWithin, String... fieldsAndValues) {
-    Doc d = doc(fieldsAndValues);
+    XmlDoc d = doc(fieldsAndValues);
     return add(d, "commitWithin", String.valueOf(commitWithin));
   }
 
-  /**
-   * Generates a simple &lt;add&gt;&lt;doc&gt;... XML String with no options
-   */
-  public String adoc(SolrInputDocument sdoc) {
-    List<String> fields = new ArrayList<String>();
-    for (SolrInputField sf : sdoc) {
-      for (Object o : sf.getValues()) {
-        fields.add(sf.getName());
-        fields.add(o.toString());
-      }
-    }
-    return adoc(fields.toArray(new String[fields.size()]));
-  }
-
-    
-  /**
-   * Generates an &lt;add&gt;&lt;doc&gt;... XML String with options
-   * on the add.
-   *
-   * @param doc the Document to add
-   * @param args 0th and Even numbered args are param names, Odds are param values.
-   * @see #add
-   * @see #doc
-   */
-  public String add(Doc doc, String... args) {
-    try {
-      StringWriter r = new StringWriter();
-            
-      // this is anoying
-      if (null == args || 0 == args.length) {
-        r.write("<add>");
-        r.write(doc.xml);
-        r.write("</add>");
-      } else {
-        XML.writeUnescapedXML(r, "add", doc.xml, (Object[])args);
-      }
-            
-      return r.getBuffer().toString();
-    } catch (IOException e) {
-      throw new RuntimeException
-        ("this should never happen with a StringWriter", e);
-    }
-  }
 
   /**
    * Generates a &lt;delete&gt;... XML string for an ID
@@ -408,49 +126,7 @@ public abstract class AbstractSolrTestCa
   public String delQ(String q, String... args) {
     return TestHarness.deleteByQuery(q, args);
   }
-  
-  /**
-   * Generates a simple &lt;doc&gt;... XML String with no options
-   *
-   * @param fieldsAndValues 0th and Even numbered args are fields names, Odds are field values.
-   * @see TestHarness#makeSimpleDoc
-   */
-  public Doc doc(String... fieldsAndValues) {
-    Doc d = new Doc();
-    d.xml = TestHarness.makeSimpleDoc(fieldsAndValues).toString();
-    return d;
-  }
 
-  /**
-   * Generates a SolrQueryRequest using the LocalRequestFactory
-   * @see #lrf
-   */
-  public SolrQueryRequest req(String... q) {
-    return lrf.makeRequest(q);
-  }
-
-  /**
-   * Generates a SolrQueryRequest using the LocalRequestFactory
-   * @see #lrf
-   */
-  public SolrQueryRequest req(String[] params, String... moreParams) {
-    String[] allParams = moreParams;
-    if (params.length!=0) {
-      int len = params.length + moreParams.length;
-      allParams = new String[len];
-      System.arraycopy(params,0,allParams,0,params.length);
-      System.arraycopy(moreParams,0,allParams,params.length,moreParams.length);
-    }
-
-    return lrf.makeRequest(allParams);
-  }
-
-  /** Neccessary to make method signatures un-ambiguous */
-  public static class Doc {
-    public String xml;
-    @Override
-    public String toString() { return xml; }
-  }
 
   public static boolean recurseDelete(File f) {
     if (f.isDirectory()) {

Modified: lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java?rev=1403336&r1=1403335&r2=1403336&view=diff
==============================================================================
--- lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java (original)
+++ lucene/dev/branches/lucene3846/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java Mon Oct 29 14:55:01 2012
@@ -72,7 +72,7 @@ import java.util.Map;
  */
 public class TestHarness {
   String coreName;
-  protected CoreContainer container;
+  protected volatile CoreContainer container;
   private final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<DocumentBuilder>();
   private final ThreadLocal<XPath> xpathTL = new ThreadLocal<XPath>();
   public UpdateRequestHandler updater;
@@ -124,6 +124,7 @@ public class TestHarness {
   
   public TestHarness(String coreName, CoreContainer.Initializer init) {
     try {
+
       container = init.initialize();
       if (coreName == null)
         coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;