Copied: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/AbstractZooKeeperTestCase.java (from r892824, lucene/solr/branches/cloud/src/test/org/apache/solr/AbstractZooKeeperTestCase.java) URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/AbstractZooKeeperTestCase.java?p2=lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/AbstractZooKeeperTestCase.java&p1=lucene/solr/branches/cloud/src/test/org/apache/solr/AbstractZooKeeperTestCase.java&r1=892824&r2=894959&rev=894959&view=diff ============================================================================== --- lucene/solr/branches/cloud/src/test/org/apache/solr/AbstractZooKeeperTestCase.java (original) +++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/AbstractZooKeeperTestCase.java Fri Jan 1 00:17:31 2010 @@ -1,13 +1,27 @@ -package org.apache.solr; +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 org.apache.solr.core.CoreContainer; import org.apache.solr.util.AbstractSolrTestCase; import org.apache.solr.util.TestHarness; -import org.apache.solr.util.ZooPut; -import org.apache.zookeeper.server.ServerConfig; -import org.apache.zookeeper.server.ZooKeeperServerMain; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,20 +29,20 @@ * Base test class for ZooKeeper tests. */ public abstract class AbstractZooKeeperTestCase extends AbstractSolrTestCase { - public static final String ZOO_KEEPER_HOST = "localhost:2181/solr"; - protected static Logger log = LoggerFactory.getLogger(AbstractZooKeeperTestCase.class); - - class ZKServerMain extends ZooKeeperServerMain { - public void shutdown() { - super.shutdown(); - } - } - protected ZKServerMain zkServer = new ZKServerMain(); + + static final String ZOO_KEEPER_HOST = "localhost:2181/solr"; + static final int TIMEOUT = 10000; + + protected static Logger log = LoggerFactory + .getLogger(AbstractZooKeeperTestCase.class); + protected File tmpDir = new File(System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + getClass().getName() + "-" + System.currentTimeMillis()); + private ZooKeeperTestServer zkServer; + public AbstractZooKeeperTestCase() { } @@ -42,81 +56,78 @@ } public void setUp() throws Exception { - // we don't call super.setUp - System.setProperty("zkHost", ZOO_KEEPER_HOST); - Thread zooThread = new Thread() { - @Override - public void run() { - ServerConfig config = new ServerConfig() { - { - this.clientPort = 2181; - this.dataDir = tmpDir.getAbsolutePath() + File.separator - + "zookeeper/server1/data"; - this.dataLogDir = this.dataDir; - } - }; - - try { - zkServer.runFromConfig(config); - log.info("ZOOKEEPER EXIT"); - } catch (Throwable e) { - e.printStackTrace(); - throw new RuntimeException(e); + try { + System.setProperty("zkHost", ZOO_KEEPER_HOST); + String zkDir = tmpDir.getAbsolutePath() + File.separator + + "zookeeper/server1/data"; + zkServer = new ZooKeeperTestServer(zkDir); + zkServer.run(); + + buildZooKeeper(getSolrConfigFile(), getSchemaFile()); + + log.info("####SETUP_START " + getName()); + dataDir = tmpDir; + dataDir.mkdirs(); + + // set some system properties for use by tests + System.setProperty("solr.test.sys.prop1", "propone"); + System.setProperty("solr.test.sys.prop2", "proptwo"); + + CoreContainer.Initializer init = new CoreContainer.Initializer() { + { + this.dataDir = AbstractZooKeeperTestCase.this.dataDir + .getAbsolutePath(); } - } - }; - - zooThread.setDaemon(true); - zooThread.start(); - Thread.sleep(500); // pause for ZooKeeper to start - - buildZooKeeper(getSolrConfigFile(), getSchemaFile()); - - log.info("####SETUP_START " + getName()); - dataDir = tmpDir; - dataDir.mkdirs(); - - // set some system properties for use by tests - System.setProperty("solr.test.sys.prop1", "propone"); - System.setProperty("solr.test.sys.prop2", "proptwo"); - - CoreContainer.Initializer init = new CoreContainer.Initializer() { - { - this.dataDir = AbstractZooKeeperTestCase.this.dataDir.getAbsolutePath(); - } - }; - - h = new TestHarness("", init); - lrf = h.getRequestFactory("standard", 0, 20, "version", "2.2"); + }; + h = new TestHarness("", init); + lrf = h.getRequestFactory("standard", 0, 20, "version", "2.2"); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } log.info("####SETUP_END " + getName()); + } - public static void buildZooKeeper(String config, String schema) throws Exception { - ZooPut zooPut = new ZooPut(ZOO_KEEPER_HOST.substring(0, ZOO_KEEPER_HOST.indexOf('/'))); - zooPut.makePath("/solr"); - zooPut.close(); - - zooPut = new ZooPut(ZOO_KEEPER_HOST); - - zooPut.makePath("/collections/collection1/config=collection1"); - - putConfig(zooPut, config); - putConfig(zooPut, schema); - putConfig(zooPut, "stopwords.txt"); - putConfig(zooPut, "protwords.txt"); - putConfig(zooPut, "mapping-ISOLatin1Accent.txt"); - putConfig(zooPut, "old_synonyms.txt"); - zooPut.close(); - } - - private static void putConfig(ZooPut zooPut, String name) throws Exception { - zooPut.putFile("/configs/collection1/" + name, new File("solr" + File.separator - + "conf" + File.separator + name)); + // static to share with distrib test + static void buildZooKeeper(String config, String schema) + throws Exception { + ZooKeeperWriter zkWriter = new ZooKeeperWriter(ZOO_KEEPER_HOST.substring(0, ZOO_KEEPER_HOST + .indexOf('/')), TIMEOUT); + + zkWriter.makePath("/solr"); + zkWriter.close(); + + zkWriter = new ZooKeeperWriter(ZOO_KEEPER_HOST, TIMEOUT); + + zkWriter.makePath("/collections/collection1/config=collection1"); + + putConfig(zkWriter, config); + putConfig(zkWriter, schema); + putConfig(zkWriter, "stopwords.txt"); + putConfig(zkWriter, "protwords.txt"); + putConfig(zkWriter, "mapping-ISOLatin1Accent.txt"); + putConfig(zkWriter, "old_synonyms.txt"); + zkWriter.close(); + } + + private static void putConfig(ZooKeeperWriter zkWriter, String name) throws Exception { + zkWriter.write("/configs/collection1/" + name, new File("solr" + + File.separator + "conf" + File.separator + name)); } public void tearDown() throws Exception { - zkServer.shutdown(); + printLayout(); + zkServer.shutdown(); super.tearDown(); } + + private void printLayout() throws Exception { + ZooKeeperReader zkReader = new ZooKeeperReader(ZOO_KEEPER_HOST.substring(0, ZOO_KEEPER_HOST + .indexOf('/')), TIMEOUT); + + zkReader.printLayoutToStdOut(); + zkReader.close(); + } }
Copied: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/BasicDistributedZooKeeperTest.java (from r892824, lucene/solr/branches/cloud/src/test/org/apache/solr/BasicDistributedZooKeeperTest.java) URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/BasicDistributedZooKeeperTest.java?p2=lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/BasicDistributedZooKeeperTest.java&p1=lucene/solr/branches/cloud/src/test/org/apache/solr/BasicDistributedZooKeeperTest.java&r1=892824&r2=894959&rev=894959&view=diff ============================================================================== --- lucene/solr/branches/cloud/src/test/org/apache/solr/BasicDistributedZooKeeperTest.java (original) +++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/BasicDistributedZooKeeperTest.java Fri Jan 1 00:17:31 2010 @@ -1,6 +1,27 @@ -package org.apache.solr; +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.HashSet; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.embedded.JettySolrRunner; /** * nocommit: @@ -34,6 +55,31 @@ String oddField="oddField_s"; String missingField="missing_but_valid_field_t"; String invalidField="invalid_field_not_in_schema"; + + protected void createServers(int numShards) throws Exception { + controlJetty = createJetty(testDir, "control", "shard2"); + controlClient = createNewSolrServer(controlJetty.getLocalPort()); + + StringBuilder sb = new StringBuilder(); + for (int i = 1; i <= numShards; i++) { + if (sb.length() > 0) sb.append(','); + JettySolrRunner j = createJetty(testDir, "shard" + i, "shard" + (i + 2)); + jettys.add(j); + clients.add(createNewSolrServer(j.getLocalPort())); + sb.append("localhost:").append(j.getLocalPort()).append(context); + } + + shards = sb.toString(); + } + + public void testDistribSearch() throws Exception { + for (int nServers = 3; nServers < 4; nServers++) { + createServers(nServers); + RandVal.uniqueValues = new HashSet(); //reset random values + doTest(); + destroyServers(); + } + } @Override public void doTest() throws Exception { Copied: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/BasicZooKeeperTest.java (from r892824, lucene/solr/branches/cloud/src/test/org/apache/solr/BasicZooKeeperTest.java) URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/BasicZooKeeperTest.java?p2=lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/BasicZooKeeperTest.java&p1=lucene/solr/branches/cloud/src/test/org/apache/solr/BasicZooKeeperTest.java&r1=892824&r2=894959&rev=894959&view=diff ============================================================================== --- lucene/solr/branches/cloud/src/test/org/apache/solr/BasicZooKeeperTest.java (original) +++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/BasicZooKeeperTest.java Fri Jan 1 00:17:31 2010 @@ -1,8 +1,26 @@ -package org.apache.solr; +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.solr.core.SolrCore; import org.apache.solr.update.SolrIndexWriter; + /** * TODO: assert config came from ZooKeeper * @@ -82,5 +100,8 @@ assertU(delQ("id:[100 TO 110]")); assertU(commit()); assertQ(req("id:[100 TO 110]"), "//*...@numfound='0']"); + + //nocommit + System.out.println("search nodes:" + h.getCoreContainer().getZooKeeperController().getSearchNodes()); } } Added: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/DistributedZooKeeperFailuresTest.java URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/DistributedZooKeeperFailuresTest.java?rev=894959&view=auto ============================================================================== --- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/DistributedZooKeeperFailuresTest.java (added) +++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/DistributedZooKeeperFailuresTest.java Fri Jan 1 00:17:31 2010 @@ -0,0 +1,128 @@ +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.util.HashSet; + +import org.apache.solr.client.solrj.embedded.JettySolrRunner; + +/** + * nocommit: + * + */ +public class DistributedZooKeeperFailuresTest extends AbstractDistributedZooKeeperTestCase { + @Override + public String getSchemaFile() { + return "schema.xml"; + } + + @Override + public String getSolrConfigFile() { + return "solrconfig.xml"; + } + + protected String getSolrConfigFilename() { + return "solr.lowZkTimeout.xml"; + } + + + 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="missing_but_valid_field_t"; + String invalidField="invalid_field_not_in_schema"; + + + JettySolrRunner jetty; + int port = 0; + + @Override + public void setUp() throws Exception { + super.setUp(); + + jetty = new JettySolrRunner(context, 0, getSolrConfigFilename()); + jetty.start(); + port = jetty.getLocalPort(); + + } + + + protected void createServers(int numShards) throws Exception { + controlJetty = createJetty(testDir, "control", "shard2", getSolrConfigFilename()); + controlClient = createNewSolrServer(controlJetty.getLocalPort()); + + StringBuilder sb = new StringBuilder(); + for (int i = 1; i <= numShards; i++) { + if (sb.length() > 0) sb.append(','); + JettySolrRunner j = createJetty(testDir, "shard" + i, "shard" + (i + 2), getSolrConfigFilename()); + jettys.add(j); + clients.add(createNewSolrServer(j.getLocalPort())); + sb.append("localhost:").append(j.getLocalPort()).append(context); + } + + shards = sb.toString(); + } + + public void testDistribSearch() throws Exception { + for (int nServers = 3; nServers < 4; nServers++) { + createServers(nServers); + RandVal.uniqueValues = new HashSet(); //reset random values + doTest(); + jetty.stop(); + destroyServers(); + } + } + + @Override + public void doTest() throws Exception { + del("*:*"); + + // nocommit : test too long + System.out.println("gc block"); + for(int i = 0; i < 400; i++) { + // try and timeout + System.gc(); + } + System.out.println("done gc block"); + // 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); + } + + //Thread.sleep(10000000000L); + } +} Added: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/TestShardInfoList.java URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/TestShardInfoList.java?rev=894959&view=auto ============================================================================== --- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/TestShardInfoList.java (added) +++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/TestShardInfoList.java Fri Jan 1 00:17:31 2010 @@ -0,0 +1,28 @@ +package org.apache.solr.cloud; + +import junit.framework.TestCase; + +/** + * 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. + */ + +public class TestShardInfoList extends TestCase { + + public void testBasic() { + // setup in zookeeper + // read with shardlist + } +} Added: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZooKeeperReaderTest.java URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZooKeeperReaderTest.java?rev=894959&view=auto ============================================================================== --- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZooKeeperReaderTest.java (added) +++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZooKeeperReaderTest.java Fri Jan 1 00:17:31 2010 @@ -0,0 +1,136 @@ +package org.apache.solr.cloud; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.Map.Entry; + +import junit.framework.TestCase; + +import org.apache.zookeeper.KeeperException; + +public class ZooKeeperReaderTest extends TestCase { + + private static final String COLLECTION_NAME = "collection1"; + + private static final String SHARD2 = "shard2"; + + private static final String SHARD1 = "shard1"; + + static final String ZOO_KEEPER_HOST = "localhost:2181/solr"; + + static final int TIMEOUT = 10000; + + private static final String URL1 = "http://localhost:3133/solr/core0"; + + private static final boolean DEBUG = true; + + protected File tmpDir = new File(System.getProperty("java.io.tmpdir") + + System.getProperty("file.separator") + getClass().getName() + "-" + + System.currentTimeMillis()); + + public void testReadShards() throws Exception { + String zkDir = tmpDir.getAbsolutePath() + File.separator + + "zookeeper/server1/data"; + + ZooKeeperTestServer server = new ZooKeeperTestServer(zkDir); + server.run(); + + makeSolrZkNode(); + + ZooKeeperWriter writer = new ZooKeeperWriter(ZOO_KEEPER_HOST, TIMEOUT); + String shardsPath = "/collections/collection1/shards"; + writer.makePath(shardsPath); + + addShardToZk(writer, shardsPath, URL1, SHARD1 + "," + SHARD2); + addShardToZk(writer, shardsPath, "http://localhost:3123/solr/core1", SHARD1); + addShardToZk(writer, shardsPath, "http://localhost:3133/solr/core1", SHARD1); + + ZooKeeperReader reader = new ZooKeeperReader(ZOO_KEEPER_HOST, TIMEOUT); + + if (DEBUG) { + reader.printLayoutToStdOut(); + } + + Map<String,ShardInfoList> shardInfoMap = reader.readShardInfo(shardsPath); + assertTrue(shardInfoMap.size() > 0); + Set<Entry<String,ShardInfoList>> entries = shardInfoMap.entrySet(); + + if (DEBUG) { + for (Entry<String,ShardInfoList> entry : entries) { + System.out.println("shard:" + entry.getKey() + " value:" + + entry.getValue().toString()); + } + } + + Set<String> keys = shardInfoMap.keySet(); + + assertTrue(keys.size() == 2); + + assertTrue(keys.contains(SHARD1)); + assertTrue(keys.contains(SHARD2)); + + ShardInfoList shardInfoList = shardInfoMap.get(SHARD1); + + assertEquals(3, shardInfoList.getShards().size()); + + shardInfoList = shardInfoMap.get(SHARD2); + + assertEquals(1, shardInfoList.getShards().size()); + + assertEquals(URL1, shardInfoList.getShards().get(0).getUrl()); + + server.shutdown(); + } + + public void testReadConfigName() throws Exception { + String zkDir = tmpDir.getAbsolutePath() + File.separator + + "zookeeper/server1/data"; + + ZooKeeperTestServer server = new ZooKeeperTestServer(zkDir); + server.run(); + + makeSolrZkNode(); + + ZooKeeperWriter writer = new ZooKeeperWriter(ZOO_KEEPER_HOST, TIMEOUT); + String actualConfigName = "firstConfig"; + + String shardsPath = "/collections/" + COLLECTION_NAME + "/config=" + actualConfigName; + writer.makePath(shardsPath); + + ZooKeeperReader reader = new ZooKeeperReader(ZOO_KEEPER_HOST, TIMEOUT); + + if (DEBUG) { + reader.printLayoutToStdOut(); + } + + String configName = reader.readConfigName(COLLECTION_NAME); + assertEquals(configName, actualConfigName); + + } + + private void addShardToZk(ZooKeeperWriter writer, String shardsPath, + String url, String shardList) throws IOException, KeeperException, + InterruptedException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + // nocommit: could do xml + Properties props = new Properties(); + props.put(ZooKeeperController.URL_PROP, url); + props.put(ZooKeeperController.SHARD_LIST_PROP, shardList); + props.store(baos, ZooKeeperController.PROPS_DESC); + + writer.makeEphemeralSeqPath(shardsPath + + ZooKeeperController.NODE_ZKPREFIX, baos.toByteArray(), null); + } + + private void makeSolrZkNode() throws Exception { + ZooKeeperWriter zkWriter = new ZooKeeperWriter(ZOO_KEEPER_HOST.substring(0, + ZOO_KEEPER_HOST.indexOf('/')), TIMEOUT); + + zkWriter.makePath("/solr"); + zkWriter.close(); + } +} Added: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZooKeeperTestServer.java URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZooKeeperTestServer.java?rev=894959&view=auto ============================================================================== --- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZooKeeperTestServer.java (added) +++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZooKeeperTestServer.java Fri Jan 1 00:17:31 2010 @@ -0,0 +1,53 @@ +package org.apache.solr.cloud; + +import org.apache.zookeeper.server.ServerConfig; +import org.apache.zookeeper.server.ZooKeeperServerMain; + +public class ZooKeeperTestServer { + private static final int PORT = 2181; + + protected ZKServerMain zkServer = new ZKServerMain(); + + private String zkDir; + + class ZKServerMain extends ZooKeeperServerMain { + public void shutdown() { + super.shutdown(); + } + } + + public ZooKeeperTestServer(String zkDir) { + this.zkDir = zkDir; + } + + public void run() throws InterruptedException { + // we don't call super.setUp + Thread zooThread = new Thread() { + @Override + public void run() { + ServerConfig config = new ServerConfig() { + { + this.clientPort = PORT; + this.dataDir = zkDir;; + this.dataLogDir = zkDir; + } + }; + + try { + zkServer.runFromConfig(config); + } catch (Throwable e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + }; + + zooThread.setDaemon(true); + zooThread.start(); + Thread.sleep(500); // pause for ZooKeeper to start + } + + public void shutdown() { + zkServer.shutdown(); + } +} Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java?rev=894959&r1=894958&r2=894959&view=diff ============================================================================== --- lucene/solr/branches/cloud/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java (original) +++ lucene/solr/branches/cloud/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java Fri Jan 1 00:17:31 2010 @@ -30,6 +30,9 @@ // The tests public void testLastModified() throws Exception { + // check that the right solrconfig is being used + assertTrue(h.getCore().getCoreDescriptor().getConfigName().endsWith(getSolrConfigFilename())); + doLastModified("GET"); doLastModified("HEAD"); } Added: lucene/solr/branches/cloud/src/test/test-files/solr/solr.lowZkTimeout.xml URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/test-files/solr/solr.lowZkTimeout.xml?rev=894959&view=auto ============================================================================== --- lucene/solr/branches/cloud/src/test/test-files/solr/solr.lowZkTimeout.xml (added) +++ lucene/solr/branches/cloud/src/test/test-files/solr/solr.lowZkTimeout.xml Fri Jan 1 00:17:31 2010 @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + 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. +--> + +<!-- + All (relative) paths are relative to the installation path + + persistent: Save changes made via the API to this file + sharedLib: path to a lib directory that will be shared across all cores +--> +<solr persistent="false"> + + <!-- + adminPath: RequestHandler path to manage cores. + If 'null' (or absent), cores will not be manageable via request handler + --> + <cores adminPath="/admin/cores" hostContext="solr" zkClientTimeout="30"> + <core name="DEFAULT_CORE" instanceDir="." shardList="shard1"/> + </cores> +</solr> Modified: lucene/solr/branches/cloud/src/test/test-files/solr/solr.xml URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/test-files/solr/solr.xml?rev=894959&r1=894958&r2=894959&view=diff ============================================================================== --- lucene/solr/branches/cloud/src/test/test-files/solr/solr.xml (original) +++ lucene/solr/branches/cloud/src/test/test-files/solr/solr.xml Fri Jan 1 00:17:31 2010 @@ -28,7 +28,7 @@ adminPath: RequestHandler path to manage cores. If 'null' (or absent), cores will not be manageable via request handler --> - <cores adminPath="/admin/cores" zkClientTimeout="10000"> - <core name="DEFAULT_CORE" instanceDir="." /> + <cores adminPath="/admin/cores" hostPort="8983" hostContext="solr" zkClientTimeout="8000"> + <core name="DEFAULT_CORE" instanceDir="." shardList="shard1"/> </cores> </solr> Modified: lucene/solr/branches/cloud/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java?rev=894959&r1=894958&r2=894959&view=diff ============================================================================== --- lucene/solr/branches/cloud/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java (original) +++ lucene/solr/branches/cloud/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java Fri Jan 1 00:17:31 2010 @@ -53,6 +53,8 @@ public JettySolrRunner( String context, int port, String solrConfigFilename ) { this.init( context, port ); + // nocommit + System.out.println("set config:" + solrConfigFilename); dispatchFilter.setInitParameter("solrconfig-filename", solrConfigFilename); } @@ -100,6 +102,17 @@ } if (waitForSolr) waitForSolr(context); } + + public void setPortOverride(int port) { + //nocommit: + dispatchFilter.setInitParameter("zkPortOverride", Integer.toString(port)); + } + + public void setTestShardListOverride(String shardList) { + //nocommit: + System.out.println("set shardlist override:"+shardList); + dispatchFilter.setInitParameter("testShardListOverride", shardList); + } public void stop() throws Exception Modified: lucene/solr/branches/cloud/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java?rev=894959&r1=894958&r2=894959&view=diff ============================================================================== --- lucene/solr/branches/cloud/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java (original) +++ lucene/solr/branches/cloud/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java Fri Jan 1 00:17:31 2010 @@ -79,6 +79,9 @@ // web.xml configuration this.pathPrefix = config.getInitParameter( "path-prefix" ); init.setSolrConfigFilename(config.getInitParameter("solrconfig-filename")); + // nocommit : consider + init.setZKPortOverride(config.getInitParameter("zkPortOverride")); + init.setTestShardListOverride(config.getInitParameter("testShardListOverride")); this.cores = init.initialize(); abortOnConfigurationError = init.isAbortOnConfigurationError();
