You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/02/09 02:04:13 UTC
svn commit: r1068718 [19/21] - in /lucene/dev/branches/bulkpostings: ./
dev-tools/eclipse/ dev-tools/idea/.idea/ dev-tools/idea/lucene/
dev-tools/maven/ dev-tools/maven/lucene/ dev-tools/maven/lucene/contrib/ant/
dev-tools/maven/lucene/contrib/db/bdb-j...
Modified: lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java?rev=1068718&r1=1068717&r2=1068718&view=diff
==============================================================================
--- lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java (original)
+++ lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java Wed Feb 9 01:03:49 2011
@@ -1,284 +1,284 @@
-package org.apache.solr.cloud;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.net.MalformedURLException;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.impl.CloudSolrServer;
-import org.apache.solr.client.solrj.response.QueryResponse;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.ModifiableSolrParams;
-import org.junit.BeforeClass;
-
-/**
- *
- */
-public class BasicDistributedZkTest extends AbstractDistributedZkTestCase {
-
- private static final String DEFAULT_COLLECTION = "collection1";
- private static final boolean DEBUG = false;
- String t1="a_t";
- String i1="a_si";
- String nint = "n_i";
- String tint = "n_ti";
- String nfloat = "n_f";
- String tfloat = "n_tf";
- String ndouble = "n_d";
- String tdouble = "n_td";
- String nlong = "n_l";
- String tlong = "n_tl";
- String ndate = "n_dt";
- String tdate = "n_tdt";
-
- String oddField="oddField_s";
- String missingField="ignore_exception__missing_but_valid_field_t";
- String invalidField="ignore_exception__invalid_field_not_in_schema";
-
- public BasicDistributedZkTest() {
- fixShardCount = true;
-
- System.setProperty("CLOUD_UPDATE_DELAY", "0");
- }
-
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- System.setProperty("solr.solr.home", SolrTestCaseJ4.TEST_HOME);
- }
-
- @Override
- protected void setDistributedParams(ModifiableSolrParams params) {
-
- if (r.nextBoolean()) {
- // don't set shards, let that be figured out from the cloud state
- params.set("distrib", "true");
- } else {
- // use shard ids rather than physical locations
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < shardCount; i++) {
- if (i > 0)
- sb.append(',');
- sb.append("shard" + (i + 3));
- }
- params.set("shards", sb.toString());
- params.set("distrib", "true");
- }
- }
-
- @Override
- public void doTest() throws Exception {
- del("*:*");
- indexr(id,1, i1, 100, tlong, 100,t1,"now is the time for all good men"
- ,"foo_f", 1.414f, "foo_b", "true", "foo_d", 1.414d);
- indexr(id,2, i1, 50 , tlong, 50,t1,"to come to the aid of their country."
- );
- indexr(id,3, i1, 2, tlong, 2,t1,"how now brown cow"
- );
- indexr(id,4, i1, -100 ,tlong, 101,t1,"the quick fox jumped over the lazy dog"
- );
- indexr(id,5, i1, 500, tlong, 500 ,t1,"the quick fox jumped way over the lazy dog"
- );
- indexr(id,6, i1, -600, tlong, 600 ,t1,"humpty dumpy sat on a wall");
- indexr(id,7, i1, 123, tlong, 123 ,t1,"humpty dumpy had a great fall");
- indexr(id,8, i1, 876, tlong, 876,t1,"all the kings horses and all the kings men");
- indexr(id,9, i1, 7, tlong, 7,t1,"couldn't put humpty together again");
- indexr(id,10, i1, 4321, tlong, 4321,t1,"this too shall pass");
- indexr(id,11, i1, -987, tlong, 987,t1,"An eye for eye only ends up making the whole world blind.");
- indexr(id,12, i1, 379, tlong, 379,t1,"Great works are performed, not by strength, but by perseverance.");
- indexr(id,13, i1, 232, tlong, 232,t1,"no eggs on wall, lesson learned", oddField, "odd man out");
-
- indexr(id, 14, "SubjectTerms_mfacet", new String[] {"mathematical models", "mathematical analysis"});
- indexr(id, 15, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});
- indexr(id, 16, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});
- String[] vals = new String[100];
- for (int i=0; i<100; i++) {
- vals[i] = "test " + i;
- }
- indexr(id, 17, "SubjectTerms_mfacet", vals);
-
- for (int i=100; i<150; i++) {
- indexr(id, i);
- }
-
- commit();
-
- handle.clear();
- handle.put("QTime", SKIPVAL);
- handle.put("timestamp", SKIPVAL);
-
- // random value sort
- for (String f : fieldNames) {
- query("q","*:*", "sort",f+" desc");
- query("q","*:*", "sort",f+" asc");
- }
-
- // these queries should be exactly ordered and scores should exactly match
- query("q","*:*", "sort",i1+" desc");
- query("q","*:*", "sort",i1+" asc");
- query("q","*:*", "sort",i1+" desc", "fl","*,score");
- query("q","*:*", "sort",tlong+" asc", "fl","score"); // test legacy behavior - "score"=="*,score"
- query("q","*:*", "sort",tlong+" desc");
- handle.put("maxScore", SKIPVAL);
- query("q","{!func}"+i1);// does not expect maxScore. So if it comes ,ignore it. JavaBinCodec.writeSolrDocumentList()
- //is agnostic of request params.
- handle.remove("maxScore");
- query("q","{!func}"+i1, "fl","*,score"); // even scores should match exactly here
-
- handle.put("highlighting", UNORDERED);
- handle.put("response", UNORDERED);
-
- handle.put("maxScore", SKIPVAL);
- query("q","quick");
- query("q","all","fl","id","start","0");
- query("q","all","fl","foofoofoo","start","0"); // no fields in returned docs
- query("q","all","fl","id","start","100");
-
- handle.put("score", SKIPVAL);
- query("q","quick","fl","*,score");
- query("q","all","fl","*,score","start","1");
- query("q","all","fl","*,score","start","100");
-
- query("q","now their fox sat had put","fl","*,score",
- "hl","true","hl.fl",t1);
-
- query("q","now their fox sat had put","fl","foofoofoo",
- "hl","true","hl.fl",t1);
-
- query("q","matchesnothing","fl","*,score");
-
- query("q","*:*", "rows",100, "facet","true", "facet.field",t1);
- query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","count");
- query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","count", "facet.mincount",2);
- query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","index");
- query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","index", "facet.mincount",2);
- query("q","*:*", "rows",100, "facet","true", "facet.field",t1,"facet.limit",1);
- query("q","*:*", "rows",100, "facet","true", "facet.query","quick", "facet.query","all", "facet.query","*:*");
- query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.offset",1);
- query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.mincount",2);
-
- // test faceting multiple things at once
- query("q","*:*", "rows",100, "facet","true", "facet.query","quick", "facet.query","all", "facet.query","*:*"
- ,"facet.field",t1);
-
- // test filter tagging, facet exclusion, and naming (multi-select facet support)
- query("q","*:*", "rows",100, "facet","true", "facet.query","{!key=myquick}quick", "facet.query","{!key=myall ex=a}all", "facet.query","*:*"
- ,"facet.field","{!key=mykey ex=a}"+t1
- ,"facet.field","{!key=other ex=b}"+t1
- ,"facet.field","{!key=again ex=a,b}"+t1
- ,"facet.field",t1
- ,"fq","{!tag=a}id:[1 TO 7]", "fq","{!tag=b}id:[3 TO 9]"
- );
- query("q", "*:*", "facet", "true", "facet.field", "{!ex=t1}SubjectTerms_mfacet", "fq", "{!tag=t1}SubjectTerms_mfacet:(test 1)", "facet.limit", "10", "facet.mincount", "1");
-
- // test field that is valid in schema but missing in all shards
- query("q","*:*", "rows",100, "facet","true", "facet.field",missingField, "facet.mincount",2);
- // test field that is valid in schema and missing in some shards
- query("q","*:*", "rows",100, "facet","true", "facet.field",oddField, "facet.mincount",2);
-
- query("q","*:*", "sort",i1+" desc", "stats", "true", "stats.field", i1);
-
- /*** TODO: the failure may come back in "exception"
- try {
- // test error produced for field that is invalid for schema
- query("q","*:*", "rows",100, "facet","true", "facet.field",invalidField, "facet.mincount",2);
- TestCase.fail("SolrServerException expected for invalid field that is not in schema");
- } catch (SolrServerException ex) {
- // expected
- }
- ***/
-
- // Try to get better coverage for refinement queries by turning off over requesting.
- // This makes it much more likely that we may not get the top facet values and hence
- // we turn of that checking.
- handle.put("facet_fields", SKIPVAL);
- query("q","*:*", "rows",0, "facet","true", "facet.field",t1,"facet.limit",5, "facet.shard.limit",5);
- // check a complex key name
- query("q","*:*", "rows",0, "facet","true", "facet.field","{!key='a b/c \\' \\} foo'}"+t1,"facet.limit",5, "facet.shard.limit",5);
- handle.remove("facet_fields");
-
-
- // index the same document to two servers and make sure things
- // don't blow up.
- if (clients.size()>=2) {
- index(id,100, i1, 107 ,t1,"oh no, a duplicate!");
- for (int i=0; i<clients.size(); i++) {
- index_specific(i, id,100, i1, 107 ,t1,"oh no, a duplicate!");
- }
- commit();
- query("q","duplicate", "hl","true", "hl.fl", t1);
- query("q","fox duplicate horses", "hl","true", "hl.fl", t1);
- query("q","*:*", "rows",100);
- }
-
- // test debugging
- handle.put("explain", UNORDERED);
- handle.put("debug", UNORDERED);
- handle.put("time", SKIPVAL);
- query("q","now their fox sat had put","fl","*,score",CommonParams.DEBUG_QUERY, "true");
- query("q", "id:[1 TO 5]", CommonParams.DEBUG_QUERY, "true");
- query("q", "id:[1 TO 5]", CommonParams.DEBUG, CommonParams.TIMING);
- query("q", "id:[1 TO 5]", CommonParams.DEBUG, CommonParams.RESULTS);
- query("q", "id:[1 TO 5]", CommonParams.DEBUG, CommonParams.QUERY);
-
- // TODO: This test currently fails because debug info is obtained only
- // on shards with matches.
- // query("q","matchesnothing","fl","*,score", "debugQuery", "true");
-
- // Thread.sleep(10000000000L);
- if (DEBUG) {
- super.printLayout();
- }
- }
-
- volatile CloudSolrServer solrj;
-
- @Override
- protected QueryResponse queryServer(ModifiableSolrParams params) throws SolrServerException {
-
- if (r.nextBoolean())
- return super.queryServer(params);
-
- // use the distributed solrj client
- if (solrj == null) {
- synchronized(this) {
- try {
- CloudSolrServer server = new CloudSolrServer(zkServer.getZkAddress());
- server.setDefaultCollection(DEFAULT_COLLECTION);
- solrj = server;
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- if (r.nextBoolean())
- params.set("collection",DEFAULT_COLLECTION);
-
- QueryResponse rsp = solrj.query(params);
- return rsp;
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- System.clearProperty("CLOUD_UPDATE_DELAY");
- System.clearProperty("zkHost");
- }
-}
+package org.apache.solr.cloud;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.net.MalformedURLException;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.CloudSolrServer;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.junit.BeforeClass;
+
+/**
+ *
+ */
+public class BasicDistributedZkTest extends AbstractDistributedZkTestCase {
+
+ private static final String DEFAULT_COLLECTION = "collection1";
+ private static final boolean DEBUG = false;
+ String t1="a_t";
+ String i1="a_si";
+ String nint = "n_i";
+ String tint = "n_ti";
+ String nfloat = "n_f";
+ String tfloat = "n_tf";
+ String ndouble = "n_d";
+ String tdouble = "n_td";
+ String nlong = "n_l";
+ String tlong = "other_tl1";
+ String ndate = "n_dt";
+ String tdate = "n_tdt";
+
+ String oddField="oddField_s";
+ String missingField="ignore_exception__missing_but_valid_field_t";
+ String invalidField="ignore_exception__invalid_field_not_in_schema";
+
+ public BasicDistributedZkTest() {
+ fixShardCount = true;
+
+ System.setProperty("CLOUD_UPDATE_DELAY", "0");
+ }
+
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ System.setProperty("solr.solr.home", SolrTestCaseJ4.TEST_HOME);
+ }
+
+ @Override
+ protected void setDistributedParams(ModifiableSolrParams params) {
+
+ if (r.nextBoolean()) {
+ // don't set shards, let that be figured out from the cloud state
+ params.set("distrib", "true");
+ } else {
+ // use shard ids rather than physical locations
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < shardCount; i++) {
+ if (i > 0)
+ sb.append(',');
+ sb.append("shard" + (i + 3));
+ }
+ params.set("shards", sb.toString());
+ params.set("distrib", "true");
+ }
+ }
+
+ @Override
+ public void doTest() throws Exception {
+ del("*:*");
+ indexr(id,1, i1, 100, tlong, 100,t1,"now is the time for all good men"
+ ,"foo_f", 1.414f, "foo_b", "true", "foo_d", 1.414d);
+ indexr(id,2, i1, 50 , tlong, 50,t1,"to come to the aid of their country."
+ );
+ indexr(id,3, i1, 2, tlong, 2,t1,"how now brown cow"
+ );
+ indexr(id,4, i1, -100 ,tlong, 101,t1,"the quick fox jumped over the lazy dog"
+ );
+ indexr(id,5, i1, 500, tlong, 500 ,t1,"the quick fox jumped way over the lazy dog"
+ );
+ indexr(id,6, i1, -600, tlong, 600 ,t1,"humpty dumpy sat on a wall");
+ indexr(id,7, i1, 123, tlong, 123 ,t1,"humpty dumpy had a great fall");
+ indexr(id,8, i1, 876, tlong, 876,t1,"all the kings horses and all the kings men");
+ indexr(id,9, i1, 7, tlong, 7,t1,"couldn't put humpty together again");
+ indexr(id,10, i1, 4321, tlong, 4321,t1,"this too shall pass");
+ indexr(id,11, i1, -987, tlong, 987,t1,"An eye for eye only ends up making the whole world blind.");
+ indexr(id,12, i1, 379, tlong, 379,t1,"Great works are performed, not by strength, but by perseverance.");
+ indexr(id,13, i1, 232, tlong, 232,t1,"no eggs on wall, lesson learned", oddField, "odd man out");
+
+ indexr(id, 14, "SubjectTerms_mfacet", new String[] {"mathematical models", "mathematical analysis"});
+ indexr(id, 15, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});
+ indexr(id, 16, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});
+ String[] vals = new String[100];
+ for (int i=0; i<100; i++) {
+ vals[i] = "test " + i;
+ }
+ indexr(id, 17, "SubjectTerms_mfacet", vals);
+
+ for (int i=100; i<150; i++) {
+ indexr(id, i);
+ }
+
+ commit();
+
+ handle.clear();
+ handle.put("QTime", SKIPVAL);
+ handle.put("timestamp", SKIPVAL);
+
+ // random value sort
+ for (String f : fieldNames) {
+ query("q","*:*", "sort",f+" desc");
+ query("q","*:*", "sort",f+" asc");
+ }
+
+ // these queries should be exactly ordered and scores should exactly match
+ query("q","*:*", "sort",i1+" desc");
+ query("q","*:*", "sort",i1+" asc");
+ query("q","*:*", "sort",i1+" desc", "fl","*,score");
+ query("q","*:*", "sort","n_tl1 asc", "fl","score"); // test legacy behavior - "score"=="*,score"
+ query("q","*:*", "sort","n_tl1 desc");
+ handle.put("maxScore", SKIPVAL);
+ query("q","{!func}"+i1);// does not expect maxScore. So if it comes ,ignore it. JavaBinCodec.writeSolrDocumentList()
+ //is agnostic of request params.
+ handle.remove("maxScore");
+ query("q","{!func}"+i1, "fl","*,score"); // even scores should match exactly here
+
+ handle.put("highlighting", UNORDERED);
+ handle.put("response", UNORDERED);
+
+ handle.put("maxScore", SKIPVAL);
+ query("q","quick");
+ query("q","all","fl","id","start","0");
+ query("q","all","fl","foofoofoo","start","0"); // no fields in returned docs
+ query("q","all","fl","id","start","100");
+
+ handle.put("score", SKIPVAL);
+ query("q","quick","fl","*,score");
+ query("q","all","fl","*,score","start","1");
+ query("q","all","fl","*,score","start","100");
+
+ query("q","now their fox sat had put","fl","*,score",
+ "hl","true","hl.fl",t1);
+
+ query("q","now their fox sat had put","fl","foofoofoo",
+ "hl","true","hl.fl",t1);
+
+ query("q","matchesnothing","fl","*,score");
+
+ query("q","*:*", "rows",100, "facet","true", "facet.field",t1);
+ query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","count");
+ query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","count", "facet.mincount",2);
+ query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","index");
+ query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","index", "facet.mincount",2);
+ query("q","*:*", "rows",100, "facet","true", "facet.field",t1,"facet.limit",1);
+ query("q","*:*", "rows",100, "facet","true", "facet.query","quick", "facet.query","all", "facet.query","*:*");
+ query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.offset",1);
+ query("q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.mincount",2);
+
+ // test faceting multiple things at once
+ query("q","*:*", "rows",100, "facet","true", "facet.query","quick", "facet.query","all", "facet.query","*:*"
+ ,"facet.field",t1);
+
+ // test filter tagging, facet exclusion, and naming (multi-select facet support)
+ query("q","*:*", "rows",100, "facet","true", "facet.query","{!key=myquick}quick", "facet.query","{!key=myall ex=a}all", "facet.query","*:*"
+ ,"facet.field","{!key=mykey ex=a}"+t1
+ ,"facet.field","{!key=other ex=b}"+t1
+ ,"facet.field","{!key=again ex=a,b}"+t1
+ ,"facet.field",t1
+ ,"fq","{!tag=a}id:[1 TO 7]", "fq","{!tag=b}id:[3 TO 9]"
+ );
+ query("q", "*:*", "facet", "true", "facet.field", "{!ex=t1}SubjectTerms_mfacet", "fq", "{!tag=t1}SubjectTerms_mfacet:(test 1)", "facet.limit", "10", "facet.mincount", "1");
+
+ // test field that is valid in schema but missing in all shards
+ query("q","*:*", "rows",100, "facet","true", "facet.field",missingField, "facet.mincount",2);
+ // test field that is valid in schema and missing in some shards
+ query("q","*:*", "rows",100, "facet","true", "facet.field",oddField, "facet.mincount",2);
+
+ query("q","*:*", "sort",i1+" desc", "stats", "true", "stats.field", i1);
+
+ /*** TODO: the failure may come back in "exception"
+ try {
+ // test error produced for field that is invalid for schema
+ query("q","*:*", "rows",100, "facet","true", "facet.field",invalidField, "facet.mincount",2);
+ TestCase.fail("SolrServerException expected for invalid field that is not in schema");
+ } catch (SolrServerException ex) {
+ // expected
+ }
+ ***/
+
+ // Try to get better coverage for refinement queries by turning off over requesting.
+ // This makes it much more likely that we may not get the top facet values and hence
+ // we turn of that checking.
+ handle.put("facet_fields", SKIPVAL);
+ query("q","*:*", "rows",0, "facet","true", "facet.field",t1,"facet.limit",5, "facet.shard.limit",5);
+ // check a complex key name
+ query("q","*:*", "rows",0, "facet","true", "facet.field","{!key='a b/c \\' \\} foo'}"+t1,"facet.limit",5, "facet.shard.limit",5);
+ handle.remove("facet_fields");
+
+
+ // index the same document to two servers and make sure things
+ // don't blow up.
+ if (clients.size()>=2) {
+ index(id,100, i1, 107 ,t1,"oh no, a duplicate!");
+ for (int i=0; i<clients.size(); i++) {
+ index_specific(i, id,100, i1, 107 ,t1,"oh no, a duplicate!");
+ }
+ commit();
+ query("q","duplicate", "hl","true", "hl.fl", t1);
+ query("q","fox duplicate horses", "hl","true", "hl.fl", t1);
+ query("q","*:*", "rows",100);
+ }
+
+ // test debugging
+ handle.put("explain", UNORDERED);
+ handle.put("debug", UNORDERED);
+ handle.put("time", SKIPVAL);
+ query("q","now their fox sat had put","fl","*,score",CommonParams.DEBUG_QUERY, "true");
+ query("q", "id:[1 TO 5]", CommonParams.DEBUG_QUERY, "true");
+ query("q", "id:[1 TO 5]", CommonParams.DEBUG, CommonParams.TIMING);
+ query("q", "id:[1 TO 5]", CommonParams.DEBUG, CommonParams.RESULTS);
+ query("q", "id:[1 TO 5]", CommonParams.DEBUG, CommonParams.QUERY);
+
+ // TODO: This test currently fails because debug info is obtained only
+ // on shards with matches.
+ // query("q","matchesnothing","fl","*,score", "debugQuery", "true");
+
+ // Thread.sleep(10000000000L);
+ if (DEBUG) {
+ super.printLayout();
+ }
+ }
+
+ volatile CloudSolrServer solrj;
+
+ @Override
+ protected QueryResponse queryServer(ModifiableSolrParams params) throws SolrServerException {
+
+ if (r.nextBoolean())
+ return super.queryServer(params);
+
+ // use the distributed solrj client
+ if (solrj == null) {
+ synchronized(this) {
+ try {
+ CloudSolrServer server = new CloudSolrServer(zkServer.getZkAddress());
+ server.setDefaultCollection(DEFAULT_COLLECTION);
+ solrj = server;
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ if (r.nextBoolean())
+ params.set("collection",DEFAULT_COLLECTION);
+
+ QueryResponse rsp = solrj.query(params);
+ return rsp;
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ System.clearProperty("CLOUD_UPDATE_DELAY");
+ System.clearProperty("zkHost");
+ }
+}
Modified: lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/BasicZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/BasicZkTest.java?rev=1068718&r1=1068717&r2=1068718&view=diff
==============================================================================
--- lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/BasicZkTest.java (original)
+++ lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/BasicZkTest.java Wed Feb 9 01:03:49 2011
@@ -1,138 +1,138 @@
-package org.apache.solr.cloud;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.lucene.index.LogMergePolicy;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.update.SolrIndexWriter;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- *
- */
-public class BasicZkTest extends AbstractZkTestCase {
-
- @BeforeClass
- public static void beforeClass() {
- System.setProperty("CLOUD_UPDATE_DELAY", "1");
- }
-
- @Test
- public void testBasic() throws Exception {
- // test using ZooKeeper
- assertTrue("Not using ZooKeeper", h.getCoreContainer().isZooKeeperAware());
-
- ZkController zkController = h.getCoreContainer().getZkController();
-
- // test merge factor picked up
- SolrCore core = h.getCore();
- SolrIndexWriter writer = new SolrIndexWriter("testWriter", core
- .getNewIndexDir(), core.getDirectoryFactory(), false, core.getSchema(),
- core.getSolrConfig().mainIndexConfig, core.getDeletionPolicy());
- assertEquals("Mergefactor was not picked up", ((LogMergePolicy)writer.getConfig().getMergePolicy()).getMergeFactor(), 8);
- writer.close();
-
- lrf.args.put("version", "2.0");
- assertQ("test query on empty index", req("qlkciyopsbgzyvkylsjhchghjrdf"),
- "//result[@numFound='0']");
-
- // test escaping of ";"
- assertU("deleting 42 for no reason at all", delI("42"));
- assertU("adding doc#42", adoc("id", "42", "val_s", "aa;bb"));
- assertU("does commit work?", commit());
-
- assertQ("backslash escaping semicolon", req("id:42 AND val_s:aa\\;bb"),
- "//*[@numFound='1']", "//int[@name='id'][.='42']");
-
- assertQ("quote escaping semicolon", req("id:42 AND val_s:\"aa;bb\""),
- "//*[@numFound='1']", "//int[@name='id'][.='42']");
-
- assertQ("no escaping semicolon", req("id:42 AND val_s:aa"),
- "//*[@numFound='0']");
-
- assertU(delI("42"));
- assertU(commit());
- assertQ(req("id:42"), "//*[@numFound='0']");
-
- // test overwrite default of true
-
- assertU(adoc("id", "42", "val_s", "AAA"));
- assertU(adoc("id", "42", "val_s", "BBB"));
- assertU(commit());
- assertQ(req("id:42"), "//*[@numFound='1']", "//str[.='BBB']");
- assertU(adoc("id", "42", "val_s", "CCC"));
- assertU(adoc("id", "42", "val_s", "DDD"));
- assertU(commit());
- assertQ(req("id:42"), "//*[@numFound='1']", "//str[.='DDD']");
-
- // test deletes
- String[] adds = new String[] { add(doc("id", "101"), "overwrite", "true"),
- add(doc("id", "101"), "overwrite", "true"),
- add(doc("id", "105"), "overwrite", "false"),
- add(doc("id", "102"), "overwrite", "true"),
- add(doc("id", "103"), "overwrite", "false"),
- add(doc("id", "101"), "overwrite", "true"), };
- for (String a : adds) {
- assertU(a, a);
- }
- assertU(commit());
-
- zkServer.shutdown();
-
- Thread.sleep(300);
-
- // try a reconnect from disconnect
- zkServer = new ZkTestServer(zkDir);
- zkServer.run();
-
- Thread.sleep(300);
-
- // ensure zk still thinks node is up
- assertTrue(
- zkController.getCloudState().getLiveNodes().toString(),
- zkController.getCloudState().liveNodesContain(
- zkController.getNodeName()));
-
- // test maxint
- assertQ(req("q", "id:[100 TO 110]", "rows", "2147483647"),
- "//*[@numFound='4']");
-
- // test big limit
- assertQ(req("q", "id:[100 TO 111]", "rows", "1147483647"),
- "//*[@numFound='4']");
-
- assertQ(req("id:[100 TO 110]"), "//*[@numFound='4']");
- assertU(delI("102"));
- assertU(commit());
- assertQ(req("id:[100 TO 110]"), "//*[@numFound='3']");
- assertU(delI("105"));
- assertU(commit());
- assertQ(req("id:[100 TO 110]"), "//*[@numFound='2']");
- assertU(delQ("id:[100 TO 110]"));
- assertU(commit());
- assertQ(req("id:[100 TO 110]"), "//*[@numFound='0']");
- }
-
- @AfterClass
- public static void afterClass() {
- System.clearProperty("CLOUD_UPDATE_DELAY");
- }
-}
+package org.apache.solr.cloud;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.index.LogMergePolicy;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.update.SolrIndexWriter;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class BasicZkTest extends AbstractZkTestCase {
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.setProperty("CLOUD_UPDATE_DELAY", "1");
+ }
+
+ @Test
+ public void testBasic() throws Exception {
+ // test using ZooKeeper
+ assertTrue("Not using ZooKeeper", h.getCoreContainer().isZooKeeperAware());
+
+ ZkController zkController = h.getCoreContainer().getZkController();
+
+ // test merge factor picked up
+ SolrCore core = h.getCore();
+ SolrIndexWriter writer = new SolrIndexWriter("testWriter", core
+ .getNewIndexDir(), core.getDirectoryFactory(), false, core.getSchema(),
+ core.getSolrConfig().mainIndexConfig, core.getDeletionPolicy());
+ assertEquals("Mergefactor was not picked up", ((LogMergePolicy)writer.getConfig().getMergePolicy()).getMergeFactor(), 8);
+ writer.close();
+
+ lrf.args.put("version", "2.0");
+ assertQ("test query on empty index", req("qlkciyopsbgzyvkylsjhchghjrdf"),
+ "//result[@numFound='0']");
+
+ // test escaping of ";"
+ assertU("deleting 42 for no reason at all", delI("42"));
+ assertU("adding doc#42", adoc("id", "42", "val_s", "aa;bb"));
+ assertU("does commit work?", commit());
+
+ assertQ("backslash escaping semicolon", req("id:42 AND val_s:aa\\;bb"),
+ "//*[@numFound='1']", "//int[@name='id'][.='42']");
+
+ assertQ("quote escaping semicolon", req("id:42 AND val_s:\"aa;bb\""),
+ "//*[@numFound='1']", "//int[@name='id'][.='42']");
+
+ assertQ("no escaping semicolon", req("id:42 AND val_s:aa"),
+ "//*[@numFound='0']");
+
+ assertU(delI("42"));
+ assertU(commit());
+ assertQ(req("id:42"), "//*[@numFound='0']");
+
+ // test overwrite default of true
+
+ assertU(adoc("id", "42", "val_s", "AAA"));
+ assertU(adoc("id", "42", "val_s", "BBB"));
+ assertU(commit());
+ assertQ(req("id:42"), "//*[@numFound='1']", "//str[.='BBB']");
+ assertU(adoc("id", "42", "val_s", "CCC"));
+ assertU(adoc("id", "42", "val_s", "DDD"));
+ assertU(commit());
+ assertQ(req("id:42"), "//*[@numFound='1']", "//str[.='DDD']");
+
+ // test deletes
+ String[] adds = new String[] { add(doc("id", "101"), "overwrite", "true"),
+ add(doc("id", "101"), "overwrite", "true"),
+ add(doc("id", "105"), "overwrite", "false"),
+ add(doc("id", "102"), "overwrite", "true"),
+ add(doc("id", "103"), "overwrite", "false"),
+ add(doc("id", "101"), "overwrite", "true"), };
+ for (String a : adds) {
+ assertU(a, a);
+ }
+ assertU(commit());
+
+ zkServer.shutdown();
+
+ Thread.sleep(300);
+
+ // try a reconnect from disconnect
+ zkServer = new ZkTestServer(zkDir);
+ zkServer.run();
+
+ Thread.sleep(300);
+
+ // ensure zk still thinks node is up
+ assertTrue(
+ zkController.getCloudState().getLiveNodes().toString(),
+ zkController.getCloudState().liveNodesContain(
+ zkController.getNodeName()));
+
+ // test maxint
+ assertQ(req("q", "id:[100 TO 110]", "rows", "2147483647"),
+ "//*[@numFound='4']");
+
+ // test big limit
+ assertQ(req("q", "id:[100 TO 111]", "rows", "1147483647"),
+ "//*[@numFound='4']");
+
+ assertQ(req("id:[100 TO 110]"), "//*[@numFound='4']");
+ assertU(delI("102"));
+ assertU(commit());
+ assertQ(req("id:[100 TO 110]"), "//*[@numFound='3']");
+ assertU(delI("105"));
+ assertU(commit());
+ assertQ(req("id:[100 TO 110]"), "//*[@numFound='2']");
+ assertU(delQ("id:[100 TO 110]"));
+ assertU(commit());
+ assertQ(req("id:[100 TO 110]"), "//*[@numFound='0']");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ System.clearProperty("CLOUD_UPDATE_DELAY");
+ }
+}
Modified: lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/CloudStateUpdateTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/CloudStateUpdateTest.java?rev=1068718&r1=1068717&r2=1068718&view=diff
==============================================================================
--- lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/CloudStateUpdateTest.java (original)
+++ lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/CloudStateUpdateTest.java Wed Feb 9 01:03:49 2011
@@ -1,254 +1,255 @@
-package org.apache.solr.cloud;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.File;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.common.cloud.CloudState;
-import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.cloud.SolrZkClient;
-import org.apache.solr.common.cloud.ZkNodeProps;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.CoreContainer.Initializer;
-import org.apache.solr.core.CoreDescriptor;
-import org.apache.solr.core.SolrConfig;
-import org.apache.solr.core.SolrCore;
-import org.apache.zookeeper.CreateMode;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * TODO: look at hostPort used below
- */
-public class CloudStateUpdateTest extends SolrTestCaseJ4 {
- protected static Logger log = LoggerFactory
- .getLogger(AbstractZkTestCase.class);
-
- private static final boolean VERBOSE = false;
-
- protected ZkTestServer zkServer;
-
- protected String zkDir;
-
- private CoreContainer container1;
-
- private CoreContainer container2;
-
- private CoreContainer container3;
-
- private File dataDir1;
-
- private File dataDir2;
-
- private File dataDir3;
-
- private File dataDir4;
-
- private Initializer init2;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- initCore();
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- System.setProperty("zkClientTimeout", "3000");
-
- zkDir = dataDir.getAbsolutePath() + File.separator
- + "zookeeper/server1/data";
- zkServer = new ZkTestServer(zkDir);
- zkServer.run();
- System.setProperty("zkHost", zkServer.getZkAddress());
- AbstractZkTestCase.buildZooKeeper(zkServer.getZkHost(), zkServer
- .getZkAddress(), "solrconfig.xml", "schema.xml");
-
- log.info("####SETUP_START " + getName());
- dataDir1 = new File(dataDir + File.separator + "data1");
- dataDir1.mkdirs();
-
- dataDir2 = new File(dataDir + File.separator + "data2");
- dataDir2.mkdirs();
-
- dataDir3 = new File(dataDir + File.separator + "data3");
- dataDir3.mkdirs();
-
- dataDir4 = new File(dataDir + File.separator + "data3");
- dataDir4.mkdirs();
-
- // set some system properties for use by tests
- System.setProperty("solr.test.sys.prop1", "propone");
- System.setProperty("solr.test.sys.prop2", "proptwo");
-
- System.setProperty("hostPort", "1661");
- CoreContainer.Initializer init1 = new CoreContainer.Initializer() {
- {
- this.dataDir = CloudStateUpdateTest.this.dataDir1.getAbsolutePath();
- }
- };
-
- container1 = init1.initialize();
- System.clearProperty("hostPort");
-
- System.setProperty("hostPort", "1662");
- init2 = new CoreContainer.Initializer() {
- {
- this.dataDir = CloudStateUpdateTest.this.dataDir2.getAbsolutePath();
- }
- };
-
- container2 = init2.initialize();
- System.clearProperty("hostPort");
-
- System.setProperty("hostPort", "1663");
- CoreContainer.Initializer init3 = new CoreContainer.Initializer() {
- {
- this.dataDir = CloudStateUpdateTest.this.dataDir3.getAbsolutePath();
- }
- };
- container3 = init3.initialize();
- System.clearProperty("hostPort");
-
- log.info("####SETUP_END " + getName());
-
- }
-
- @Test
- public void testCoreRegistration() throws Exception {
- System.setProperty("CLOUD_UPDATE_DELAY", "1");
-
- ZkNodeProps props2 = new ZkNodeProps();
- props2.put("configName", "conf1");
-
- SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
- zkClient.makePath("/collections/testcore", props2.store(), CreateMode.PERSISTENT);
- zkClient.makePath("/collections/testcore/shards", CreateMode.PERSISTENT);
- zkClient.close();
-
- CoreDescriptor dcore = new CoreDescriptor(container1, "testcore",
- "testcore");
-
- dcore.setDataDir(dataDir4.getAbsolutePath());
-
- SolrCore core = container1.create(dcore);
- container1.register(core, false);
-
- ZkController zkController2 = container2.getZkController();
-
- String host = zkController2.getHostName();
-
- // slight pause - TODO: takes an oddly long amount of time to schedule tasks
- // with almost no delay ...
- CloudState cloudState2 = null;
- Map<String,Slice> slices = null;
- for (int i = 75; i > 0; i--) {
- cloudState2 = zkController2.getCloudState();
- slices = cloudState2.getSlices("testcore");
-
- if (slices != null && slices.containsKey(host + ":1661_solr_testcore")) {
- break;
- }
- Thread.sleep(500);
- }
-
- assertNotNull(slices);
- assertTrue(slices.containsKey(host + ":1661_solr_testcore"));
-
- Slice slice = slices.get(host + ":1661_solr_testcore");
- assertEquals(host + ":1661_solr_testcore", slice.getName());
-
- Map<String,ZkNodeProps> shards = slice.getShards();
-
- assertEquals(1, shards.size());
-
- ZkNodeProps zkProps = shards.get(host + ":1661_solr_testcore");
-
- assertNotNull(zkProps);
-
- assertEquals(host + ":1661_solr", zkProps.get("node_name"));
-
- assertEquals("http://" + host + ":1661/solr/testcore", zkProps.get("url"));
-
- Set<String> liveNodes = cloudState2.getLiveNodes();
- assertNotNull(liveNodes);
- assertEquals(3, liveNodes.size());
-
- container3.shutdown();
-
- // slight pause (15s timeout) for watch to trigger
- for(int i = 0; i < (5 * 15); i++) {
- if(zkController2.getCloudState().getLiveNodes().size() == 2) {
- break;
- }
- Thread.sleep(200);
- }
-
- assertEquals(2, zkController2.getCloudState().getLiveNodes().size());
-
- // quickly kill / start client
-
- container2.getZkController().getZkClient().getSolrZooKeeper().getConnection()
- .disconnect();
- container2.shutdown();
-
- container2 = init2.initialize();
-
- // pause for watch to trigger
- for(int i = 0; i < 200; i++) {
- if (container1.getZkController().getCloudState().liveNodesContain(
- container2.getZkController().getNodeName())) {
- break;
- }
- Thread.sleep(100);
- }
-
- assertTrue(container1.getZkController().getCloudState().liveNodesContain(
- container2.getZkController().getNodeName()));
-
- }
-
- public void tearDown() throws Exception {
- if (VERBOSE) {
- printLayout(zkServer.getZkHost());
- }
- container1.shutdown();
- container2.shutdown();
- container3.shutdown();
- zkServer.shutdown();
- super.tearDown();
- System.clearProperty("zkClientTimeout");
- System.clearProperty("zkHost");
- System.clearProperty("hostPort");
- System.clearProperty("CLOUD_UPDATE_DELAY");
- SolrConfig.severeErrors.clear();
- }
-
- private void printLayout(String zkHost) throws Exception {
- SolrZkClient zkClient = new SolrZkClient(
- zkHost, AbstractZkTestCase.TIMEOUT);
- zkClient.printLayoutToStdOut();
- zkClient.close();
- }
-}
+package org.apache.solr.cloud;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.cloud.CloudState;
+import org.apache.solr.common.cloud.Slice;
+import org.apache.solr.common.cloud.SolrZkClient;
+import org.apache.solr.common.cloud.ZkNodeProps;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreContainer.Initializer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.core.SolrCore;
+import org.apache.zookeeper.CreateMode;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TODO: look at hostPort used below
+ */
+public class CloudStateUpdateTest extends SolrTestCaseJ4 {
+ protected static Logger log = LoggerFactory
+ .getLogger(AbstractZkTestCase.class);
+
+ private static final boolean VERBOSE = false;
+
+ protected ZkTestServer zkServer;
+
+ protected String zkDir;
+
+ private CoreContainer container1;
+
+ private CoreContainer container2;
+
+ private CoreContainer container3;
+
+ private File dataDir1;
+
+ private File dataDir2;
+
+ private File dataDir3;
+
+ private File dataDir4;
+
+ private Initializer init2;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ System.setProperty("zkClientTimeout", "3000");
+
+ zkDir = dataDir.getAbsolutePath() + File.separator
+ + "zookeeper/server1/data";
+ zkServer = new ZkTestServer(zkDir);
+ zkServer.run();
+ System.setProperty("zkHost", zkServer.getZkAddress());
+ AbstractZkTestCase.buildZooKeeper(zkServer.getZkHost(), zkServer
+ .getZkAddress(), "solrconfig.xml", "schema.xml");
+
+ log.info("####SETUP_START " + getName());
+ dataDir1 = new File(dataDir + File.separator + "data1");
+ dataDir1.mkdirs();
+
+ dataDir2 = new File(dataDir + File.separator + "data2");
+ dataDir2.mkdirs();
+
+ dataDir3 = new File(dataDir + File.separator + "data3");
+ dataDir3.mkdirs();
+
+ dataDir4 = new File(dataDir + File.separator + "data3");
+ dataDir4.mkdirs();
+
+ // set some system properties for use by tests
+ System.setProperty("solr.test.sys.prop1", "propone");
+ System.setProperty("solr.test.sys.prop2", "proptwo");
+
+ System.setProperty("hostPort", "1661");
+ CoreContainer.Initializer init1 = new CoreContainer.Initializer() {
+ {
+ this.dataDir = CloudStateUpdateTest.this.dataDir1.getAbsolutePath();
+ }
+ };
+
+ container1 = init1.initialize();
+ System.clearProperty("hostPort");
+
+ System.setProperty("hostPort", "1662");
+ init2 = new CoreContainer.Initializer() {
+ {
+ this.dataDir = CloudStateUpdateTest.this.dataDir2.getAbsolutePath();
+ }
+ };
+
+ container2 = init2.initialize();
+ System.clearProperty("hostPort");
+
+ System.setProperty("hostPort", "1663");
+ CoreContainer.Initializer init3 = new CoreContainer.Initializer() {
+ {
+ this.dataDir = CloudStateUpdateTest.this.dataDir3.getAbsolutePath();
+ }
+ };
+ container3 = init3.initialize();
+ System.clearProperty("hostPort");
+
+ log.info("####SETUP_END " + getName());
+
+ }
+
+ @Test
+ public void testCoreRegistration() throws Exception {
+ System.setProperty("CLOUD_UPDATE_DELAY", "1");
+
+ ZkNodeProps props2 = new ZkNodeProps();
+ props2.put("configName", "conf1");
+
+ SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
+ zkClient.makePath("/collections/testcore", props2.store(), CreateMode.PERSISTENT);
+ zkClient.makePath("/collections/testcore/shards", CreateMode.PERSISTENT);
+ zkClient.close();
+
+ CoreDescriptor dcore = new CoreDescriptor(container1, "testcore",
+ "testcore");
+
+ dcore.setDataDir(dataDir4.getAbsolutePath());
+
+ SolrCore core = container1.create(dcore);
+ container1.register(core, false);
+
+ ZkController zkController2 = container2.getZkController();
+
+ String host = zkController2.getHostName();
+
+ // slight pause - TODO: takes an oddly long amount of time to schedule tasks
+ // with almost no delay ...
+ CloudState cloudState2 = null;
+ Map<String,Slice> slices = null;
+ for (int i = 75; i > 0; i--) {
+ cloudState2 = zkController2.getCloudState();
+ slices = cloudState2.getSlices("testcore");
+
+ if (slices != null && slices.containsKey(host + ":1661_solr_testcore")) {
+ break;
+ }
+ Thread.sleep(500);
+ }
+
+ assertNotNull(slices);
+ assertTrue(slices.containsKey(host + ":1661_solr_testcore"));
+
+ Slice slice = slices.get(host + ":1661_solr_testcore");
+ assertEquals(host + ":1661_solr_testcore", slice.getName());
+
+ Map<String,ZkNodeProps> shards = slice.getShards();
+
+ assertEquals(1, shards.size());
+
+ ZkNodeProps zkProps = shards.get(host + ":1661_solr_testcore");
+
+ assertNotNull(zkProps);
+
+ assertEquals(host + ":1661_solr", zkProps.get("node_name"));
+
+ assertEquals("http://" + host + ":1661/solr/testcore", zkProps.get("url"));
+
+ Set<String> liveNodes = cloudState2.getLiveNodes();
+ assertNotNull(liveNodes);
+ assertEquals(3, liveNodes.size());
+
+ container3.shutdown();
+
+ // slight pause (15s timeout) for watch to trigger
+ for(int i = 0; i < (5 * 15); i++) {
+ if(zkController2.getCloudState().getLiveNodes().size() == 2) {
+ break;
+ }
+ Thread.sleep(200);
+ }
+
+ assertEquals(2, zkController2.getCloudState().getLiveNodes().size());
+
+ // quickly kill / start client
+
+ container2.getZkController().getZkClient().getSolrZooKeeper().getConnection()
+ .disconnect();
+ container2.shutdown();
+
+ container2 = init2.initialize();
+
+ // pause for watch to trigger
+ for(int i = 0; i < 200; i++) {
+ if (container1.getZkController().getCloudState().liveNodesContain(
+ container2.getZkController().getNodeName())) {
+ break;
+ }
+ Thread.sleep(100);
+ }
+
+ assertTrue(container1.getZkController().getCloudState().liveNodesContain(
+ container2.getZkController().getNodeName()));
+
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ if (VERBOSE) {
+ printLayout(zkServer.getZkHost());
+ }
+ container1.shutdown();
+ container2.shutdown();
+ container3.shutdown();
+ zkServer.shutdown();
+ super.tearDown();
+ System.clearProperty("zkClientTimeout");
+ System.clearProperty("zkHost");
+ System.clearProperty("hostPort");
+ System.clearProperty("CLOUD_UPDATE_DELAY");
+ SolrConfig.severeErrors.clear();
+ }
+
+ private void printLayout(String zkHost) throws Exception {
+ SolrZkClient zkClient = new SolrZkClient(
+ zkHost, AbstractZkTestCase.TIMEOUT);
+ zkClient.printLayoutToStdOut();
+ zkClient.close();
+ }
+}
Modified: lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkControllerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkControllerTest.java?rev=1068718&r1=1068717&r2=1068718&view=diff
==============================================================================
--- lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkControllerTest.java (original)
+++ lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkControllerTest.java Wed Feb 9 01:03:49 2011
@@ -1,224 +1,225 @@
-package org.apache.solr.cloud;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Map;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.common.cloud.CloudState;
-import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.cloud.SolrZkClient;
-import org.apache.solr.common.cloud.ZkNodeProps;
-import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.core.SolrConfig;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class ZkControllerTest extends SolrTestCaseJ4 {
-
- private static final String TEST_NODE_NAME = "test_node_name";
-
- private static final String URL3 = "http://localhost:3133/solr/core1";
-
- private static final String URL2 = "http://localhost:3123/solr/core1";
-
- private static final String SHARD3 = "localhost:3123_solr_core3";
-
- private static final String SHARD2 = "localhost:3123_solr_core2";
-
- private static final String SHARD1 = "localhost:3123_solr_core1";
-
- private static final String COLLECTION_NAME = "collection1";
-
- static final int TIMEOUT = 10000;
-
- private static final String URL1 = "http://localhost:3133/solr/core0";
-
- private static final boolean DEBUG = false;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- initCore();
- }
-
- @Test
- public void testReadShards() throws Exception {
- String zkDir = dataDir.getAbsolutePath() + File.separator
- + "zookeeper/server1/data";
- ZkTestServer server = null;
- SolrZkClient zkClient = null;
- ZkController zkController = null;
- try {
- server = new ZkTestServer(zkDir);
- server.run();
- AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
- AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
-
- zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
- String shardsPath = "/collections/collection1/shards/shardid1";
- zkClient.makePath(shardsPath);
-
- addShardToZk(zkClient, shardsPath, SHARD1, URL1);
- addShardToZk(zkClient, shardsPath, SHARD2, URL2);
- addShardToZk(zkClient, shardsPath, SHARD3, URL3);
-
- if (DEBUG) {
- zkClient.printLayoutToStdOut();
- }
-
- zkController = new ZkController(server.getZkAddress(),
- TIMEOUT, 1000, "localhost", "8983", "solr");
-
- zkController.getZkStateReader().updateCloudState(true);
- CloudState cloudInfo = zkController.getCloudState();
- Map<String,Slice> slices = cloudInfo.getSlices("collection1");
- assertNotNull(slices);
-
- for (Slice slice : slices.values()) {
- Map<String,ZkNodeProps> shards = slice.getShards();
- if (DEBUG) {
- for (String shardName : shards.keySet()) {
- ZkNodeProps props = shards.get(shardName);
- System.out.println("shard:" + shardName);
- System.out.println("props:" + props.toString());
- }
- }
- assertNotNull(shards.get(SHARD1));
- assertNotNull(shards.get(SHARD2));
- assertNotNull(shards.get(SHARD3));
-
- ZkNodeProps props = shards.get(SHARD1);
- assertEquals(URL1, props.get(ZkStateReader.URL_PROP));
- assertEquals(TEST_NODE_NAME, props.get(ZkStateReader.NODE_NAME));
-
- props = shards.get(SHARD2);
- assertEquals(URL2, props.get(ZkStateReader.URL_PROP));
- assertEquals(TEST_NODE_NAME, props.get(ZkStateReader.NODE_NAME));
-
- props = shards.get(SHARD3);
- assertEquals(URL3, props.get(ZkStateReader.URL_PROP));
- assertEquals(TEST_NODE_NAME, props.get(ZkStateReader.NODE_NAME));
-
- }
-
- } finally {
- if (zkClient != null) {
- zkClient.close();
- }
- if (zkController != null) {
- zkController.close();
- }
- if (server != null) {
- server.shutdown();
- }
- }
- }
-
- @Test
- public void testReadConfigName() throws Exception {
- String zkDir = dataDir.getAbsolutePath() + File.separator
- + "zookeeper/server1/data";
-
- ZkTestServer server = new ZkTestServer(zkDir);
- try {
- server.run();
-
- AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
-
- SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
- String actualConfigName = "firstConfig";
-
- zkClient.makePath(ZkController.CONFIGS_ZKNODE + "/" + actualConfigName);
-
- ZkNodeProps props = new ZkNodeProps();
- props.put("configName", actualConfigName);
- zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION_NAME , props.store(), CreateMode.PERSISTENT);
-
- if (DEBUG) {
- zkClient.printLayoutToStdOut();
- }
- zkClient.close();
- ZkController zkController = new ZkController(server.getZkAddress(), TIMEOUT, TIMEOUT,
- "localhost", "8983", "/solr");
- try {
- String configName = zkController.readConfigName(COLLECTION_NAME);
- assertEquals(configName, actualConfigName);
- } finally {
- zkController.close();
- }
- } finally {
-
- server.shutdown();
- }
-
- }
-
- @Test
- public void testUploadToCloud() throws Exception {
- String zkDir = dataDir.getAbsolutePath() + File.separator
- + "zookeeper/server1/data";
-
- ZkTestServer server = new ZkTestServer(zkDir);
- ZkController zkController = null;
- try {
- server.run();
-
- AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
-
- zkController = new ZkController(server.getZkAddress(),
- TIMEOUT, 1000, "localhost", "8983", "/solr");
-
- zkController.uploadToZK(getFile("solr/conf"),
- ZkController.CONFIGS_ZKNODE + "/config1");
-
- if (DEBUG) {
- zkController.printLayoutToStdOut();
- }
-
- } finally {
- if (zkController != null) {
- zkController.close();
- }
- server.shutdown();
- }
-
- }
-
- private void addShardToZk(SolrZkClient zkClient, String shardsPath,
- String zkNodeName, String url) throws IOException,
- KeeperException, InterruptedException {
-
- ZkNodeProps props = new ZkNodeProps();
- props.put(ZkStateReader.URL_PROP, url);
- props.put(ZkStateReader.NODE_NAME, TEST_NODE_NAME);
- byte[] bytes = props.store();
-
- zkClient
- .create(shardsPath + "/" + zkNodeName, bytes, CreateMode.PERSISTENT);
- }
-
- public void tearDown() throws Exception {
- SolrConfig.severeErrors.clear();
- super.tearDown();
- }
-}
+package org.apache.solr.cloud;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.cloud.CloudState;
+import org.apache.solr.common.cloud.Slice;
+import org.apache.solr.common.cloud.SolrZkClient;
+import org.apache.solr.common.cloud.ZkNodeProps;
+import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.core.SolrConfig;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ZkControllerTest extends SolrTestCaseJ4 {
+
+ private static final String TEST_NODE_NAME = "test_node_name";
+
+ private static final String URL3 = "http://localhost:3133/solr/core1";
+
+ private static final String URL2 = "http://localhost:3123/solr/core1";
+
+ private static final String SHARD3 = "localhost:3123_solr_core3";
+
+ private static final String SHARD2 = "localhost:3123_solr_core2";
+
+ private static final String SHARD1 = "localhost:3123_solr_core1";
+
+ private static final String COLLECTION_NAME = "collection1";
+
+ static final int TIMEOUT = 10000;
+
+ private static final String URL1 = "http://localhost:3133/solr/core0";
+
+ private static final boolean DEBUG = false;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore();
+ }
+
+ @Test
+ public void testReadShards() throws Exception {
+ String zkDir = dataDir.getAbsolutePath() + File.separator
+ + "zookeeper/server1/data";
+ ZkTestServer server = null;
+ SolrZkClient zkClient = null;
+ ZkController zkController = null;
+ try {
+ server = new ZkTestServer(zkDir);
+ server.run();
+ AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
+ AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
+
+ zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
+ String shardsPath = "/collections/collection1/shards/shardid1";
+ zkClient.makePath(shardsPath);
+
+ addShardToZk(zkClient, shardsPath, SHARD1, URL1);
+ addShardToZk(zkClient, shardsPath, SHARD2, URL2);
+ addShardToZk(zkClient, shardsPath, SHARD3, URL3);
+
+ if (DEBUG) {
+ zkClient.printLayoutToStdOut();
+ }
+
+ zkController = new ZkController(server.getZkAddress(),
+ TIMEOUT, 1000, "localhost", "8983", "solr");
+
+ zkController.getZkStateReader().updateCloudState(true);
+ CloudState cloudInfo = zkController.getCloudState();
+ Map<String,Slice> slices = cloudInfo.getSlices("collection1");
+ assertNotNull(slices);
+
+ for (Slice slice : slices.values()) {
+ Map<String,ZkNodeProps> shards = slice.getShards();
+ if (DEBUG) {
+ for (String shardName : shards.keySet()) {
+ ZkNodeProps props = shards.get(shardName);
+ System.out.println("shard:" + shardName);
+ System.out.println("props:" + props.toString());
+ }
+ }
+ assertNotNull(shards.get(SHARD1));
+ assertNotNull(shards.get(SHARD2));
+ assertNotNull(shards.get(SHARD3));
+
+ ZkNodeProps props = shards.get(SHARD1);
+ assertEquals(URL1, props.get(ZkStateReader.URL_PROP));
+ assertEquals(TEST_NODE_NAME, props.get(ZkStateReader.NODE_NAME));
+
+ props = shards.get(SHARD2);
+ assertEquals(URL2, props.get(ZkStateReader.URL_PROP));
+ assertEquals(TEST_NODE_NAME, props.get(ZkStateReader.NODE_NAME));
+
+ props = shards.get(SHARD3);
+ assertEquals(URL3, props.get(ZkStateReader.URL_PROP));
+ assertEquals(TEST_NODE_NAME, props.get(ZkStateReader.NODE_NAME));
+
+ }
+
+ } finally {
+ if (zkClient != null) {
+ zkClient.close();
+ }
+ if (zkController != null) {
+ zkController.close();
+ }
+ if (server != null) {
+ server.shutdown();
+ }
+ }
+ }
+
+ @Test
+ public void testReadConfigName() throws Exception {
+ String zkDir = dataDir.getAbsolutePath() + File.separator
+ + "zookeeper/server1/data";
+
+ ZkTestServer server = new ZkTestServer(zkDir);
+ try {
+ server.run();
+
+ AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
+
+ SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
+ String actualConfigName = "firstConfig";
+
+ zkClient.makePath(ZkController.CONFIGS_ZKNODE + "/" + actualConfigName);
+
+ ZkNodeProps props = new ZkNodeProps();
+ props.put("configName", actualConfigName);
+ zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION_NAME , props.store(), CreateMode.PERSISTENT);
+
+ if (DEBUG) {
+ zkClient.printLayoutToStdOut();
+ }
+ zkClient.close();
+ ZkController zkController = new ZkController(server.getZkAddress(), TIMEOUT, TIMEOUT,
+ "localhost", "8983", "/solr");
+ try {
+ String configName = zkController.readConfigName(COLLECTION_NAME);
+ assertEquals(configName, actualConfigName);
+ } finally {
+ zkController.close();
+ }
+ } finally {
+
+ server.shutdown();
+ }
+
+ }
+
+ @Test
+ public void testUploadToCloud() throws Exception {
+ String zkDir = dataDir.getAbsolutePath() + File.separator
+ + "zookeeper/server1/data";
+
+ ZkTestServer server = new ZkTestServer(zkDir);
+ ZkController zkController = null;
+ try {
+ server.run();
+
+ AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
+
+ zkController = new ZkController(server.getZkAddress(),
+ TIMEOUT, 1000, "localhost", "8983", "/solr");
+
+ zkController.uploadToZK(getFile("solr/conf"),
+ ZkController.CONFIGS_ZKNODE + "/config1");
+
+ if (DEBUG) {
+ zkController.printLayoutToStdOut();
+ }
+
+ } finally {
+ if (zkController != null) {
+ zkController.close();
+ }
+ server.shutdown();
+ }
+
+ }
+
+ private void addShardToZk(SolrZkClient zkClient, String shardsPath,
+ String zkNodeName, String url) throws IOException,
+ KeeperException, InterruptedException {
+
+ ZkNodeProps props = new ZkNodeProps();
+ props.put(ZkStateReader.URL_PROP, url);
+ props.put(ZkStateReader.NODE_NAME, TEST_NODE_NAME);
+ byte[] bytes = props.store();
+
+ zkClient
+ .create(shardsPath + "/" + zkNodeName, bytes, CreateMode.PERSISTENT);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ SolrConfig.severeErrors.clear();
+ super.tearDown();
+ }
+}
Modified: lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkNodePropsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkNodePropsTest.java?rev=1068718&r1=1068717&r2=1068718&view=diff
==============================================================================
--- lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkNodePropsTest.java (original)
+++ lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkNodePropsTest.java Wed Feb 9 01:03:49 2011
@@ -1,49 +1,49 @@
-package org.apache.solr.cloud;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-import java.io.IOException;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.common.cloud.ZkNodeProps;
-import org.junit.Test;
-
-
-public class ZkNodePropsTest extends SolrTestCaseJ4 {
- @Test
- public void testBasic() throws IOException {
-
- ZkNodeProps props = new ZkNodeProps();
- props.put("prop1", "value1");
- props.put("prop2", "value2");
- props.put("prop3", "value3");
- props.put("prop4", "value4");
- props.put("prop5", "value5");
- props.put("prop6", "value6");
- byte[] bytes = props.store();
-
- ZkNodeProps props2 = new ZkNodeProps();
- props2.load(bytes);
- assertEquals("value1", props2.get("prop1"));
- assertEquals("value2", props2.get("prop2"));
- assertEquals("value3", props2.get("prop3"));
- assertEquals("value4", props2.get("prop4"));
- assertEquals("value5", props2.get("prop5"));
- assertEquals("value6", props2.get("prop6"));
- }
-}
+package org.apache.solr.cloud;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.cloud.ZkNodeProps;
+import org.junit.Test;
+
+
+public class ZkNodePropsTest extends SolrTestCaseJ4 {
+ @Test
+ public void testBasic() throws IOException {
+
+ ZkNodeProps props = new ZkNodeProps();
+ props.put("prop1", "value1");
+ props.put("prop2", "value2");
+ props.put("prop3", "value3");
+ props.put("prop4", "value4");
+ props.put("prop5", "value5");
+ props.put("prop6", "value6");
+ byte[] bytes = props.store();
+
+ ZkNodeProps props2 = new ZkNodeProps();
+ props2.load(bytes);
+ assertEquals("value1", props2.get("prop1"));
+ assertEquals("value2", props2.get("prop2"));
+ assertEquals("value3", props2.get("prop3"));
+ assertEquals("value4", props2.get("prop4"));
+ assertEquals("value5", props2.get("prop5"));
+ assertEquals("value6", props2.get("prop6"));
+ }
+}
Modified: lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkSolrClientTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkSolrClientTest.java?rev=1068718&r1=1068717&r2=1068718&view=diff
==============================================================================
--- lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkSolrClientTest.java (original)
+++ lucene/dev/branches/bulkpostings/solr/src/test/org/apache/solr/cloud/ZkSolrClientTest.java Wed Feb 9 01:03:49 2011
@@ -1,240 +1,241 @@
-package org.apache.solr.cloud;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-import java.io.File;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import junit.framework.TestCase;
-
-import org.apache.solr.common.cloud.SolrZkClient;
-import org.apache.solr.core.SolrConfig;
-import org.apache.solr.util.AbstractSolrTestCase;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-
-public class ZkSolrClientTest extends AbstractSolrTestCase {
- private static final boolean DEBUG = false;
-
- public void testConnect() throws Exception {
- String zkDir = dataDir.getAbsolutePath() + File.separator
- + "zookeeper/server1/data";
- ZkTestServer server = null;
-
- server = new ZkTestServer(zkDir);
- server.run();
-
- SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), 100);
-
- zkClient.close();
- server.shutdown();
- }
-
- public void testMakeRootNode() throws Exception {
- String zkDir = dataDir.getAbsolutePath() + File.separator
- + "zookeeper/server1/data";
- ZkTestServer server = null;
-
- server = new ZkTestServer(zkDir);
- server.run();
-
- AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
-
- SolrZkClient zkClient = new SolrZkClient(server.getZkHost(),
- AbstractZkTestCase.TIMEOUT);
-
- assertTrue(zkClient.exists("/solr"));
-
- zkClient.close();
- server.shutdown();
- }
-
- public void testReconnect() throws Exception {
- String zkDir = dataDir.getAbsolutePath() + File.separator
- + "zookeeper/server1/data";
- ZkTestServer server = null;
- SolrZkClient zkClient = null;
- try {
- server = new ZkTestServer(zkDir);
- server.run();
-
- AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
-
- zkClient = new SolrZkClient(server.getZkAddress(), AbstractZkTestCase.TIMEOUT);
- String shardsPath = "/collections/collection1/shards";
- zkClient.makePath(shardsPath);
-
- zkClient.makePath("collections/collection1");
- int zkServerPort = server.getPort();
- // this tests disconnect state
- server.shutdown();
-
- Thread.sleep(80);
-
-
- try {
- zkClient.makePath("collections/collection2");
- TestCase.fail("Server should be down here");
- } catch (KeeperException.ConnectionLossException e) {
-
- }
-
- // bring server back up
- server = new ZkTestServer(zkDir, zkServerPort);
- server.run();
-
- // TODO: can we do better?
- // wait for reconnect
- Thread.sleep(600);
-
- try {
- zkClient.makePath("collections/collection3");
- } catch (KeeperException.ConnectionLossException e) {
- Thread.sleep(5000); // try again in a bit
- zkClient.makePath("collections/collection3");
- }
-
- if (DEBUG) {
- zkClient.printLayoutToStdOut();
- }
-
- assertNotNull(zkClient.exists("/collections/collection3", null));
- assertNotNull(zkClient.exists("/collections/collection1", null));
-
- // simulate session expiration
-
- // one option
- long sessionId = zkClient.getSolrZooKeeper().getSessionId();
- server.expire(sessionId);
-
- // another option
- //zkClient.getSolrZooKeeper().getConnection().disconnect();
-
- // this tests expired state
-
- Thread.sleep(1000); // pause for reconnect
-
- for (int i = 0; i < 8; i++) {
- try {
- zkClient.makePath("collections/collection4");
- break;
- } catch (KeeperException.SessionExpiredException e) {
-
- } catch (KeeperException.ConnectionLossException e) {
-
- }
- Thread.sleep(1000 * i);
- }
-
- if (DEBUG) {
- zkClient.printLayoutToStdOut();
- }
-
- assertNotNull("Node does not exist, but it should", zkClient.exists("/collections/collection4", null));
-
- } finally {
-
- if (zkClient != null) {
- zkClient.close();
- }
- if (server != null) {
- server.shutdown();
- }
- }
- }
-
- public void testWatchChildren() throws Exception {
- String zkDir = dataDir.getAbsolutePath() + File.separator
- + "zookeeper/server1/data";
-
- final AtomicInteger cnt = new AtomicInteger();
- ZkTestServer server = new ZkTestServer(zkDir);
- server.run();
- Thread.sleep(400);
- AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
- final SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), AbstractZkTestCase.TIMEOUT);
- try {
- zkClient.makePath("/collections");
-
- zkClient.getChildren("/collections", new Watcher() {
-
- public void process(WatchedEvent event) {
- if (DEBUG) {
- System.out.println("children changed");
- }
- cnt.incrementAndGet();
- // remake watch
- try {
- zkClient.getChildren("/collections", this);
- } catch (KeeperException e) {
- throw new RuntimeException(e);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- });
-
- zkClient.makePath("/collections/collection99/shards");
-
- zkClient.makePath("collections/collection99/config=collection1");
-
- zkClient.makePath("collections/collection99/config=collection3");
-
- zkClient.makePath("/collections/collection97/shards");
-
- if (DEBUG) {
- zkClient.printLayoutToStdOut();
- }
-
- // pause for the watches to fire
- Thread.sleep(700);
-
- if (cnt.intValue() < 2) {
- Thread.sleep(4000); // wait a bit more
- }
-
- assertEquals(2, cnt.intValue());
-
- } finally {
-
- if (zkClient != null) {
- zkClient.close();
- }
- if (server != null) {
- server.shutdown();
- }
- }
- }
-
- @Override
- public String getSchemaFile() {
- return null;
- }
-
- @Override
- public String getSolrConfigFile() {
- return null;
- }
-
- public void tearDown() throws Exception {
- SolrConfig.severeErrors.clear();
- super.tearDown();
- }
-
-}
+package org.apache.solr.cloud;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+import java.io.File;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import junit.framework.TestCase;
+
+import org.apache.solr.common.cloud.SolrZkClient;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.util.AbstractSolrTestCase;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+
+public class ZkSolrClientTest extends AbstractSolrTestCase {
+ private static final boolean DEBUG = false;
+
+ public void testConnect() throws Exception {
+ String zkDir = dataDir.getAbsolutePath() + File.separator
+ + "zookeeper/server1/data";
+ ZkTestServer server = null;
+
+ server = new ZkTestServer(zkDir);
+ server.run();
+
+ SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), 100);
+
+ zkClient.close();
+ server.shutdown();
+ }
+
+ public void testMakeRootNode() throws Exception {
+ String zkDir = dataDir.getAbsolutePath() + File.separator
+ + "zookeeper/server1/data";
+ ZkTestServer server = null;
+
+ server = new ZkTestServer(zkDir);
+ server.run();
+
+ AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
+
+ SolrZkClient zkClient = new SolrZkClient(server.getZkHost(),
+ AbstractZkTestCase.TIMEOUT);
+
+ assertTrue(zkClient.exists("/solr"));
+
+ zkClient.close();
+ server.shutdown();
+ }
+
+ public void testReconnect() throws Exception {
+ String zkDir = dataDir.getAbsolutePath() + File.separator
+ + "zookeeper/server1/data";
+ ZkTestServer server = null;
+ SolrZkClient zkClient = null;
+ try {
+ server = new ZkTestServer(zkDir);
+ server.run();
+
+ AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
+
+ zkClient = new SolrZkClient(server.getZkAddress(), AbstractZkTestCase.TIMEOUT);
+ String shardsPath = "/collections/collection1/shards";
+ zkClient.makePath(shardsPath);
+
+ zkClient.makePath("collections/collection1");
+ int zkServerPort = server.getPort();
+ // this tests disconnect state
+ server.shutdown();
+
+ Thread.sleep(80);
+
+
+ try {
+ zkClient.makePath("collections/collection2");
+ TestCase.fail("Server should be down here");
+ } catch (KeeperException.ConnectionLossException e) {
+
+ }
+
+ // bring server back up
+ server = new ZkTestServer(zkDir, zkServerPort);
+ server.run();
+
+ // TODO: can we do better?
+ // wait for reconnect
+ Thread.sleep(600);
+
+ try {
+ zkClient.makePath("collections/collection3");
+ } catch (KeeperException.ConnectionLossException e) {
+ Thread.sleep(5000); // try again in a bit
+ zkClient.makePath("collections/collection3");
+ }
+
+ if (DEBUG) {
+ zkClient.printLayoutToStdOut();
+ }
+
+ assertNotNull(zkClient.exists("/collections/collection3", null));
+ assertNotNull(zkClient.exists("/collections/collection1", null));
+
+ // simulate session expiration
+
+ // one option
+ long sessionId = zkClient.getSolrZooKeeper().getSessionId();
+ server.expire(sessionId);
+
+ // another option
+ //zkClient.getSolrZooKeeper().getConnection().disconnect();
+
+ // this tests expired state
+
+ Thread.sleep(1000); // pause for reconnect
+
+ for (int i = 0; i < 8; i++) {
+ try {
+ zkClient.makePath("collections/collection4");
+ break;
+ } catch (KeeperException.SessionExpiredException e) {
+
+ } catch (KeeperException.ConnectionLossException e) {
+
+ }
+ Thread.sleep(1000 * i);
+ }
+
+ if (DEBUG) {
+ zkClient.printLayoutToStdOut();
+ }
+
+ assertNotNull("Node does not exist, but it should", zkClient.exists("/collections/collection4", null));
+
+ } finally {
+
+ if (zkClient != null) {
+ zkClient.close();
+ }
+ if (server != null) {
+ server.shutdown();
+ }
+ }
+ }
+
+ public void testWatchChildren() throws Exception {
+ String zkDir = dataDir.getAbsolutePath() + File.separator
+ + "zookeeper/server1/data";
+
+ final AtomicInteger cnt = new AtomicInteger();
+ ZkTestServer server = new ZkTestServer(zkDir);
+ server.run();
+ Thread.sleep(400);
+ AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
+ final SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), AbstractZkTestCase.TIMEOUT);
+ try {
+ zkClient.makePath("/collections");
+
+ zkClient.getChildren("/collections", new Watcher() {
+
+ public void process(WatchedEvent event) {
+ if (DEBUG) {
+ System.out.println("children changed");
+ }
+ cnt.incrementAndGet();
+ // remake watch
+ try {
+ zkClient.getChildren("/collections", this);
+ } catch (KeeperException e) {
+ throw new RuntimeException(e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+
+ zkClient.makePath("/collections/collection99/shards");
+
+ zkClient.makePath("collections/collection99/config=collection1");
+
+ zkClient.makePath("collections/collection99/config=collection3");
+
+ zkClient.makePath("/collections/collection97/shards");
+
+ if (DEBUG) {
+ zkClient.printLayoutToStdOut();
+ }
+
+ // pause for the watches to fire
+ Thread.sleep(700);
+
+ if (cnt.intValue() < 2) {
+ Thread.sleep(4000); // wait a bit more
+ }
+
+ assertEquals(2, cnt.intValue());
+
+ } finally {
+
+ if (zkClient != null) {
+ zkClient.close();
+ }
+ if (server != null) {
+ server.shutdown();
+ }
+ }
+ }
+
+ @Override
+ public String getSchemaFile() {
+ return null;
+ }
+
+ @Override
+ public String getSolrConfigFile() {
+ return null;
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ SolrConfig.severeErrors.clear();
+ super.tearDown();
+ }
+
+}