lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1419570 [14/14] - in /lucene/dev/branches/lucene4547: ./ dev-tools/ dev-tools/eclipse/ dev-tools/idea/.idea/libraries/ dev-tools/idea/lucene/analysis/icu/ dev-tools/idea/solr/contrib/dataimporthandler/ dev-tools/maven/ dev-tools/maven/luce...
Date Mon, 10 Dec 2012 16:37:54 GMT
Modified: lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestPseudoReturnFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestPseudoReturnFields.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestPseudoReturnFields.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestPseudoReturnFields.java Mon Dec 10 16:36:47 2012
@@ -58,6 +58,30 @@ public class TestPseudoReturnFields exte
     assertU(adoc("id", "46", "val_i", "3", "ssto", "X", "subject", "ggg"));
     assertU(commit());
   }
+
+  @Test
+  public void testMultiValued() throws Exception {
+    // the response writers used to consult isMultiValued on the field
+    // but this doesn't work when you alias a single valued field to
+    // a multi valued field (the field value is copied first, then
+    // if the type lookup is done again later, we get the wrong thing). SOLR-4036
+
+    assertJQ(req("q","id:42", "fl","val_ss:val_i, val2_ss:10")
+        ,"/response/docs==[{'val2_ss':10,'val_ss':1}]"
+    );
+
+    assertJQ(req("qt","/get", "id","42", "fl","val_ss:val_i, val2_ss:10")
+        ,"/doc=={'val2_ss':10,'val_ss':1}"
+    );
+
+    // also check real-time-get from transaction log
+    assertU(adoc("id", "42", "val_i", "1", "ssto", "X", "subject", "aaa"));
+
+    assertJQ(req("qt","/get", "id","42", "fl","val_ss:val_i, val2_ss:10")
+        ,"/doc=={'val2_ss':10,'val_ss':1}"
+    );
+
+  }
   
   @Test
   public void testAllRealFields() throws Exception {

Modified: lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java Mon Dec 10 16:36:47 2012
@@ -35,6 +35,12 @@ public class TestSolrQueryParser extends
     assertU(adoc("id","1", "text",v,  "text_np",v));
     v="now cow";
     assertU(adoc("id","2", "text",v,  "text_np",v));
+    assertU(adoc("id","3", "foo_s","a ' \" \\ {! ) } ( { z"));  // A value filled with special chars
+
+    assertU(adoc("id","10", "qqq_s","X"));
+    assertU(adoc("id","11", "www_s","X"));
+    assertU(adoc("id","12", "eee_s","X"));
+
     assertU(commit());
   }
 
@@ -49,4 +55,35 @@ public class TestSolrQueryParser extends
         ,"//*[@numFound='2']"
     );
   }
+
+  @Test
+  public void testLocalParamsInQP() throws Exception {
+    assertJQ(req("q","qaz {!term f=text v=$qq} wsx", "qq","now")
+        ,"/response/numFound==2"
+    );
+
+    assertJQ(req("q","qaz {!term f=text v=$qq} wsx", "qq","nomatch")
+        ,"/response/numFound==0"
+    );
+
+    assertJQ(req("q","qaz {!term f=text}now wsx", "qq","now")
+        ,"/response/numFound==2"
+    );
+
+    assertJQ(req("q","qaz {!term f=foo_s v='a \\' \" \\\\ {! ) } ( { z'} wsx")           // single quote escaping
+        ,"/response/numFound==1"
+    );
+
+    assertJQ(req("q","qaz {!term f=foo_s v=\"a ' \\\" \\\\ {! ) } ( { z\"} wsx")         // double quote escaping
+        ,"/response/numFound==1"
+    );
+
+    // double-join to test back-to-back local params
+    assertJQ(req("q","qaz {!join from=www_s to=eee_s}{!join from=qqq_s to=www_s}id:10" )
+        ,"/response/docs/[0]/id=='12'"
+    );
+
+
+  }
+
 }

Modified: lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/TestValueSourceCache.java Mon Dec 10 16:36:47 2012
@@ -17,7 +17,6 @@ package org.apache.solr.search;
  * limitations under the License.
  */
 
-import org.apache.lucene.queryparser.classic.ParseException;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.QueryUtils;
 import org.apache.solr.SolrTestCaseJ4;
@@ -41,14 +40,14 @@ public class TestValueSourceCache extend
     _func = null;
   }
 
-  Query getQuery(String query) throws ParseException {
+  Query getQuery(String query) throws SyntaxError {
     _func.setString(query);
     return _func.parse();
   }
 
   // This is actually also tested by the tests for val_d1 below, but the bug was reported against geodist()...
   @Test
-  public void testGeodistSource() throws ParseException {
+  public void testGeodistSource() throws SyntaxError {
     Query q_home = getQuery("geodist(home_ll, 45.0, 43.0)");
     Query q_work = getQuery("geodist(work_ll, 45.0, 43.0)");
     Query q_home2 = getQuery("geodist(home_ll, 45.0, 43.0)");
@@ -57,7 +56,7 @@ public class TestValueSourceCache extend
   }
 
   @Test
-  public void testNumerics() throws ParseException {
+  public void testNumerics() throws SyntaxError {
     String[] templates = new String[]{
         "sum(#v0, #n0)",
         "product(pow(#v0,#n0),#v1,#n1)",
@@ -94,7 +93,7 @@ public class TestValueSourceCache extend
 
   // This test should will fail because q1 and q3 evaluate as equal unless
   // fixes for bug 2829 are in place.
-  void tryQuerySameTypes(String template, String numbers, String type) throws ParseException {
+  void tryQuerySameTypes(String template, String numbers, String type) throws SyntaxError {
     String s1 = template;
     String s2 = template;
     String s3 = template;
@@ -120,7 +119,7 @@ public class TestValueSourceCache extend
 
   // These should always and forever fail, and would have failed without the fixes for 2829, but why not make
   // some more tests just in case???
-  void tryQueryDiffTypes(String template, String numbers, String[] types) throws ParseException {
+  void tryQueryDiffTypes(String template, String numbers, String[] types) throws SyntaxError {
     String s1 = template;
     String s2 = template;
 

Modified: lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/function/NvlValueSourceParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/function/NvlValueSourceParser.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/function/NvlValueSourceParser.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/search/function/NvlValueSourceParser.java Mon Dec 10 16:36:47 2012
@@ -20,9 +20,9 @@ package org.apache.solr.search.function;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.SimpleFloatFunction;
-import org.apache.lucene.queryparser.classic.ParseException;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.search.FunctionQParser;
+import org.apache.solr.search.SyntaxError;
 import org.apache.solr.search.ValueSourceParser;
 
 /**
@@ -46,7 +46,7 @@ public class NvlValueSourceParser extend
     private float nvlFloatValue = 0.0f;
 
     @Override
-    public ValueSource parse(FunctionQParser fp) throws ParseException {
+    public ValueSource parse(FunctionQParser fp) throws SyntaxError {
       ValueSource source = fp.parseValueSource();
       final float nvl = fp.parseFloat();
 

Modified: lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java Mon Dec 10 16:36:47 2012
@@ -376,7 +376,7 @@ public class SpellCheckCollatorTest exte
   public void testContextSensitiveCollate() throws Exception {
     //                     DirectSolrSpellChecker   IndexBasedSpellChecker
     String[] dictionary = {"direct",                "default_teststop" };
-    for(int i=0 ; i<1 ; i++) {
+    for(int i=0 ; i<=1 ; i++) {
       assertQ(
         req(
           "q", "teststop:(flew AND form AND heathrow)",

Modified: lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/util/DateMathParserTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/util/DateMathParserTest.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/util/DateMathParserTest.java (original)
+++ lucene/dev/branches/lucene4547/solr/core/src/test/org/apache/solr/util/DateMathParserTest.java Mon Dec 10 16:36:47 2012
@@ -329,7 +329,7 @@ public class DateMathParserTest extends 
     for (String command : badCommands.keySet()) {
       try {
         Date out = p.parseMath(command);
-        fail("Didn't generate ParseException for: " + command);
+        fail("Didn't generate SyntaxError for: " + command);
       } catch (ParseException e) {
         assertEquals("Wrong pos for: " + command + " => " + e.getMessage(),
                      badCommands.get(command).intValue(), e.getErrorOffset());

Modified: lucene/dev/branches/lucene4547/solr/example/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/example/build.xml?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/example/build.xml (original)
+++ lucene/dev/branches/lucene4547/solr/example/build.xml Mon Dec 10 16:36:47 2012
@@ -43,7 +43,7 @@
 
        there is probably a cleaner way: but this ensure we have no garbage if jetty is upgraded -->
   <target name="sync-hack">
-    <delete>
+    <delete failonerror="false">
       <fileset dir="lib" includes="*.jar"/>
     </delete>
   </target>

Modified: lucene/dev/branches/lucene4547/solr/example/example-DIH/ivy.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/example/example-DIH/ivy.xml?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/example/example-DIH/ivy.xml (original)
+++ lucene/dev/branches/lucene4547/solr/example/example-DIH/ivy.xml Mon Dec 10 16:36:47 2012
@@ -21,6 +21,7 @@
 
     <dependencies>
       <dependency org="hsqldb" name="hsqldb" rev="1.8.0.10" transitive="false"/>
+      <dependency org="org.apache.derby" name="derby" rev="10.9.1.0" transitive="false"/>
       <exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/> 
     </dependencies>
 </ivy-module>

Modified: lucene/dev/branches/lucene4547/solr/example/ivy.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/example/ivy.xml?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/example/ivy.xml (original)
+++ lucene/dev/branches/lucene4547/solr/example/ivy.xml Mon Dec 10 16:36:47 2012
@@ -16,6 +16,9 @@
    specific language governing permissions and limitations
    under the License.    
 -->
+<!DOCTYPE ivy-module [
+  <!ENTITY jetty.version "8.1.8.v20121106">
+]>
 <ivy-module version="2.0">
     <info organisation="org.apache.solr" module="example"/>
     <configurations>
@@ -25,18 +28,18 @@
     </configurations>
 
     <dependencies>
-      <dependency org="org.eclipse.jetty" name="jetty-continuation" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-deploy" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-http" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-io" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-jmx" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-security" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-server" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-servlet" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-util" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-webapp" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-xml" rev="8.1.7.v20120910" transitive="false" conf="jetty->default"/>
-      <dependency org="org.eclipse.jetty" name="jetty-start" rev="8.1.7.v20120910" transitive="false" conf="start->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-continuation" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-deploy" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-http" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-io" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-jmx" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-security" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-server" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-servlet" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-util" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-webapp" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-xml" rev="&jetty.version;" transitive="false" conf="jetty->default"/>
+      <dependency org="org.eclipse.jetty" name="jetty-start" rev="&jetty.version;" transitive="false" conf="start->default"/>
       <dependency org="org.eclipse.jetty.orbit" name="javax.servlet" rev="3.0.0.v201112011016" transitive="false" conf="servlet->default">
         <artifact name="javax.servlet" type="orbit" ext="jar"/>
       </dependency>

Modified: lucene/dev/branches/lucene4547/solr/example/solr/collection1/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/example/solr/collection1/conf/solrconfig.xml?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/example/solr/collection1/conf/solrconfig.xml (original)
+++ lucene/dev/branches/lucene4547/solr/example/solr/collection1/conf/solrconfig.xml Mon Dec 10 16:36:47 2012
@@ -154,7 +154,7 @@
          before flushing.
          If both ramBufferSizeMB and maxBufferedDocs is set, then
          Lucene will flush based on whichever limit is hit first.  -->
-    <!-- <ramBufferSizeMB>32</ramBufferSizeMB> -->
+    <!-- <ramBufferSizeMB>100</ramBufferSizeMB> -->
     <!-- <maxBufferedDocs>1000</maxBufferedDocs> -->
 
     <!-- Expert: Merge Policy 
@@ -374,7 +374,7 @@
          "dir" - the target directory for transaction logs, defaults to the
             solr data directory.  --> 
     <updateLog>
-      <str name="dir">${solr.data.dir:}</str>
+      <str name="dir">${solr.ulog.dir:}</str>
     </updateLog>
    
 

Modified: lucene/dev/branches/lucene4547/solr/licenses/start.jar.sha1
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/licenses/start.jar.sha1?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/licenses/start.jar.sha1 (original)
+++ lucene/dev/branches/lucene4547/solr/licenses/start.jar.sha1 Mon Dec 10 16:36:47 2012
@@ -1 +1 @@
-b90a67a4f1f6db9e9cea94663e82c320d70e8982
+5f657368cd61ab70babe98bcd6709e199a4829d9

Modified: lucene/dev/branches/lucene4547/solr/solrj/ivy.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/ivy.xml?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/ivy.xml (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/ivy.xml Mon Dec 10 16:36:47 2012
@@ -20,7 +20,7 @@
     <info organisation="org.apache.solr" module="solrj"/>
 
     <dependencies>
-      <dependency org="org.apache.zookeeper" name="zookeeper" rev="3.3.6" transitive="false"/>
+      <dependency org="org.apache.zookeeper" name="zookeeper" rev="3.4.5" transitive="false"/>
       <dependency org="org.slf4j" name="log4j-over-slf4j" rev="1.6.4" transitive="false"/>
       <dependency org="org.apache.httpcomponents" name="httpcore" rev="4.1.4" transitive="false"/>
       <dependency org="org.apache.httpcomponents" name="httpclient" rev="4.1.3" transitive="false"/>

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java Mon Dec 10 16:36:47 2012
@@ -20,6 +20,7 @@ package org.apache.solr.client.solrj.imp
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -195,9 +196,8 @@ public class CloudSolrServer extends Sol
     // Retrieve slices from the cloud state and, for each collection specified,
     // add it to the Map of slices.
     Map<String,Slice> slices = new HashMap<String,Slice>();
-    for (int i = 0; i < collectionList.size(); i++) {
-      String coll= collectionList.get(i);
-      ClientUtils.appendMap(coll, slices, clusterState.getSlices(coll));
+    for (String collectionName : collectionList) {
+      ClientUtils.addSlices(slices, collectionName, clusterState.getSlices(collectionName), true);
     }
 
     Set<String> liveNodes = clusterState.getLiveNodes();

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java Mon Dec 10 16:36:47 2012
@@ -242,15 +242,13 @@ public class ClientUtils 
     catch (IOException e) {throw new RuntimeException(e);}  // can't happen
     return sb.toString();
   }
-  
-  public static void appendMap(String collection, Map<String,Slice> map1, Map<String,Slice> map2) {
-    if (map1==null)
-      map1 = new HashMap<String,Slice>();
-    if (map2!=null) {
-      Set<Entry<String,Slice>> entrySet = map2.entrySet();
-      for (Entry<String,Slice> entry : entrySet) {
-        map1.put(collection + "_" + entry.getKey(), entry.getValue());
-      }
+
+  /** Constructs a slices map from a collection of slices and handles disambiguation if multiple collections are being queried simultaneously */
+  public static void addSlices(Map<String,Slice> target, String collectionName, Collection<Slice> slices, boolean multiCollection) {
+    for (Slice slice : slices) {
+      String key = slice.getName();
+      if (multiCollection) key = collectionName + "_" + key;
+      target.put(key, slice);
     }
   }
 }

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java Mon Dec 10 16:36:47 2012
@@ -18,6 +18,7 @@ package org.apache.solr.common.cloud;
  */
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -30,7 +31,7 @@ import java.util.Set;
 import org.apache.noggit.JSONWriter;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.cloud.HashPartitioner.Range;
+import org.apache.solr.common.cloud.DocRouter.Range;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.data.Stat;
 import org.slf4j.Logger;
@@ -39,21 +40,17 @@ import org.slf4j.LoggerFactory;
 /**
  * Immutable state of the cloud. Normally you can get the state by using
  * {@link ZkStateReader#getClusterState()}.
+ * @lucene.experimental
  */
 public class ClusterState implements JSONWriter.Writable {
   private static Logger log = LoggerFactory.getLogger(ClusterState.class);
   
   private Integer zkClusterStateVersion;
   
-  private final Map<String, Map<String,Slice>> collectionStates;  // Map<collectionName, Map<sliceName,Slice>>
+  private final Map<String, DocCollection> collectionStates;  // Map<collectionName, Map<sliceName,Slice>>
   private final Set<String> liveNodes;
-  
-  private final HashPartitioner hp = new HashPartitioner();
-  
-  private final Map<String,RangeInfo> rangeInfos = new HashMap<String,RangeInfo>();
-  private final Map<String,Map<String,ZkNodeProps>> leaders = new HashMap<String,Map<String,ZkNodeProps>>();
-
 
+  private final Map<String,RangeInfo> rangeInfos = new HashMap<String,RangeInfo>();
   
   /**
    * Use this constr when ClusterState is meant for publication.
@@ -61,7 +58,7 @@ public class ClusterState implements JSO
    * hashCode and equals will only depend on liveNodes and not clusterStateVersion.
    */
   public ClusterState(Set<String> liveNodes,
-      Map<String, Map<String,Slice>> collectionStates) {
+      Map<String, DocCollection> collectionStates) {
     this(null, liveNodes, collectionStates);
   }
   
@@ -69,60 +66,41 @@ public class ClusterState implements JSO
    * Use this constr when ClusterState is meant for consumption.
    */
   public ClusterState(Integer zkClusterStateVersion, Set<String> liveNodes,
-      Map<String, Map<String,Slice>> collectionStates) {
+      Map<String, DocCollection> 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());
+    this.collectionStates = new HashMap<String, DocCollection>(collectionStates.size());
     this.collectionStates.putAll(collectionStates);
     addRangeInfos(collectionStates.keySet());
-    getShardLeaders();
   }
 
-  private void getShardLeaders() {
-    Set<Entry<String,Map<String,Slice>>> collections = collectionStates.entrySet();
-    for (Entry<String,Map<String,Slice>> collection : collections) {
-      Map<String,Slice> state = collection.getValue();
-      Set<Entry<String,Slice>> slices = state.entrySet();
-      for (Entry<String,Slice> sliceEntry : slices) {
-        Slice slice = sliceEntry.getValue();
-        Map<String,Replica> shards = slice.getReplicasMap();
-        Set<Entry<String,Replica>> shardsEntries = shards.entrySet();
-        for (Entry<String,Replica> shardEntry : shardsEntries) {
-          ZkNodeProps props = shardEntry.getValue();
-          if (props.containsKey(ZkStateReader.LEADER_PROP)) {
-            Map<String,ZkNodeProps> leadersForCollection = leaders.get(collection.getKey());
-            if (leadersForCollection == null) {
-              leadersForCollection = new HashMap<String,ZkNodeProps>();
-              leaders.put(collection.getKey(), leadersForCollection);
-            }
-            leadersForCollection.put(sliceEntry.getKey(), props);
-            break; // we found the leader for this shard
-          }
-        }
-      }
-    }
-  }
 
   /**
-   * Get properties of a shard leader for specific collection.
+   * Get properties of a shard/slice leader for specific collection, or null if one currently doesn't exist.
    */
-  public ZkNodeProps getLeader(String collection, String shard) {
-    Map<String,ZkNodeProps> collectionLeaders = leaders.get(collection);
-    if (collectionLeaders == null) return null;
-    return collectionLeaders.get(shard);
+  public Replica getLeader(String collection, String sliceName) {
+    DocCollection coll = collectionStates.get(collection);
+    if (coll == null) return null;
+    Slice slice = coll.getSlice(sliceName);
+    if (slice == null) return null;
+    return slice.getLeader();
   }
   
   /**
-   * Get shard properties or null if shard is not found.
-   */
-  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);
-      }
+   * Get replica properties (if the slice is unknown) or null if replica is not found.
+   * If the slice is known, do not use this method.
+   * coreNodeName is the same as replicaName
+   */
+  public Replica getReplica(final String collection, final String coreNodeName) {
+    return getReplica(collectionStates.get(collection), coreNodeName);
+  }
+
+  private Replica getReplica(DocCollection coll, String replicaName) {
+    if (coll == null) return null;
+    for(Slice slice: coll.getSlices()) {
+      Replica replica = slice.getReplica(replicaName);
+      if (replica != null) return replica;
     }
     return null;
   }
@@ -134,22 +112,35 @@ public class ClusterState implements JSO
   }
 
   /**
-   * Get the index Slice for collection.
+   * Get the Slice for collection.
    */
-  public Slice getSlice(String collection, String slice) {
-    if (collectionStates.containsKey(collection)
-        && collectionStates.get(collection).containsKey(slice))
-      return collectionStates.get(collection).get(slice);
-    return null;
+  public Slice getSlice(String collection, String sliceName) {
+    DocCollection coll = collectionStates.get(collection);
+    if (coll == null) return null;
+    return coll.getSlice(sliceName);
+  }
+
+  public Map<String, Slice> getSlicesMap(String collection) {
+    DocCollection coll = collectionStates.get(collection);
+    if (coll == null) return null;
+    return coll.getSlicesMap();
+  }
+
+  public Collection<Slice> getSlices(String collection) {
+    DocCollection coll = collectionStates.get(collection);
+    if (coll == null) return null;
+    return coll.getSlices();
   }
 
   /**
-   * Get all slices for collection.
+   * Get the named DocCollection object, or throw an exception if it doesn't exist.
    */
-  public Map<String, Slice> getSlices(String collection) {
-    if(!collectionStates.containsKey(collection))
-      return null;
-    return Collections.unmodifiableMap(collectionStates.get(collection));
+  public DocCollection getCollection(String collection) {
+    DocCollection coll = collectionStates.get(collection);
+    if (coll == null) {
+      throw new SolrException(ErrorCode.BAD_REQUEST, "Could not find collection:" + collection);
+    }
+    return coll;
   }
 
   /**
@@ -162,7 +153,7 @@ public class ClusterState implements JSO
   /**
    * @return Map&lt;collectionName, Map&lt;sliceName,Slice&gt;&gt;
    */
-  public Map<String, Map<String, Slice>> getCollectionStates() {
+  public Map<String, DocCollection> getCollectionStates() {
     return Collections.unmodifiableMap(collectionStates);
   }
 
@@ -174,17 +165,14 @@ public class ClusterState implements JSO
   }
 
   /**
-   * Get shardId for core.
-   * @param coreNodeName in the form of nodeName_coreName
+   * Get the slice/shardId for a core.
+   * @param coreNodeName in the form of nodeName_coreName (the name of the replica)
    */
   public String getShardId(String coreNodeName) {
-    for (Entry<String, Map<String, Slice>> states: collectionStates.entrySet()){
-      for(Entry<String, Slice> slices: states.getValue().entrySet()) {
-        for(Entry<String, Replica> shards: slices.getValue().getReplicasMap().entrySet()){
-          if(coreNodeName.equals(shards.getKey())) {
-            return slices.getKey();
-          }
-        }
+     // System.out.println("###### getShardId("+coreNodeName+") in " + collectionStates);
+    for (DocCollection coll : collectionStates.values()) {
+      for (Slice slice : coll.getSlices()) {
+        if (slice.getReplicasMap().containsKey(coreNodeName)) return slice.getName();
       }
     }
     return null;
@@ -209,19 +197,14 @@ public class ClusterState implements JSO
     RangeInfo rangeInfo;
     rangeInfo = new RangeInfo();
 
-    Map<String,Slice> slices = getSlices(collection);
-    
-    if (slices == null) {
-      throw new SolrException(ErrorCode.BAD_REQUEST, "Can not find collection "
-          + collection + " in " + this);
-    }
+    DocCollection coll = getCollection(collection);
     
-    Set<String> shards = slices.keySet();
+    Set<String> shards = coll.getSlicesMap().keySet();
     ArrayList<String> shardList = new ArrayList<String>(shards.size());
     shardList.addAll(shards);
     Collections.sort(shardList);
     
-    ranges = hp.partitionRange(shards.size(), Integer.MIN_VALUE, Integer.MAX_VALUE);
+    ranges = DocRouter.DEFAULT.partitionRange(shards.size(), Integer.MIN_VALUE, Integer.MAX_VALUE);
     
     rangeInfo.ranges = ranges;
     rangeInfo.shardList = shardList;
@@ -229,23 +212,6 @@ public class ClusterState implements JSO
     return rangeInfo;
   }
 
-  /**
-   * Get shard id for hash. This is used when determining which Slice the
-   * document is to be submitted to.
-   */
-  public String getShard(int hash, String collection) {
-    RangeInfo rangInfo = getRanges(collection);
-    
-    int cnt = 0;
-    for (Range range : rangInfo.ranges) {
-      if (range.includes(hash)) {
-        return rangInfo.shardList.get(cnt);
-      }
-      cnt++;
-    }
-    
-    throw new IllegalStateException("The HashPartitioner failed");
-  }
 
   @Override
   public String toString() {
@@ -278,24 +244,46 @@ public class ClusterState implements JSO
    * @return the ClusterState
    */
   public static ClusterState load(Integer version, byte[] bytes, Set<String> liveNodes) {
+    // System.out.println("######## ClusterState.load:" + (bytes==null ? null : new String(bytes)));
     if (bytes == null || bytes.length == 0) {
-      return new ClusterState(version, liveNodes, Collections.<String, Map<String,Slice>>emptyMap());
+      return new ClusterState(version, liveNodes, Collections.<String, DocCollection>emptyMap());
+    }
+    Map<String, Object> stateMap = (Map<String, Object>) ZkStateReader.fromJSON(bytes);
+    Map<String,DocCollection> collections = new LinkedHashMap<String,DocCollection>(stateMap.size());
+    for (Entry<String, Object> entry : stateMap.entrySet()) {
+      String collectionName = entry.getKey();
+      DocCollection coll = collectionFromObjects(collectionName, (Map<String,Object>)entry.getValue());
+      collections.put(collectionName, coll);
     }
-    // System.out.println("########## Loading ClusterState:" + new String(bytes));
-    LinkedHashMap<String, Object> stateMap = (LinkedHashMap<String, Object>) ZkStateReader.fromJSON(bytes);
-    HashMap<String,Map<String, Slice>> state = new HashMap<String,Map<String,Slice>>();
-
-    for(String collectionName: stateMap.keySet()){
-      Map<String, Object> collection = (Map<String, Object>)stateMap.get(collectionName);
-      Map<String, Slice> slices = new LinkedHashMap<String,Slice>();
-
-      for (Entry<String,Object> sliceEntry : collection.entrySet()) {
-        Slice slice = new Slice(sliceEntry.getKey(), null, (Map<String,Object>)sliceEntry.getValue());
-        slices.put(slice.getName(), slice);
+
+    // System.out.println("######## ClusterState.load result:" + collections);
+    return new ClusterState(version, liveNodes, collections);
+  }
+
+  private static DocCollection collectionFromObjects(String name, Map<String,Object> objs) {
+    Map<String,Object> props = (Map<String,Object>)objs.get(DocCollection.PROPERTIES);
+    if (props == null) props = Collections.emptyMap();
+    DocRouter router = DocRouter.getDocRouter(props.get(DocCollection.DOC_ROUTER));
+    Map<String,Slice> slices = makeSlices(objs);
+    return new DocCollection(name, slices, props, router);
+  }
+
+  private static Map<String,Slice> makeSlices(Map<String,Object> genericSlices) {
+    if (genericSlices == null) return Collections.emptyMap();
+    Map<String,Slice> result = new LinkedHashMap<String, Slice>(genericSlices.size());
+    for (Map.Entry<String,Object> entry : genericSlices.entrySet()) {
+      String name = entry.getKey();
+      if (DocCollection.PROPERTIES.equals(name)) continue;  // skip special properties entry
+      Object val = entry.getValue();
+      Slice s;
+      if (val instanceof Slice) {
+        s = (Slice)val;
+      } else {
+        s = new Slice(name, null, (Map<String,Object>)val);
       }
-      state.put(collectionName, slices);
+      result.put(name, s);
     }
-    return new ClusterState(version, liveNodes, state);
+    return result;
   }
 
   @Override

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java Mon Dec 10 16:36:47 2012
@@ -24,11 +24,12 @@ import java.util.Map;
 
 public class Replica extends ZkNodeProps {
   private final String name;
+  private final String nodeName;
 
   public Replica(String name, Map<String,Object> propMap) {
     super(propMap);
     this.name = name;
-    String nodeName = (String)propMap.get(ZkStateReader.NODE_NAME_PROP);
+    nodeName = (String)propMap.get(ZkStateReader.NODE_NAME_PROP);
     assert nodeName == null || name.startsWith(nodeName);
   }
 
@@ -36,9 +37,13 @@ public class Replica extends ZkNodeProps
     return name;
   }
 
+  /** The name of the node this replica resides on */
+  public String getNodeName() {
+    return nodeName;
+  }
+
   @Override
   public String toString() {
     return name + ':' + JSONUtil.toJSON(propMap, -1); // small enough, keep it on one line (i.e. no indent)
   }
-
 }

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java Mon Dec 10 16:36:47 2012
@@ -34,7 +34,7 @@ public class Slice extends ZkNodeProps {
   public static String LEADER = "leader";       // FUTURE: do we want to record the leader as a slice property in the JSON (as opposed to isLeader as a replica property?)
 
   private final String name;
-  private final HashPartitioner.Range range;
+  private final DocRouter.Range range;
   private final Integer replicationFactor;
   private final Map<String,Replica> replicas;
   private final Replica leader;
@@ -49,15 +49,21 @@ public class Slice extends ZkNodeProps {
     this.name = name;
 
     Object rangeObj = propMap.get(RANGE);
-    HashPartitioner.Range tmpRange = null;
-    if (rangeObj instanceof HashPartitioner.Range) {
-      tmpRange = (HashPartitioner.Range)rangeObj;
+    DocRouter.Range tmpRange = null;
+    if (rangeObj instanceof DocRouter.Range) {
+      tmpRange = (DocRouter.Range)rangeObj;
     } else if (rangeObj != null) {
-      HashPartitioner hp = new HashPartitioner();
-      tmpRange = hp.fromString(rangeObj.toString());
+      // Doesn't support custom implementations of Range, but currently not needed.
+      tmpRange = DocRouter.DEFAULT.fromString(rangeObj.toString());
     }
     range = tmpRange;
 
+    /** debugging.  this isn't an error condition for custom sharding.
+    if (range == null) {
+      System.out.println("###### NO RANGE for " + name + " props=" + props);
+    }
+    **/
+
     replicationFactor = null;  // future
 
     // add the replicas *after* the other properties (for aesthetics, so it's easy to find slice properties in the JSON output)
@@ -121,6 +127,14 @@ public class Slice extends ZkNodeProps {
     return leader;
   }
 
+  public Replica getReplica(String replicaName) {
+    return replicas.get(replicaName);
+  }
+
+  public DocRouter.Range getRange() {
+    return range;
+  }
+
   @Override
   public String toString() {
     return name + ':' + JSONUtil.toJSON(propMap);

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java Mon Dec 10 16:36:47 2012
@@ -112,14 +112,14 @@ public class SolrZkClient {
           });
     } catch (Throwable e) {
       connManager.close();
-      throw new RuntimeException();
+      throw new RuntimeException(e);
     }
     
     try {
       connManager.waitForConnected(clientConnectTimeout);
     } catch (Throwable e) {
       connManager.close();
-      throw new RuntimeException();
+      throw new RuntimeException(e);
     }
     numOpens.incrementAndGet();
   }
@@ -590,6 +590,8 @@ public class SolrZkClient {
       return;
     }
     for (String string : children) {
+      // we can't clean the built-in zookeeper node
+      if (path.equals("/") && string.equals("zookeeper")) continue;
       if (path.equals("/")) {
         clean(path + string);
       } else {

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java Mon Dec 10 16:36:47 2012
@@ -19,7 +19,8 @@ package org.apache.solr.common.cloud;
 
 import java.io.IOException;
 import java.lang.reflect.Field;
-import java.nio.channels.SelectionKey;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
 
@@ -60,11 +61,12 @@ public class SolrZooKeeper extends ZooKe
               sendThreadFld.setAccessible(true);
               Object sendThread = sendThreadFld.get(cnxn);
               if (sendThread != null) {
-                final Field sockKeyFld = sendThread.getClass().getDeclaredField("sockKey");
-                sockKeyFld.setAccessible(true);
-                final SelectionKey sockKey = (SelectionKey) sockKeyFld.get(sendThread);
-                if (sockKey != null) {
-                  sockKey.channel().close();
+                Method method = sendThread.getClass().getDeclaredMethod("testableCloseSocket");
+                method.setAccessible(true);
+                try {
+                  method.invoke(sendThread);
+                } catch (InvocationTargetException e) {
+                  // is fine
                 }
               }
             } catch (Exception e) {

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java Mon Dec 10 16:36:47 2012
@@ -39,6 +39,8 @@ public class ZkNodeProps implements JSON
    */
   public ZkNodeProps(Map<String,Object> propMap) {
     this.propMap = propMap;
+    // TODO: store an unmodifiable map, but in a way that guarantees not to wrap more than once.
+    // Always wrapping introduces a memory leak.
   }
 
 
@@ -70,14 +72,14 @@ public class ZkNodeProps implements JSON
    * Get property keys.
    */
   public Set<String> keySet() {
-    return Collections.unmodifiableSet(propMap.keySet());
+    return propMap.keySet();
   }
 
   /**
    * Get all properties as map.
    */
   public Map<String, Object> getProperties() {
-    return Collections.unmodifiableMap(propMap);
+    return propMap;
   }
 
   /** Returns a shallow writable copy of the properties */

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java Mon Dec 10 16:36:47 2012
@@ -186,7 +186,7 @@ public class ZkStateReader {
           if (EventType.None.equals(event.getType())) {
             return;
           }
-          log.info("A cluster state change has occurred - updating... ({})", ZkStateReader.this.clusterState.getLiveNodes().size());
+          log.info("A cluster state change: {}, has occurred - updating... (live nodes size: {})", (event) , ZkStateReader.this.clusterState == null ? 0 : ZkStateReader.this.clusterState.getLiveNodes().size());
           try {
             
             // delayed approach
@@ -397,19 +397,22 @@ public class ZkStateReader {
   }
   
   /**
-   * Get shard leader properties.
+   * Get shard leader properties, with retry if none exist.
    */
-  public ZkNodeProps getLeaderProps(String collection, String shard) throws InterruptedException {
+  public Replica getLeaderProps(String collection, String shard) throws InterruptedException {
     return getLeaderProps(collection, shard, 1000);
   }
-  
-  public ZkNodeProps getLeaderProps(String collection, String shard, int timeout) throws InterruptedException {
+
+  /**
+   * Get shard leader properties, with retry if none exist.
+   */
+  public Replica getLeaderProps(String collection, String shard, int timeout) throws InterruptedException {
     long timeoutAt = System.currentTimeMillis() + timeout;
     while (System.currentTimeMillis() < timeoutAt) {
       if (clusterState != null) {    
-        final ZkNodeProps nodeProps = clusterState.getLeader(collection, shard);
-        if (nodeProps != null) {
-          return nodeProps;
+        Replica replica = clusterState.getLeader(collection, shard);
+        if (replica != null && getClusterState().liveNodesContain(replica.getNodeName())) {
+          return replica;
         }
       }
       Thread.sleep(50);
@@ -450,7 +453,7 @@ public class ZkStateReader {
     if (clusterState == null) {
       return null;
     }
-    Map<String,Slice> slices = clusterState.getSlices(collection);
+    Map<String,Slice> slices = clusterState.getSlicesMap(collection);
     if (slices == null) {
       throw new ZooKeeperException(ErrorCode.BAD_REQUEST,
           "Could not find collection in zk: " + collection + " "

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/params/MoreLikeThisParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/params/MoreLikeThisParams.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/params/MoreLikeThisParams.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/params/MoreLikeThisParams.java Mon Dec 10 16:36:47 2012
@@ -31,6 +31,7 @@ public interface MoreLikeThisParams 
   
   public final static String SIMILARITY_FIELDS     = PREFIX + "fl";
   public final static String MIN_TERM_FREQ         = PREFIX + "mintf";
+  public final static String MAX_DOC_FREQ          = PREFIX + "maxdf";
   public final static String MIN_DOC_FREQ          = PREFIX + "mindf";
   public final static String MIN_WORD_LEN          = PREFIX + "minwl";
   public final static String MAX_WORD_LEN          = PREFIX + "maxwl";

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/params/ShardParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/params/ShardParams.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/params/ShardParams.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/java/org/apache/solr/common/params/ShardParams.java Mon Dec 10 16:36:47 2012
@@ -45,4 +45,7 @@ public interface ShardParams {
 
   /** Should things fail if there is an error? (true/false) */
   public static final String SHARDS_TOLERANT = "shards.tolerant";
+
+  /** Should things fail if there is an error? (true/false) */
+  public static final String SHARD_KEYS = "shard.keys";
 }

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java Mon Dec 10 16:36:47 2012
@@ -59,6 +59,7 @@ public abstract class MergeIndexesExampl
   @AfterClass
   public static void afterClass() {
     cores.shutdown();
+    cores = null;
   }
   
   @Override

Modified: lucene/dev/branches/lucene4547/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java (original)
+++ lucene/dev/branches/lucene4547/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java Mon Dec 10 16:36:47 2012
@@ -198,7 +198,7 @@ public class TestSolrProperties extends 
     CoreAdminRequest.renameCore(name, "renamed_core", coreadmin);
     mcr = CoreAdminRequest.persist(SOLR_PERSIST_XML, getRenamedSolrAdmin());
     
-//    fis = new FileInputStream(new File(solrXml.getParent(), SOLR_PERSIST_XML));
+//    fis = new FileInputStream(new File(tempDir, SOLR_PERSIST_XML));
 //    String solrPersistXml = IOUtils.toString(fis);
 //    System.out.println("xml:" + solrPersistXml);
 //    fis.close();

Modified: lucene/dev/branches/lucene4547/solr/test-framework/ivy.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/test-framework/ivy.xml?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/test-framework/ivy.xml (original)
+++ lucene/dev/branches/lucene4547/solr/test-framework/ivy.xml Mon Dec 10 16:36:47 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.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->*" />
+      <dependency org="com.carrotsearch.randomizedtesting" name="junit4-ant" rev="2.0.5" transitive="false" conf="default->*;junit4-stdalone->*" />
+      <dependency org="com.carrotsearch.randomizedtesting" name="randomizedtesting-runner" rev="2.0.5" transitive="false" conf="default->*;junit4-stdalone->*" />
 
       <exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/> 
     </dependencies>

Modified: lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java (original)
+++ lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java Mon Dec 10 16:36:47 2012
@@ -33,6 +33,7 @@ import java.util.Set;
 import junit.framework.Assert;
 
 import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.util.Constants;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -64,6 +65,7 @@ public abstract class BaseDistributedSea
 
   @BeforeClass
   public static void initialize() {
+    assumeFalse("SOLR-4147: ibm 64bit has jvm bugs!", Constants.JRE_IS_64BIT && Constants.JAVA_VENDOR.startsWith("IBM"));
     r = new Random(random().nextLong());
   }
 

Modified: lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java (original)
+++ lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java Mon Dec 10 16:36:47 2012
@@ -64,8 +64,9 @@ public abstract class AbstractDistribZkT
     System.setProperty("enable.update.log", "true");
     System.setProperty("remove.version.field", "true");
 
-
-    AbstractZkTestCase.buildZooKeeper(zkServer.getZkHost(), zkServer.getZkAddress(), "solrconfig.xml", "schema.xml");
+    String schema = getSchemaFile();
+    if (schema == null) schema = "schema.xml";
+    AbstractZkTestCase.buildZooKeeper(zkServer.getZkHost(), zkServer.getZkAddress(), "solrconfig.xml", schema);
 
     // set some system properties for use by tests
     System.setProperty("solr.test.sys.prop1", "propone");
@@ -79,8 +80,16 @@ public abstract class AbstractDistribZkT
     FileUtils.copyDirectory(new File(getSolrHome()), controlHome);
     
     System.setProperty("collection", "control_collection");
-    controlJetty = createJetty(controlHome, null, "control_shard");
+    String numShardsS = System.getProperty(ZkStateReader.NUM_SHARDS_PROP);
+    System.setProperty(ZkStateReader.NUM_SHARDS_PROP, "1");
+    controlJetty = createJetty(controlHome, null);      // let the shardId default to shard1
     System.clearProperty("collection");
+    if(numShardsS != null) {
+      System.setProperty(ZkStateReader.NUM_SHARDS_PROP, numShardsS);
+    } else {
+      System.clearProperty(ZkStateReader.NUM_SHARDS_PROP);
+    }
+
     controlClient = createNewSolrServer(controlJetty.getLocalPort());
 
     StringBuilder sb = new StringBuilder();
@@ -128,7 +137,7 @@ public abstract class AbstractDistribZkT
       boolean sawLiveRecovering = false;
       zkStateReader.updateClusterState(true);
       ClusterState clusterState = zkStateReader.getClusterState();
-      Map<String,Slice> slices = clusterState.getSlices(collection);
+      Map<String,Slice> slices = clusterState.getSlicesMap(collection);
       assertNotNull("Could not find collection:" + collection, slices);
       for (Map.Entry<String,Slice> entry : slices.entrySet()) {
         Map<String,Replica> shards = entry.getValue().getReplicasMap();
@@ -174,6 +183,8 @@ public abstract class AbstractDistribZkT
       }
       cnt++;
     }
+
+    log.info("Recoveries finished - collection: " + collection);
   }
 
   protected void assertAllActive(String collection,ZkStateReader zkStateReader)
@@ -181,7 +192,7 @@ public abstract class AbstractDistribZkT
 
       zkStateReader.updateClusterState(true);
       ClusterState clusterState = zkStateReader.getClusterState();
-      Map<String,Slice> slices = clusterState.getSlices(collection);
+      Map<String,Slice> slices = clusterState.getSlicesMap(collection);
       if (slices == null) {
         throw new IllegalArgumentException("Cannot find collection:" + collection);
       }

Modified: lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java (original)
+++ lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java Mon Dec 10 16:36:47 2012
@@ -46,6 +46,7 @@ import org.apache.solr.common.SolrDocume
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.cloud.ClusterState;
+import org.apache.solr.common.cloud.DocCollection;
 import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.cloud.Slice;
 import org.apache.solr.common.cloud.ZkCoreNodeProps;
@@ -226,18 +227,22 @@ public abstract class AbstractFullDistri
     
     System.setProperty("collection", "control_collection");
     String numShards = System.getProperty(ZkStateReader.NUM_SHARDS_PROP);
-    System.clearProperty(ZkStateReader.NUM_SHARDS_PROP);
-    
+
+    // we want hashes by default, so set to 1 shard as opposed to leaving unset
+    // System.clearProperty(ZkStateReader.NUM_SHARDS_PROP);
+    System.setProperty(ZkStateReader.NUM_SHARDS_PROP, "1");
+
     File controlJettyDir = new File(TEMP_DIR,
             getClass().getName() + "-controljetty-" + System.currentTimeMillis());
     org.apache.commons.io.FileUtils.copyDirectory(new File(getSolrHome()), controlJettyDir);
 
-    controlJetty = createJetty(controlJettyDir, testDir + "/control/data",
-        "control_shard");
+    controlJetty = createJetty(controlJettyDir, testDir + "/control/data");  // don't pass shard name... let it default to "shard1"
     System.clearProperty("collection");
     if(numShards != null) {
       System.setProperty(ZkStateReader.NUM_SHARDS_PROP, numShards);
-    } 
+    } else {
+      System.clearProperty(ZkStateReader.NUM_SHARDS_PROP);
+    }
     controlClient = createNewSolrServer(controlJetty.getLocalPort());
     
     initCloud();
@@ -337,9 +342,12 @@ public abstract class AbstractFullDistri
     return jettys;
   }
 
-  protected int getNumShards(String defaultCollection) {
+  protected int getNumShards(String collection) {
     ZkStateReader zkStateReader = cloudClient.getZkStateReader();
-    Map<String,Slice> slices = zkStateReader.getClusterState().getSlices(defaultCollection);
+    Map<String,Slice> slices = zkStateReader.getClusterState().getSlicesMap(collection);
+    if (slices == null) {
+      throw new IllegalArgumentException("Could not find collection:" + collection);
+    }
     int cnt = 0;
     for (Map.Entry<String,Slice> entry : slices.entrySet()) {
       cnt += entry.getValue().getReplicasMap().size();
@@ -368,30 +376,24 @@ public abstract class AbstractFullDistri
     shardToJetty.clear();
     
     ClusterState clusterState = zkStateReader.getClusterState();
-    Map<String,Slice> slices = clusterState.getSlices(DEFAULT_COLLECTION);
-    
-    if (slices == null) {
-      throw new RuntimeException("No slices found for collection "
-          + DEFAULT_COLLECTION + " in " + clusterState.getCollections());
-    }
-    
+    DocCollection coll = clusterState.getCollection(DEFAULT_COLLECTION);
+
     List<CloudSolrServerClient> theClients = new ArrayList<CloudSolrServerClient>();
     for (SolrServer client : clients) {
       // find info for this client in zk 
       nextClient:
-      // we find ou state by simply matching ports...
-      for (Map.Entry<String,Slice> slice : slices.entrySet()) {
-        Map<String,Replica> theShards = slice.getValue().getReplicasMap();
-        for (Map.Entry<String,Replica> shard : theShards.entrySet()) {
+      // we find out state by simply matching ports...
+      for (Slice slice : coll.getSlices()) {
+        for (Replica replica : slice.getReplicas()) {
           int port = new URI(((HttpSolrServer) client).getBaseURL())
               .getPort();
           
-          if (shard.getKey().contains(":" + port + "_")) {
+          if (replica.getName().contains(":" + port + "_")) {
             CloudSolrServerClient csc = new CloudSolrServerClient();
             csc.solrClient = client;
             csc.port = port;
-            csc.shardName = shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP);
-            csc.info = shard.getValue();
+            csc.shardName = replica.getStr(ZkStateReader.NODE_NAME_PROP);
+            csc.info = replica;
             
             theClients .add(csc);
             
@@ -408,27 +410,25 @@ public abstract class AbstractFullDistri
       }
       
       nextJetty:
-      for (Map.Entry<String,Slice> slice : slices.entrySet()) {
-        Map<String,Replica> theShards = slice.getValue().getReplicasMap();
-        for (Map.Entry<String,Replica> shard : theShards.entrySet()) {
-          if (shard.getKey().contains(":" + port + "_")) {
-            List<CloudJettyRunner> list = shardToJetty.get(slice.getKey());
+      for (Slice slice : coll.getSlices()) {
+        for (Replica replica : slice.getReplicas()) {
+          if (replica.getName().contains(":" + port + "_")) {
+            List<CloudJettyRunner> list = shardToJetty.get(slice.getName());
             if (list == null) {
               list = new ArrayList<CloudJettyRunner>();
-              shardToJetty.put(slice.getKey(), list);
+              shardToJetty.put(slice.getName(), list);
             }
-            boolean isLeader = shard.getValue().containsKey(
-                ZkStateReader.LEADER_PROP);
+            boolean isLeader = slice.getLeader() == replica;
             CloudJettyRunner cjr = new CloudJettyRunner();
             cjr.jetty = jetty;
-            cjr.info = shard.getValue();
-            cjr.nodeName = shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP);
-            cjr.coreNodeName = shard.getKey();
-            cjr.url = shard.getValue().getStr(ZkStateReader.BASE_URL_PROP) + "/" + shard.getValue().getStr(ZkStateReader.CORE_NAME_PROP);
+            cjr.info = replica;
+            cjr.nodeName = replica.getStr(ZkStateReader.NODE_NAME_PROP);
+            cjr.coreNodeName = replica.getName();
+            cjr.url = replica.getStr(ZkStateReader.BASE_URL_PROP) + "/" + replica.getStr(ZkStateReader.CORE_NAME_PROP);
             cjr.client = findClientByPort(port, theClients);
             list.add(cjr);
             if (isLeader) {
-              shardToLeaderJetty.put(slice.getKey(), cjr);
+              shardToLeaderJetty.put(slice.getName(), cjr);
             }
             cloudJettys.add(cjr);
             break nextJetty;
@@ -440,12 +440,12 @@ public abstract class AbstractFullDistri
     // # of jetties may not match replicas in shard here, because we don't map
     // jetties that are not running - every shard should have at least one
     // running jetty though
-    for (Map.Entry<String,Slice> slice : slices.entrySet()) {
+    for (Slice slice : coll.getSlices()) {
       // check that things look right
-      List<CloudJettyRunner> jetties = shardToJetty.get(slice.getKey());
-      assertNotNull("Test setup problem: We found no jetties for shard: " + slice.getKey()
+      List<CloudJettyRunner> jetties = shardToJetty.get(slice.getName());
+      assertNotNull("Test setup problem: We found no jetties for shard: " + slice.getName()
           + " just:" + shardToJetty.keySet(), jetties);
-      assertEquals(slice.getValue().getReplicasMap().size(), jetties.size());
+      assertEquals(slice.getReplicas().size(), jetties.size());
     }
   }
   
@@ -940,7 +940,7 @@ public abstract class AbstractFullDistri
     try {
       zk.createClusterStateWatchersAndUpdate();
       clusterState = zk.getClusterState();
-      slices = clusterState.getSlices(DEFAULT_COLLECTION);
+      slices = clusterState.getSlicesMap(DEFAULT_COLLECTION);
     } finally {
       zk.close();
     }

Modified: lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java (original)
+++ lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java Mon Dec 10 16:36:47 2012
@@ -62,7 +62,6 @@ public abstract class AbstractZkTestCase
 
   @BeforeClass
   public static void azt_beforeClass() throws Exception {
-    System.out.println("azt beforeclass");
     createTempDir();
     zkDir = dataDir.getAbsolutePath() + File.separator
         + "zookeeper/server1/data";
@@ -102,9 +101,10 @@ public abstract class AbstractZkTestCase
     zkClient.makePath("/collections/control_collection", ZkStateReader.toJSON(zkProps), CreateMode.PERSISTENT, true);
     zkClient.makePath("/collections/control_collection/shards", CreateMode.PERSISTENT, true);
 
-    putConfig(zkClient, solrhome, config);
-    putConfig(zkClient, solrhome, schema);
-    putConfig(zkClient, solrhome, "solrconfig.xml");
+    // for now, always upload the config and schema to the canonical names
+    putConfig(zkClient, solrhome, config, "solrconfig.xml");
+    putConfig(zkClient, solrhome, schema, "schema.xml");
+
     putConfig(zkClient, solrhome, "stopwords.txt");
     putConfig(zkClient, solrhome, "protwords.txt");
     putConfig(zkClient, solrhome, "currency.xml");
@@ -118,16 +118,21 @@ public abstract class AbstractZkTestCase
 
   private static void putConfig(SolrZkClient zkClient, File solrhome, final String name)
       throws Exception {
-    String path = "/configs/conf1/" + name;
+    putConfig(zkClient, solrhome, name, name);
+  }
+
+  private static void putConfig(SolrZkClient zkClient, File solrhome, final String srcName, String destName)
+      throws Exception {
     File file = new File(solrhome, "collection1"
-        + File.separator + "conf" + File.separator + name);
+        + File.separator + "conf" + File.separator + srcName);
     if (!file.exists()) {
       log.info("skipping " + file.getAbsolutePath() + " because it doesn't exist");
       return;
     }
-    
-    log.info("put " + file.getAbsolutePath() + " to " + path);
-    zkClient.makePath(path, file, false, true);  
+
+    String destPath = "/configs/conf1/" + destName;
+    log.info("put " + file.getAbsolutePath() + " to " + destPath);
+    zkClient.makePath(destPath, file, false, true);
   }
 
   @Override
@@ -149,6 +154,9 @@ public abstract class AbstractZkTestCase
 
     zkServer.shutdown();
 
+    zkServer = null;
+    zkDir = null;
+    
     // wait just a bit for any zk client threads to outlast timeout
     Thread.sleep(2000);
   }

Modified: lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java (original)
+++ lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java Mon Dec 10 16:36:47 2012
@@ -263,7 +263,7 @@ public class ChaosMonkey {
   }
 
   private String getRandomSlice() {
-    Map<String,Slice> slices = zkStateReader.getClusterState().getSlices(collection);
+    Map<String,Slice> slices = zkStateReader.getClusterState().getSlicesMap(collection);
     
     List<String> sliceKeyList = new ArrayList<String>(slices.size());
     sliceKeyList.addAll(slices.keySet());
@@ -292,7 +292,7 @@ public class ChaosMonkey {
       // get latest cloud state
       zkStateReader.updateClusterState(true);
       
-      Slice theShards = zkStateReader.getClusterState().getSlices(collection)
+      Slice theShards = zkStateReader.getClusterState().getSlicesMap(collection)
           .get(slice);
       
       ZkNodeProps props = theShards.getReplicasMap().get(cloudJetty.coreNodeName);

Modified: lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java (original)
+++ lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java Mon Dec 10 16:36:47 2012
@@ -32,7 +32,7 @@ import java.util.List;
 import javax.management.JMException;
 
 import org.apache.zookeeper.jmx.ManagedUtil;
-import org.apache.zookeeper.server.NIOServerCnxn;
+import org.apache.zookeeper.server.ServerCnxnFactory;
 import org.apache.zookeeper.server.ServerConfig;
 import org.apache.zookeeper.server.SessionTracker.Session;
 import org.apache.zookeeper.server.ZKDatabase;
@@ -59,7 +59,7 @@ public class ZkTestServer {
 
   class ZKServerMain {
 
-    private NIOServerCnxn.Factory cnxnFactory;
+    private ServerCnxnFactory cnxnFactory;
     private ZooKeeperServer zooKeeperServer;
     
     protected void initializeAndRun(String[] args) throws ConfigException,
@@ -67,16 +67,16 @@ public class ZkTestServer {
       try {
         ManagedUtil.registerLog4jMBeans();
       } catch (JMException e) {
-
+        log.warn("Unable to register log4j JMX control", e);
       }
-
+      
       ServerConfig config = new ServerConfig();
       if (args.length == 1) {
         config.parse(args[0]);
       } else {
         config.parse(args);
       }
-
+      
       runFromConfig(config);
     }
 
@@ -86,25 +86,31 @@ public class ZkTestServer {
      * @throws IOException If there is a low-level I/O error.
      */
     public void runFromConfig(ServerConfig config) throws IOException {
+      log.info("Starting server");
       try {
         // Note that this thread isn't going to be doing anything else,
         // so rather than spawning another thread, we will just call
         // run() in this thread.
         // create a file logger url from the command line args
         zooKeeperServer = new ZooKeeperServer();
-
-        FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(config
-            .getDataLogDir()), new File(config.getDataDir()));
+        
+        FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(
+            config.getDataLogDir()), new File(config.getDataDir()));
         zooKeeperServer.setTxnLogFactory(ftxn);
         zooKeeperServer.setTickTime(config.getTickTime());
-        cnxnFactory = new NIOServerCnxn.Factory(config.getClientPortAddress(), config
-            .getMaxClientCnxns());
+        zooKeeperServer.setMinSessionTimeout(config.getMinSessionTimeout());
+        zooKeeperServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
+        cnxnFactory = ServerCnxnFactory.createFactory();
+        cnxnFactory.configure(config.getClientPortAddress(),
+            config.getMaxClientCnxns());
         cnxnFactory.startup(zooKeeperServer);
         cnxnFactory.join();
         if (zooKeeperServer.isRunning()) {
-          zooKeeperServer.shutdown();
+          zkServer.shutdown();
         }
       } catch (InterruptedException e) {
+        // warn, but generally this is ok
+        log.warn("Server interrupted", e);
       }
     }
 
@@ -207,6 +213,7 @@ public class ZkTestServer {
             } else {
               this.clientPortAddress = new InetSocketAddress(clientPort);
             }
+            System.out.println("client port:" + this.clientPortAddress);
           }
         };
 
@@ -287,12 +294,13 @@ public class ZkTestServer {
    * @param host the destination host
    * @param port the destination port
    * @param cmd the 4letterword
-   * @throws IOException If there is a low-level I/O error.
+   * @return server response
+
    */
   public static String send4LetterWord(String host, int port, String cmd)
-      throws IOException
+          throws IOException
   {
-
+      log.info("connecting to " + host + " " + port);
       Socket sock = new Socket(host, port);
       BufferedReader reader = null;
       try {
@@ -303,8 +311,8 @@ public class ZkTestServer {
           sock.shutdownOutput();
 
           reader =
-              new BufferedReader(
-                      new InputStreamReader(sock.getInputStream(), "US-ASCII"));
+                  new BufferedReader(
+                          new InputStreamReader(sock.getInputStream(), "US-ASCII"));
           StringBuilder sb = new StringBuilder();
           String line;
           while((line = reader.readLine()) != null) {

Modified: lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java (original)
+++ lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java Mon Dec 10 16:36:47 2012
@@ -31,21 +31,27 @@ public class MockDirectoryFactory extend
   @Override
   protected Directory create(String path) throws IOException {
     Directory dir = LuceneTestCase.newDirectory();
-    // we can't currently do this check because of how
-    // Solr has to reboot a new Directory sometimes when replicating
-    // or rolling back - the old directory is closed and the following
-    // test assumes it can open an IndexWriter when that happens - we
-    // have a new Directory for the same dir and still an open IW at 
-    // this point
     if (dir instanceof MockDirectoryWrapper) {
-      ((MockDirectoryWrapper)dir).setAssertNoUnrefencedFilesOnClose(false);
+      MockDirectoryWrapper mockDirWrapper = (MockDirectoryWrapper) dir;
+      
+      // we can't currently do this check because of how
+      // Solr has to reboot a new Directory sometimes when replicating
+      // or rolling back - the old directory is closed and the following
+      // test assumes it can open an IndexWriter when that happens - we
+      // have a new Directory for the same dir and still an open IW at 
+      // this point
+      mockDirWrapper.setAssertNoUnrefencedFilesOnClose(false);
+      
+      // ram dirs in cores that are restarted end up empty
+      // and check index fails
+      mockDirWrapper.setCheckIndexOnClose(false);
+      
+      // if we enable this, TestReplicationHandler fails when it
+      // tries to write to index.properties after the file has
+      // already been created.
+      mockDirWrapper.setPreventDoubleWrite(false);
     }
     
-    // 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/lucene4547/solr/test-framework/src/java/org/apache/solr/util/RevertDefaultThreadHandlerRule.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/util/RevertDefaultThreadHandlerRule.java?rev=1419570&r1=1419569&r2=1419570&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/util/RevertDefaultThreadHandlerRule.java (original)
+++ lucene/dev/branches/lucene4547/solr/test-framework/src/java/org/apache/solr/util/RevertDefaultThreadHandlerRule.java Mon Dec 10 16:36:47 2012
@@ -3,6 +3,7 @@ package org.apache.solr.util;
 import java.lang.Thread.UncaughtExceptionHandler;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.apache.zookeeper.server.NIOServerCnxnFactory;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -38,12 +39,12 @@ public final class RevertDefaultThreadHa
           UncaughtExceptionHandler p = Thread.getDefaultUncaughtExceptionHandler();
           try {
             // Try to initialize a zookeeper class that reinitializes default exception handler.
-            Class<?> cl = org.apache.zookeeper.server.NIOServerCnxn.Factory.class;
+            Class<?> cl = NIOServerCnxnFactory.class;
             // Make sure static initializers have been called.
             Class.forName(cl.getName(), true, cl.getClassLoader());
           } finally {
             if (p == Thread.getDefaultUncaughtExceptionHandler()) {
-              throw new RuntimeException("Zookeeper no longer resets default thread handler.");
+            //  throw new RuntimeException("Zookeeper no longer resets default thread handler.");
             }
             Thread.setDefaultUncaughtExceptionHandler(p);
           }



Mime
View raw message