You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2016/06/03 14:13:02 UTC
lucene-solr:master: SOLR-9181: Fix test bug in ZkStateReaderTest
Repository: lucene-solr
Updated Branches:
refs/heads/master aed3fc11b -> 950fd9133
SOLR-9181: Fix test bug in ZkStateReaderTest
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/950fd913
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/950fd913
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/950fd913
Branch: refs/heads/master
Commit: 950fd913354912f9c84a07dcf60258726d6d6f4f
Parents: aed3fc1
Author: Alan Woodward <ro...@apache.org>
Authored: Thu Jun 2 15:15:46 2016 +0100
Committer: Alan Woodward <ro...@apache.org>
Committed: Fri Jun 3 15:12:50 2016 +0100
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +-
.../solr/cloud/overseer/ZkStateReaderTest.java | 35 ++++++--------------
.../apache/solr/common/cloud/ZkStateReader.java | 14 ++++----
3 files changed, 17 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/950fd913/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index fa84d56..391345f 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -140,7 +140,7 @@ New Features
* SOLR-8208: [subquery] document transformer executes separate requests per result document. (Cao Manh Dat via Mikhail Khludnev)
-* SOLR-8323, SOLR-9113: Add CollectionStateWatcher API (Alan Woodward, Scott Blum)
+* SOLR-8323, SOLR-9113, SOLR-9181: Add CollectionStateWatcher API (Alan Woodward, Scott Blum)
* SOLR-8988: Adds query option facet.distrib.mco which when set to true allows the use of facet.mincount=1 in cloud mode.
(Keith Laban, Dennis Gove)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/950fd913/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java b/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java
index ad51614..1e9454a 100644
--- a/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java
@@ -18,6 +18,7 @@ package org.apache.solr.cloud.overseer;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.SolrTestCaseJ4;
@@ -29,13 +30,14 @@ import org.apache.solr.cloud.ZkTestServer;
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocRouter;
-import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.Utils;
public class ZkStateReaderTest extends SolrTestCaseJ4 {
+ private static final long TIMEOUT = 30;
+
/** Uses explicit refresh to ensure latest changes are visible. */
public void testStateFormatUpdateWithExplicitRefresh() throws Exception {
testStateFormatUpdate(true, true);
@@ -84,7 +86,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
{
// create new collection with stateFormat = 1
- DocCollection stateV1 = new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE);
+ DocCollection stateV1 = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE);
ZkWriteCommand c1 = new ZkWriteCommand("c1", stateV1);
writer.enqueueUpdate(reader.getClusterState(), c1, null);
writer.writePendingUpdates();
@@ -97,12 +99,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
if (explicitRefresh) {
reader.forceUpdateCollection("c1");
} else {
- for (int i = 0; i < 1000; ++i) {
- if (reader.getClusterState().hasCollection("c1")) {
- break;
- }
- Thread.sleep(50);
- }
+ reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null);
}
DocCollection collection = reader.getClusterState().getCollection("c1");
@@ -112,7 +109,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
{
// Now update the collection to stateFormat = 2
- DocCollection stateV2 = new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json");
+ DocCollection stateV2 = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json");
ZkWriteCommand c2 = new ZkWriteCommand("c1", stateV2);
writer.enqueueUpdate(reader.getClusterState(), c2, null);
writer.writePendingUpdates();
@@ -125,12 +122,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
if (explicitRefresh) {
reader.forceUpdateCollection("c1");
} else {
- for (int i = 0; i < 1000; ++i) {
- if (reader.getClusterState().getCollection("c1").getStateFormat() == 2) {
- break;
- }
- Thread.sleep(50);
- }
+ reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null && c.getStateFormat() == 2);
}
DocCollection collection = reader.getClusterState().getCollection("c1");
@@ -166,7 +158,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
// create new collection with stateFormat = 2
ZkWriteCommand c1 = new ZkWriteCommand("c1",
- new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"));
+ new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"));
writer.enqueueUpdate(reader.getClusterState(), c1, null);
writer.writePendingUpdates();
reader.forceUpdateCollection("c1");
@@ -216,7 +208,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
// create new collection with stateFormat = 2
- DocCollection state = new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE + "/c1/state.json");
+ DocCollection state = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE + "/c1/state.json");
ZkWriteCommand wc = new ZkWriteCommand("c1", state);
writer.enqueueUpdate(reader.getClusterState(), wc, null);
writer.writePendingUpdates();
@@ -224,14 +216,7 @@ public class ZkStateReaderTest extends SolrTestCaseJ4 {
assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true));
//reader.forceUpdateCollection("c1");
-
- for (int i = 0; i < 100; ++i) {
- Thread.sleep(50);
- ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1");
- if (ref != null) {
- break;
- }
- }
+ reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null);
ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1");
assertNotNull(ref);
assertFalse(ref.isLazilyLoaded());
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/950fd913/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
index aff5bba..3de0a61 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
@@ -515,10 +515,8 @@ public class ZkStateReader implements Closeable {
String coll = watchEntry.getKey();
CollectionWatch collWatch = watchEntry.getValue();
ClusterState.CollectionRef ref = this.legacyCollectionStates.get(coll);
- if (ref == null)
- continue;
// legacy collections are always in-memory
- DocCollection oldState = ref.get();
+ DocCollection oldState = ref == null ? null : ref.get();
ClusterState.CollectionRef newRef = loadedData.getCollectionStates().get(coll);
DocCollection newState = newRef == null ? null : newRef.get();
if (!collWatch.stateWatchers.isEmpty()
@@ -1156,17 +1154,17 @@ public class ZkStateReader implements Closeable {
v.stateWatchers.add(stateWatcher);
return v;
});
+
if (watchSet.get()) {
new StateWatcher(collection).refreshAndWatch();
synchronized (getUpdateLock()) {
constructState();
}
}
- else {
- DocCollection state = clusterState.getCollectionOrNull(collection);
- if (stateWatcher.onStateChanged(liveNodes, state) == true) {
- removeCollectionStateWatcher(collection, stateWatcher);
- }
+
+ DocCollection state = clusterState.getCollectionOrNull(collection);
+ if (stateWatcher.onStateChanged(liveNodes, state) == true) {
+ removeCollectionStateWatcher(collection, stateWatcher);
}
}