You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2011/02/09 10:36:03 UTC
svn commit: r1068809 [34/36] - in /lucene/dev/branches/docvalues: ./
dev-tools/eclipse/ dev-tools/idea/.idea/ dev-tools/idea/.idea/copyright/
dev-tools/idea/lucene/ dev-tools/idea/lucene/contrib/ant/
dev-tools/idea/lucene/contrib/queryparser/ dev-tools...
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkControllerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkControllerTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkControllerTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkControllerTest.java Wed Feb 9 09:35:27 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.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/docvalues/solr/src/test/org/apache/solr/cloud/ZkNodePropsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkNodePropsTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkNodePropsTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkNodePropsTest.java Wed Feb 9 09:35:27 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/docvalues/solr/src/test/org/apache/solr/cloud/ZkSolrClientTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkSolrClientTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkSolrClientTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkSolrClientTest.java Wed Feb 9 09:35:27 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();
+ }
+
+}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkTestServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkTestServer.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkTestServer.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/cloud/ZkTestServer.java Wed Feb 9 09:35:27 2011
@@ -1,319 +1,319 @@
-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.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.management.JMException;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.zookeeper.jmx.ManagedUtil;
-import org.apache.zookeeper.server.NIOServerCnxn;
-import org.apache.zookeeper.server.ServerConfig;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.apache.zookeeper.server.SessionTracker.Session;
-import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
-import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
-
-public class ZkTestServer {
-
- protected final ZKServerMain zkServer = new ZKServerMain();
-
- private String zkDir;
-
- private int clientPort;
-
- private Thread zooThread;
-
- class ZKServerMain {
-
- private NIOServerCnxn.Factory cnxnFactory;
- private ZooKeeperServer zooKeeperServer;
-
- protected void initializeAndRun(String[] args) throws ConfigException,
- IOException {
- try {
- ManagedUtil.registerLog4jMBeans();
- } catch (JMException e) {
-
- }
-
- ServerConfig config = new ServerConfig();
- if (args.length == 1) {
- config.parse(args[0]);
- } else {
- config.parse(args);
- }
-
- runFromConfig(config);
- }
-
- /**
- * Run from a ServerConfig.
- *
- * @param config ServerConfig to use.
- * @throws IOException
- */
- public void runFromConfig(ServerConfig config) throws IOException {
- try {
- // Note that this thread isn't going to be doing anything else,
- // so rather than spawning another thread, we will just call
- // run() in this thread.
- // create a file logger url from the command line args
- zooKeeperServer = new ZooKeeperServer();
-
- FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(config
- .getDataLogDir()), new File(config.getDataDir()));
- zooKeeperServer.setTxnLogFactory(ftxn);
- zooKeeperServer.setTickTime(config.getTickTime());
- cnxnFactory = new NIOServerCnxn.Factory(config.getClientPortAddress(), config
- .getMaxClientCnxns());
- cnxnFactory.startup(zooKeeperServer);
- cnxnFactory.join();
- if (zooKeeperServer.isRunning()) {
- zooKeeperServer.shutdown();
- }
- } catch (InterruptedException e) {
- }
- }
-
- /**
- * Shutdown the serving instance
- * @throws IOException
- */
- protected void shutdown() throws IOException {
- zooKeeperServer.shutdown();
- zooKeeperServer.getZKDatabase().close();
- waitForServerDown(getZkHost() + ":" + getPort(), 5000);
- cnxnFactory.shutdown();
- }
-
- public int getLocalPort() {
- if (cnxnFactory == null) {
- throw new IllegalStateException("A port has not yet been selected");
- }
- int port = cnxnFactory.getLocalPort();
- if (port == 0) {
- throw new IllegalStateException("A port has not yet been selected");
- }
- return port;
- }
- }
-
- public ZkTestServer(String zkDir) {
- this.zkDir = zkDir;
- }
-
- public ZkTestServer(String zkDir, int port) {
- this.zkDir = zkDir;
- this.clientPort = port;
- }
-
- public String getZkHost() {
- return "127.0.0.1:" + zkServer.getLocalPort();
- }
-
- public String getZkAddress() {
- return "127.0.0.1:" + zkServer.getLocalPort() + "/solr";
- }
-
- public int getPort() {
- return zkServer.getLocalPort();
- }
-
- public void expire(final long sessionId) {
- zkServer.zooKeeperServer.expire(new Session() {
- @Override
- public long getSessionId() {
- return sessionId;
- }
- @Override
- public int getTimeout() {
- return 4000;
- }});
- }
-
- public void run() throws InterruptedException {
- // we don't call super.setUp
- zooThread = new Thread() {
-
- @Override
- public void run() {
- ServerConfig config = new ServerConfig() {
-
- {
- setClientPort(ZkTestServer.this.clientPort);
- this.dataDir = zkDir;
- this.dataLogDir = zkDir;
- this.tickTime = 1500;
- }
-
- public void setClientPort(int clientPort) {
- if (clientPortAddress != null) {
- try {
- this.clientPortAddress = new InetSocketAddress(
- InetAddress.getByName(clientPortAddress.getHostName()), clientPort);
- } catch (UnknownHostException e) {
- throw new RuntimeException(e);
- }
- } else {
- this.clientPortAddress = new InetSocketAddress(clientPort);
- }
- }
- };
-
- try {
- zkServer.runFromConfig(config);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
- };
-
- zooThread.setDaemon(true);
- zooThread.start();
-
- int cnt = 0;
- int port = -1;
- try {
- port = getPort();
- } catch(IllegalStateException e) {
-
- }
- while (port < 1) {
- Thread.sleep(100);
- try {
- port = getPort();
- } catch(IllegalStateException e) {
-
- }
- if (cnt == 40) {
- throw new RuntimeException("Could not get the port for ZooKeeper server");
- }
- cnt++;
- }
- }
-
- @SuppressWarnings("deprecation")
- public void shutdown() throws IOException {
- SolrTestCaseJ4.ignoreException("java.nio.channels.ClosedChannelException");
- // TODO: this can log an exception while trying to unregister a JMX MBean
- try {
- zkServer.shutdown();
- } finally {
- SolrTestCaseJ4.resetExceptionIgnores();
- }
- }
-
-
- public static boolean waitForServerDown(String hp, long timeout) {
- long start = System.currentTimeMillis();
- while (true) {
- try {
- HostPort hpobj = parseHostPortList(hp).get(0);
- send4LetterWord(hpobj.host, hpobj.port, "stat");
- } catch (IOException e) {
- return true;
- }
-
- if (System.currentTimeMillis() > start + timeout) {
- break;
- }
- try {
- Thread.sleep(250);
- } catch (InterruptedException e) {
- // ignore
- }
- }
- return false;
- }
-
- public static class HostPort {
- String host;
- int port;
-
- HostPort(String host, int port) {
- this.host = host;
- this.port = port;
- }
- }
-
- /**
- * Send the 4letterword
- * @param host the destination host
- * @param port the destination port
- * @param cmd the 4letterword
- * @return
- * @throws IOException
- */
- public static String send4LetterWord(String host, int port, String cmd)
- throws IOException
- {
-
- Socket sock = new Socket(host, port);
- BufferedReader reader = null;
- try {
- OutputStream outstream = sock.getOutputStream();
- outstream.write(cmd.getBytes());
- outstream.flush();
- // this replicates NC - close the output stream before reading
- sock.shutdownOutput();
-
- reader =
- new BufferedReader(
- new InputStreamReader(sock.getInputStream()));
- StringBuilder sb = new StringBuilder();
- String line;
- while((line = reader.readLine()) != null) {
- sb.append(line + "\n");
- }
- return sb.toString();
- } finally {
- sock.close();
- if (reader != null) {
- reader.close();
- }
- }
- }
-
- public static List<HostPort> parseHostPortList(String hplist) {
- ArrayList<HostPort> alist = new ArrayList<HostPort>();
- for (String hp : hplist.split(",")) {
- int idx = hp.lastIndexOf(':');
- String host = hp.substring(0, idx);
- int port;
- try {
- port = Integer.parseInt(hp.substring(idx + 1));
- } catch (RuntimeException e) {
- throw new RuntimeException("Problem parsing " + hp + e.toString());
- }
- alist.add(new HostPort(host, port));
- }
- return alist;
- }
-}
+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.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.management.JMException;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.zookeeper.jmx.ManagedUtil;
+import org.apache.zookeeper.server.NIOServerCnxn;
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.server.SessionTracker.Session;
+import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
+
+public class ZkTestServer {
+
+ protected final ZKServerMain zkServer = new ZKServerMain();
+
+ private String zkDir;
+
+ private int clientPort;
+
+ private Thread zooThread;
+
+ class ZKServerMain {
+
+ private NIOServerCnxn.Factory cnxnFactory;
+ private ZooKeeperServer zooKeeperServer;
+
+ protected void initializeAndRun(String[] args) throws ConfigException,
+ IOException {
+ try {
+ ManagedUtil.registerLog4jMBeans();
+ } catch (JMException e) {
+
+ }
+
+ ServerConfig config = new ServerConfig();
+ if (args.length == 1) {
+ config.parse(args[0]);
+ } else {
+ config.parse(args);
+ }
+
+ runFromConfig(config);
+ }
+
+ /**
+ * Run from a ServerConfig.
+ *
+ * @param config ServerConfig to use.
+ * @throws IOException
+ */
+ public void runFromConfig(ServerConfig config) throws IOException {
+ try {
+ // Note that this thread isn't going to be doing anything else,
+ // so rather than spawning another thread, we will just call
+ // run() in this thread.
+ // create a file logger url from the command line args
+ zooKeeperServer = new ZooKeeperServer();
+
+ FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(config
+ .getDataLogDir()), new File(config.getDataDir()));
+ zooKeeperServer.setTxnLogFactory(ftxn);
+ zooKeeperServer.setTickTime(config.getTickTime());
+ cnxnFactory = new NIOServerCnxn.Factory(config.getClientPortAddress(), config
+ .getMaxClientCnxns());
+ cnxnFactory.startup(zooKeeperServer);
+ cnxnFactory.join();
+ if (zooKeeperServer.isRunning()) {
+ zooKeeperServer.shutdown();
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+
+ /**
+ * Shutdown the serving instance
+ * @throws IOException
+ */
+ protected void shutdown() throws IOException {
+ zooKeeperServer.shutdown();
+ zooKeeperServer.getZKDatabase().close();
+ waitForServerDown(getZkHost() + ":" + getPort(), 5000);
+ cnxnFactory.shutdown();
+ }
+
+ public int getLocalPort() {
+ if (cnxnFactory == null) {
+ throw new IllegalStateException("A port has not yet been selected");
+ }
+ int port = cnxnFactory.getLocalPort();
+ if (port == 0) {
+ throw new IllegalStateException("A port has not yet been selected");
+ }
+ return port;
+ }
+ }
+
+ public ZkTestServer(String zkDir) {
+ this.zkDir = zkDir;
+ }
+
+ public ZkTestServer(String zkDir, int port) {
+ this.zkDir = zkDir;
+ this.clientPort = port;
+ }
+
+ public String getZkHost() {
+ return "127.0.0.1:" + zkServer.getLocalPort();
+ }
+
+ public String getZkAddress() {
+ return "127.0.0.1:" + zkServer.getLocalPort() + "/solr";
+ }
+
+ public int getPort() {
+ return zkServer.getLocalPort();
+ }
+
+ public void expire(final long sessionId) {
+ zkServer.zooKeeperServer.expire(new Session() {
+ @Override
+ public long getSessionId() {
+ return sessionId;
+ }
+ @Override
+ public int getTimeout() {
+ return 4000;
+ }});
+ }
+
+ public void run() throws InterruptedException {
+ // we don't call super.setUp
+ zooThread = new Thread() {
+
+ @Override
+ public void run() {
+ ServerConfig config = new ServerConfig() {
+
+ {
+ setClientPort(ZkTestServer.this.clientPort);
+ this.dataDir = zkDir;
+ this.dataLogDir = zkDir;
+ this.tickTime = 1500;
+ }
+
+ public void setClientPort(int clientPort) {
+ if (clientPortAddress != null) {
+ try {
+ this.clientPortAddress = new InetSocketAddress(
+ InetAddress.getByName(clientPortAddress.getHostName()), clientPort);
+ } catch (UnknownHostException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ this.clientPortAddress = new InetSocketAddress(clientPort);
+ }
+ }
+ };
+
+ try {
+ zkServer.runFromConfig(config);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+
+ zooThread.setDaemon(true);
+ zooThread.start();
+
+ int cnt = 0;
+ int port = -1;
+ try {
+ port = getPort();
+ } catch(IllegalStateException e) {
+
+ }
+ while (port < 1) {
+ Thread.sleep(100);
+ try {
+ port = getPort();
+ } catch(IllegalStateException e) {
+
+ }
+ if (cnt == 40) {
+ throw new RuntimeException("Could not get the port for ZooKeeper server");
+ }
+ cnt++;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public void shutdown() throws IOException {
+ SolrTestCaseJ4.ignoreException("java.nio.channels.ClosedChannelException");
+ // TODO: this can log an exception while trying to unregister a JMX MBean
+ try {
+ zkServer.shutdown();
+ } finally {
+ SolrTestCaseJ4.resetExceptionIgnores();
+ }
+ }
+
+
+ public static boolean waitForServerDown(String hp, long timeout) {
+ long start = System.currentTimeMillis();
+ while (true) {
+ try {
+ HostPort hpobj = parseHostPortList(hp).get(0);
+ send4LetterWord(hpobj.host, hpobj.port, "stat");
+ } catch (IOException e) {
+ return true;
+ }
+
+ if (System.currentTimeMillis() > start + timeout) {
+ break;
+ }
+ try {
+ Thread.sleep(250);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
+ return false;
+ }
+
+ public static class HostPort {
+ String host;
+ int port;
+
+ HostPort(String host, int port) {
+ this.host = host;
+ this.port = port;
+ }
+ }
+
+ /**
+ * Send the 4letterword
+ * @param host the destination host
+ * @param port the destination port
+ * @param cmd the 4letterword
+ * @return
+ * @throws IOException
+ */
+ public static String send4LetterWord(String host, int port, String cmd)
+ throws IOException
+ {
+
+ Socket sock = new Socket(host, port);
+ BufferedReader reader = null;
+ try {
+ OutputStream outstream = sock.getOutputStream();
+ outstream.write(cmd.getBytes("US-ASCII"));
+ outstream.flush();
+ // this replicates NC - close the output stream before reading
+ sock.shutdownOutput();
+
+ reader =
+ new BufferedReader(
+ new InputStreamReader(sock.getInputStream()));
+ StringBuilder sb = new StringBuilder();
+ String line;
+ while((line = reader.readLine()) != null) {
+ sb.append(line + "\n");
+ }
+ return sb.toString();
+ } finally {
+ sock.close();
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
+ public static List<HostPort> parseHostPortList(String hplist) {
+ ArrayList<HostPort> alist = new ArrayList<HostPort>();
+ for (String hp : hplist.split(",")) {
+ int idx = hp.lastIndexOf(':');
+ String host = hp.substring(0, idx);
+ int port;
+ try {
+ port = Integer.parseInt(hp.substring(idx + 1));
+ } catch (RuntimeException e) {
+ throw new RuntimeException("Problem parsing " + hp + e.toString());
+ }
+ alist.add(new HostPort(host, port));
+ }
+ return alist;
+ }
+}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/common/util/ContentStreamTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/common/util/ContentStreamTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/common/util/ContentStreamTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/common/util/ContentStreamTest.java Wed Feb 9 09:35:27 2011
@@ -25,7 +25,9 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
+import java.net.ConnectException;
import java.net.URL;
+import java.net.URLConnection;
import org.apache.commons.io.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
@@ -41,7 +43,7 @@ public class ContentStreamTest extends L
String input = "aads ghaskdgasgldj asl sadg ajdsg &jag # @ hjsakg hsakdg hjkas s";
ContentStreamBase stream = new ContentStreamBase.StringStream( input );
assertEquals( input.length(), stream.getSize().intValue() );
- assertEquals( input, IOUtils.toString( stream.getStream() ) );
+ assertEquals( input, IOUtils.toString( stream.getStream(), "UTF-8" ) );
assertEquals( input, IOUtils.toString( stream.getReader() ) );
}
@@ -63,33 +65,43 @@ public class ContentStreamTest extends L
public void testURLStream() throws IOException
{
- String content = null;
+ byte[] content = null;
+ String contentType = null;
URL url = new URL( "http://svn.apache.org/repos/asf/lucene/dev/trunk/" );
- InputStream in = url.openStream();
+ InputStream in = null;
try {
- content = IOUtils.toString( in );
- }
- finally {
- IOUtils.closeQuietly(in);
+ URLConnection conn = url.openConnection();
+ in = conn.getInputStream();
+ contentType = conn.getContentType();
+ content = IOUtils.toByteArray(in);
+ } catch (ConnectException ex) {
+ assumeNoException("Unable to connect to " + url + " to run the test.", ex);
+ }finally {
+ if (in != null) {
+ IOUtils.closeQuietly(in);
+ }
}
- assertTrue( content.length() > 10 ); // found something...
+ assertTrue( content.length > 10 ); // found something...
ContentStreamBase stream = new ContentStreamBase.URLStream( url );
- assertEquals( content.length(), stream.getSize().intValue() );
+ assertEquals( content.length, stream.getSize().intValue() );
// Test the stream
in = stream.getStream();
try {
assertTrue( IOUtils.contentEquals(
- new ByteArrayInputStream( content.getBytes() ), in ) );
+ new ByteArrayInputStream(content), in ) );
}
finally {
IOUtils.closeQuietly(in);
}
+ String charset = ContentStreamBase.getCharsetFromContentType(contentType);
+ if (charset == null)
+ charset = ContentStreamBase.DEFAULT_CHARSET;
// Re-open the stream and this time use a reader
stream = new ContentStreamBase.URLStream( url );
- assertTrue( IOUtils.contentEquals( new StringReader( content ), stream.getReader() ) );
+ assertTrue( IOUtils.contentEquals( new StringReader(new String(content, charset)), stream.getReader() ) );
}
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/common/util/DOMUtilTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/common/util/DOMUtilTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/common/util/DOMUtilTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/common/util/DOMUtilTest.java Wed Feb 9 09:35:27 2011
@@ -17,7 +17,7 @@
package org.apache.solr.common.util;
-import java.io.ByteArrayInputStream;
+import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -27,6 +27,7 @@ import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
import org.apache.lucene.util.LuceneTestCase;
@@ -85,6 +86,6 @@ public class DOMUtilTest extends LuceneT
}
public Document getDocument( String xml ) throws Exception {
- return builder.parse( new ByteArrayInputStream( xml.getBytes() ) );
+ return builder.parse(new InputSource(new StringReader(xml)));
}
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/AlternateDirectoryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/AlternateDirectoryTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/AlternateDirectoryTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/AlternateDirectoryTest.java Wed Feb 9 09:35:27 2011
@@ -48,6 +48,7 @@ public class AlternateDirectoryTest exte
public static volatile boolean openCalled = false;
public static volatile Directory dir;
+ @Override
public Directory open(String path) throws IOException {
openCalled = true;
// need to close the directory, or otherwise the test fails.
@@ -63,6 +64,7 @@ public class AlternateDirectoryTest exte
static public class TestIndexReaderFactory extends IndexReaderFactory {
static volatile boolean newReaderCalled = false;
+ @Override
public IndexReader newReader(Directory indexDir, boolean readOnly)
throws IOException {
TestIndexReaderFactory.newReaderCalled = true;
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/DummyValueSourceParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/DummyValueSourceParser.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/DummyValueSourceParser.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/DummyValueSourceParser.java Wed Feb 9 09:35:27 2011
@@ -32,17 +32,21 @@ import org.apache.solr.search.function.V
public class DummyValueSourceParser extends ValueSourceParser {
private NamedList args;
+ @Override
public void init(NamedList args) {
this.args = args;
}
+ @Override
public ValueSource parse(FunctionQParser fp) throws ParseException {
ValueSource source = fp.parseValueSource();
ValueSource result = new SimpleFloatFunction(source) {
+ @Override
protected String name() {
return "foo";
}
+ @Override
protected float func(int doc, DocValues vals) {
float result = 0;
return result;
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/IndexReaderFactoryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/IndexReaderFactoryTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/IndexReaderFactoryTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/IndexReaderFactoryTest.java Wed Feb 9 09:35:27 2011
@@ -20,10 +20,12 @@ import org.apache.solr.util.AbstractSolr
public class IndexReaderFactoryTest extends AbstractSolrTestCase {
+ @Override
public String getSchemaFile() {
return "schema.xml";
}
+ @Override
public String getSolrConfigFile() {
return "solrconfig-termindex.xml";
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/MockQuerySenderListenerReqHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/MockQuerySenderListenerReqHandler.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/MockQuerySenderListenerReqHandler.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/MockQuerySenderListenerReqHandler.java Wed Feb 9 09:35:27 2011
@@ -34,36 +34,43 @@ public class MockQuerySenderListenerReqH
AtomicInteger initCounter = new AtomicInteger(0);
+ @Override
public void init(NamedList args) {
initCounter.incrementAndGet();
super.init(args);
}
+ @Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
this.req = req;
this.rsp = rsp;
}
+ @Override
public String getDescription() {
String result = null;
return result;
}
+ @Override
public String getSourceId() {
String result = null;
return result;
}
+ @Override
public String getSource() {
String result = null;
return result;
}
+ @Override
public String getVersion() {
String result = null;
return result;
}
+ @Override
public NamedList<Object> getStatistics() {
NamedList<Object> lst = super.getStatistics();
lst.add("initCount", initCounter.intValue());
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java Wed Feb 9 09:35:27 2011
@@ -18,6 +18,7 @@
package org.apache.solr.core;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.SingleInstanceLockFactory;
import org.apache.lucene.util.LuceneTestCase;
import java.io.IOException;
@@ -27,7 +28,7 @@ import java.io.IOException;
public class RAMDirectoryFactoryTest extends LuceneTestCase {
public void testOpenReturnsTheSameForSamePath() throws IOException {
final Directory directory = new RefCntRamDirectory();
- RAMDirectoryFactory factory = new RAMDirectoryFactory() {
+ RAMDirectoryFactory factory = new RAMDirectoryFactory() {
@Override
Directory openNew(String path) throws IOException {
return directory;
@@ -40,6 +41,8 @@ public class RAMDirectoryFactoryTest ext
"every time open() is called for the same path", directory, dir1);
assertEquals("RAMDirectoryFactory should not create new instance of RefCntRamDirectory " +
"every time open() is called for the same path", directory, dir2);
+ dir1.close();
+ dir2.close();
}
public void testOpenSucceedForEmptyDir() throws IOException {
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java Wed Feb 9 09:35:27 2011
@@ -42,6 +42,7 @@ import org.xml.sax.SAXException;
*/
public class TestArbitraryIndexDir extends AbstractSolrTestCase{
+ @Override
public void setUp() throws Exception {
super.setUp();
@@ -58,6 +59,7 @@ public class TestArbitraryIndexDir exten
("standard",0,20,"version","2.2");
}
+ @Override
public void tearDown() throws Exception {
super.tearDown();
@@ -99,8 +101,7 @@ public class TestArbitraryIndexDir exten
Directory dir = newFSDirectory(newDir);
IndexWriter iw = new IndexWriter(
dir,
- new IndexWriterConfig(Version.LUCENE_40, new StandardAnalyzer(Version.LUCENE_40)).
- setMaxFieldLength(1000)
+ new IndexWriterConfig(Version.LUCENE_40, new StandardAnalyzer(Version.LUCENE_40))
);
Document doc = new Document();
doc.add(new Field("id", "2", Field.Store.YES, Field.Index.ANALYZED));
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestBadConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestBadConfig.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestBadConfig.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestBadConfig.java Wed Feb 9 09:35:27 2011
@@ -21,9 +21,12 @@ import org.apache.solr.util.AbstractSolr
public class TestBadConfig extends AbstractSolrTestCase {
+ @Override
public String getSchemaFile() { return "schema.xml"; }
+ @Override
public String getSolrConfigFile() { return "bad_solrconfig.xml"; }
+ @Override
public void setUp() throws Exception {
ignoreException("unset.sys.property");
try {
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestConfig.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestConfig.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestConfig.java Wed Feb 9 09:35:27 2011
@@ -139,7 +139,7 @@ public class TestConfig extends SolrTest
StandardIndexReaderFactory sirf = (StandardIndexReaderFactory) irf;
assertEquals(12, sirf.termInfosIndexDivisor);
SolrQueryRequest req = req();
- assertEquals(12, req.getSearcher().getReader().getTermInfosIndexDivisor());
+ assertEquals(12, req.getSearcher().getIndexReader().getTermInfosIndexDivisor());
req.close();
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxIntegration.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxIntegration.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxIntegration.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxIntegration.java Wed Feb 9 09:35:27 2011
@@ -46,6 +46,7 @@ public class TestJmxIntegration extends
return "solrconfig.xml";
}
+ @Override
@Before
public void setUp() throws Exception {
// Make sure that at least one MBeanServer is available
@@ -53,6 +54,7 @@ public class TestJmxIntegration extends
super.setUp();
}
+ @Override
@After
public void tearDown() throws Exception {
super.tearDown();
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxMonitoredMap.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxMonitoredMap.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxMonitoredMap.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxMonitoredMap.java Wed Feb 9 09:35:27 2011
@@ -51,6 +51,7 @@ public class TestJmxMonitoredMap extends
private JmxMonitoredMap<String, SolrInfoMBean> monitoredMap;
+ @Override
@Before
public void setUp() throws Exception {
super.setUp();
@@ -84,6 +85,7 @@ public class TestJmxMonitoredMap extends
}
}
+ @Override
@After
public void tearDown() throws Exception {
try {
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java Wed Feb 9 09:35:27 2011
@@ -1,5 +1,22 @@
package org.apache.solr.core;
+/**
+ * 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.lucene.index.IndexWriter;
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestPropInject.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestPropInject.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestPropInject.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestPropInject.java Wed Feb 9 09:35:27 2011
@@ -1,5 +1,22 @@
package org.apache.solr.core;
+/**
+ * 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.lucene.index.ConcurrentMergeScheduler;
@@ -9,10 +26,12 @@ import org.apache.solr.update.DirectUpda
import org.apache.solr.util.AbstractSolrTestCase;
public class TestPropInject extends AbstractSolrTestCase {
+ @Override
public String getSchemaFile() {
return "schema.xml";
}
+ @Override
public String getSolrConfigFile() {
return "solrconfig-propinject.xml";
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestQuerySenderListener.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestQuerySenderListener.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestQuerySenderListener.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestQuerySenderListener.java Wed Feb 9 09:35:27 2011
@@ -75,7 +75,7 @@ public class TestQuerySenderListener ext
String evt = mock.req.getParams().get(EventParams.EVENT);
assertNotNull("Event is null", evt);
assertTrue(evt + " is not equal to " + EventParams.FIRST_SEARCHER, evt.equals(EventParams.FIRST_SEARCHER) == true);
- Directory dir = currentSearcher.getReader().directory();
+ Directory dir = currentSearcher.getIndexReader().directory();
SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getSchema(), "testQuerySenderListener", dir, true, false);
qsl.newSearcher(newSearcher, currentSearcher);
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestSolrDeletionPolicy1.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestSolrDeletionPolicy1.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestSolrDeletionPolicy1.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestSolrDeletionPolicy1.java Wed Feb 9 09:35:27 2011
@@ -34,6 +34,7 @@ public class TestSolrDeletionPolicy1 ext
initCore("solrconfig-delpolicy1.xml","schema.xml");
}
+ @Override
@Before
public void setUp() throws Exception {
super.setUp();
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestXIncludeConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestXIncludeConfig.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestXIncludeConfig.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestXIncludeConfig.java Wed Feb 9 09:35:27 2011
@@ -1,5 +1,22 @@
package org.apache.solr.core;
+/**
+ * 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.commons.io.FileUtils;
@@ -16,11 +33,13 @@ import javax.xml.parsers.DocumentBuilder
public class TestXIncludeConfig extends AbstractSolrTestCase {
protected boolean supports;
+ @Override
public String getSchemaFile() {
return "schema.xml";
}
//public String getSolrConfigFile() { return "solrconfig.xml"; }
+ @Override
public String getSolrConfigFile() {
return "solrconfig-xinclude.xml";
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java Wed Feb 9 09:35:27 2011
@@ -30,8 +30,12 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.Reader;
/**
* A test for {@link DocumentAnalysisRequestHandler}.
@@ -71,15 +75,14 @@ public class DocumentAnalysisRequestHand
"</doc>" +
"</docs>";
- final List<ContentStream> contentStreams = new ArrayList<ContentStream>(1);
- contentStreams.add(new ContentStreamBase.StringStream(docsInput));
+ final ContentStream cs = new ContentStreamBase.StringStream(docsInput);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add("analysis.query", "The Query String");
params.add("analysis.showmatch", "true");
SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {
@Override
public Iterable<ContentStream> getContentStreams() {
- return contentStreams;
+ return Collections.singleton(cs);
}
};
@@ -106,6 +109,94 @@ public class DocumentAnalysisRequestHand
req.close();
}
+ /** A binary-only ContentStream */
+ static class ByteStream extends ContentStreamBase {
+ private final byte[] bytes;
+
+ public ByteStream(byte[] bytes, String contentType) {
+ this.bytes = bytes;
+ this.contentType = contentType;
+ name = null;
+ size = Long.valueOf(bytes.length);
+ sourceInfo = "rawBytes";
+ }
+
+ public InputStream getStream() throws IOException {
+ return new ByteArrayInputStream(bytes);
+ }
+
+ @Override
+ public Reader getReader() throws IOException {
+ throw new IOException("This is a byte stream, Readers are not supported.");
+ }
+ }
+
+
+ // This test should also test charset detection in UpdateRequestHandler,
+ // but the DocumentAnalysisRequestHandler is simplier to use/check.
+ @Test
+ public void testCharsetInDocument() throws Exception {
+ final byte[] xmlBytes = (
+ "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n" +
+ "<docs>\r\n" +
+ " <doc>\r\n" +
+ " <field name=\"id\">Müller</field>\r\n" +
+ " </doc>" +
+ "</docs>"
+ ).getBytes("ISO-8859-1");
+
+ // we declare a content stream without charset:
+ final ContentStream cs = new ByteStream(xmlBytes, "application/xml");
+
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {
+ @Override
+ public Iterable<ContentStream> getContentStreams() {
+ return Collections.singleton(cs);
+ }
+ };
+
+ DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req);
+ assertNotNull(request);
+ final List<SolrInputDocument> documents = request.getDocuments();
+ assertNotNull(documents);
+ assertEquals(1, documents.size());
+ SolrInputDocument doc = documents.get(0);
+ assertEquals("Müller", doc.getField("id").getValue());
+ }
+
+ // This test should also test charset detection in UpdateRequestHandler,
+ // but the DocumentAnalysisRequestHandler is simplier to use/check.
+ @Test
+ public void testCharsetOutsideDocument() throws Exception {
+ final byte[] xmlBytes = (
+ "<docs>\r\n" +
+ " <doc>\r\n" +
+ " <field name=\"id\">Müller</field>\r\n" +
+ " </doc>" +
+ "</docs>"
+ ).getBytes("ISO-8859-1");
+
+ // we declare a content stream with charset:
+ final ContentStream cs = new ByteStream(xmlBytes, "application/xml; charset=ISO-8859-1");
+
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {
+ @Override
+ public Iterable<ContentStream> getContentStreams() {
+ return Collections.singleton(cs);
+ }
+ };
+
+ DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req);
+ assertNotNull(request);
+ final List<SolrInputDocument> documents = request.getDocuments();
+ assertNotNull(documents);
+ assertEquals(1, documents.size());
+ SolrInputDocument doc = documents.get(0);
+ assertEquals("Müller", doc.getField("id").getValue());
+ }
+
/**
* Tests the {@link DocumentAnalysisRequestHandler#handleAnalysisRequest(org.apache.solr.client.solrj.request.DocumentAnalysisRequest,
* org.apache.solr.schema.IndexSchema)}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/JsonLoaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/JsonLoaderTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/JsonLoaderTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/JsonLoaderTest.java Wed Feb 9 09:35:27 2011
@@ -146,23 +146,28 @@ class BufferingRequestProcessor extends
super(next);
}
+ @Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
addCommands.add( cmd );
}
+ @Override
public void processDelete(DeleteUpdateCommand cmd) throws IOException {
deleteCommands.add( cmd );
}
+ @Override
public void processCommit(CommitUpdateCommand cmd) throws IOException {
commitCommands.add( cmd );
}
+ @Override
public void processRollback(RollbackUpdateCommand cmd) throws IOException
{
rollbackCommands.add( cmd );
}
+ @Override
public void finish() throws IOException {
// nothing?
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java Wed Feb 9 09:35:27 2011
@@ -94,7 +94,17 @@ public class MoreLikeThisHandlerTest ext
assertQ("morelike this - harrison ford",mltreq
,"//result/doc[1]/int[@name='id'][.='45']");
+ // test MoreLikeThis debug
+ params.set(CommonParams.DEBUG_QUERY, "true");
+ assertQ("morelike this - harrison ford",mltreq
+ ,"//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='rawMLTQuery']"
+ ,"//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='boostedMLTQuery']"
+ ,"//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='realMLTQuery']"
+ ,"//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/lst[@name='explain']/str[@name='45']"
+ );
+
// test that qparser plugins work
+ params.remove(CommonParams.DEBUG_QUERY);
params.set(CommonParams.Q, "{!field f=id}44");
assertQ(mltreq
,"//result/doc[1]/int[@name='id'][.='45']");
@@ -112,9 +122,9 @@ public class MoreLikeThisHandlerTest ext
assertQ(mltreq
,"//result/doc[1]/int[@name='id'][.='45']");
- // test that debugging works
+ // test that debugging works (test for MoreLikeThis*Handler*)
params.set(CommonParams.QT, "/mlt");
- params.set("debugQuery", "true");
+ params.set(CommonParams.DEBUG_QUERY, "true");
assertQ(mltreq
,"//result/doc[1]/int[@name='id'][.='45']"
,"//lst[@name='debug']/lst[@name='explain']"
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java Wed Feb 9 09:35:27 2011
@@ -43,9 +43,9 @@ public class StandardRequestHandlerTest
public void testSorting() throws Exception {
SolrCore core = h.getCore();
- assertU(adoc("id", "10", "title", "test", "val_s", "aaa"));
- assertU(adoc("id", "11", "title", "test", "val_s", "bbb"));
- assertU(adoc("id", "12", "title", "test", "val_s", "ccc"));
+ assertU(adoc("id", "10", "title", "test", "val_s1", "aaa"));
+ assertU(adoc("id", "11", "title", "test", "val_s1", "bbb"));
+ assertU(adoc("id", "12", "title", "test", "val_s1", "ccc"));
assertU(commit());
Map<String,String> args = new HashMap<String, String>();
@@ -58,7 +58,7 @@ public class StandardRequestHandlerTest
,"//*[@numFound='3']"
);
- args.put( CommonParams.SORT, "val_s asc" );
+ args.put( CommonParams.SORT, "val_s1 asc" );
assertQ("with sort param [asc]", req
,"//*[@numFound='3']"
,"//result/doc[1]/int[@name='id'][.='10']"
@@ -66,7 +66,7 @@ public class StandardRequestHandlerTest
,"//result/doc[3]/int[@name='id'][.='12']"
);
- args.put( CommonParams.SORT, "val_s desc" );
+ args.put( CommonParams.SORT, "val_s1 desc" );
assertQ("with sort param [desc]", req
,"//*[@numFound='3']"
,"//result/doc[1]/int[@name='id'][.='12']"
@@ -84,7 +84,7 @@ public class StandardRequestHandlerTest
// Using legacy ';' param
args.remove( CommonParams.SORT );
args.put( QueryParsing.DEFTYPE, "lucenePlusSort" );
- args.put( CommonParams.Q, "title:test; val_s desc" );
+ args.put( CommonParams.Q, "title:test; val_s1 desc" );
assertQ("with sort param [desc]", req
,"//*[@numFound='3']"
,"//result/doc[1]/int[@name='id'][.='12']"
@@ -92,8 +92,8 @@ public class StandardRequestHandlerTest
,"//result/doc[3]/int[@name='id'][.='10']"
);
- args.put( CommonParams.Q, "title:test; val_s asc" );
- assertQ("with sort param [desc]", req
+ args.put( CommonParams.Q, "title:test; val_s1 asc" );
+ assertQ("with sort param [asc]", req
,"//*[@numFound='3']"
,"//result/doc[1]/int[@name='id'][.='10']"
,"//result/doc[2]/int[@name='id'][.='11']"