You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2017/10/31 14:02:01 UTC
[19/50] [abbrv] lucene-solr:jira/solr-11285-sim: SOLR-11170: Make
AssignBackwardCompatibilityTest more reliable
SOLR-11170: Make AssignBackwardCompatibilityTest more reliable
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/161be0a4
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/161be0a4
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/161be0a4
Branch: refs/heads/jira/solr-11285-sim
Commit: 161be0a4ae38e857eb831b90121229db69f7fd4b
Parents: 7d9cf43
Author: Cao Manh Dat <da...@apache.org>
Authored: Fri Oct 27 10:23:28 2017 +0700
Committer: Cao Manh Dat <da...@apache.org>
Committed: Fri Oct 27 10:23:28 2017 +0700
----------------------------------------------------------------------
.../java/org/apache/solr/util/NumberUtils.java | 8 +---
.../cloud/AssignBackwardCompatibilityTest.java | 26 ++++++++++---
.../org/apache/solr/util/NumberUtilsTest.java | 40 ++++++++++++++++++++
3 files changed, 62 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/161be0a4/solr/core/src/java/org/apache/solr/util/NumberUtils.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/NumberUtils.java b/solr/core/src/java/org/apache/solr/util/NumberUtils.java
index 93359bb..2e1226b 100644
--- a/solr/core/src/java/org/apache/solr/util/NumberUtils.java
+++ b/solr/core/src/java/org/apache/solr/util/NumberUtils.java
@@ -211,11 +211,7 @@ public class NumberUtils {
public static int bytesToInt(byte[] bytes) {
if (bytes == null) return 0;
- int val = 0;
- for (int i = 0; i < bytes.length; i++) {
- val = val << 8;
- val += bytes[i];
- }
- return val;
+ assert bytes.length == 4;
+ return bytes[0] << 24 | (bytes[1] & 255) << 16 | (bytes[2] & 255) << 8 | bytes[3] & 255;
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/161be0a4/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java b/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java
index cc463ef..aaa47b4 100644
--- a/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java
@@ -28,7 +28,9 @@ import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.common.cloud.ClusterStateUtil;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.util.NumberUtils;
import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.data.Stat;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
@@ -59,21 +61,22 @@ public class AssignBackwardCompatibilityTest extends SolrCloudTestCase {
Set<String> coreNames = new HashSet<>();
Set<String> coreNodeNames = new HashSet<>();
- int numOperations = random().nextInt(4 * 15);
+ int numOperations = random().nextInt(15) + 15;
int numLiveReplicas = 4;
boolean clearedCounter = false;
for (int i = 0; i < numOperations; i++) {
+ log.info("Collection counter={} i={}", getCounter(), i);
boolean deleteReplica = random().nextBoolean() && numLiveReplicas > 1;
// No need to clear counter more than one time
- if (random().nextInt(30) < 5 && !clearedCounter) {
+ if (random().nextBoolean() && i > 5 && !clearedCounter) {
+ log.info("Clear collection counter");
// clear counter
cluster.getZkClient().delete("/collections/"+COLLECTION+"/counter", -1, true);
clearedCounter = true;
}
if (deleteReplica) {
- assertTrue(ClusterStateUtil.waitForLiveAndActiveReplicaCount(
- cluster.getSolrClient().getZkStateReader(), COLLECTION, numLiveReplicas, 30000));
+ waitForState("Expected " + numLiveReplicas + " active replicas", COLLECTION, clusterShape(1, numLiveReplicas));
DocCollection dc = getCollectionState(COLLECTION);
Replica replica = getRandomReplica(dc.getSlice("shard1"), (r) -> r.getState() == Replica.State.ACTIVE);
CollectionAdminRequest.deleteReplica(COLLECTION, "shard1", replica.getName()).process(cluster.getSolrClient());
@@ -86,6 +89,8 @@ public class AssignBackwardCompatibilityTest extends SolrCloudTestCase {
.keySet().iterator().next();
assertFalse("Core name is not unique coreName=" + coreName + " " + coreNames, coreNames.contains(coreName));
coreNames.add(coreName);
+ numLiveReplicas++;
+ waitForState("Expected " + numLiveReplicas + " active replicas", COLLECTION, clusterShape(1, numLiveReplicas));
Replica newReplica = getCollectionState(COLLECTION).getReplicas().stream()
.filter(r -> r.getCoreName().equals(coreName))
@@ -93,9 +98,18 @@ public class AssignBackwardCompatibilityTest extends SolrCloudTestCase {
String coreNodeName = newReplica.getName();
assertFalse("Core node name is not unique", coreNodeNames.contains(coreName));
coreNodeNames.add(coreNodeName);
-
- numLiveReplicas++;
}
}
}
+
+ private int getCounter() throws KeeperException, InterruptedException {
+ try {
+ byte[] data = cluster.getZkClient().getData("/collections/"+COLLECTION+"/counter", null, new Stat(), true);
+ int count = NumberUtils.bytesToInt(data);
+ if (count < 0) throw new AssertionError("Found negative collection counter " + count);
+ return count;
+ } catch (KeeperException e) {
+ return -1;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/161be0a4/solr/core/src/test/org/apache/solr/util/NumberUtilsTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/util/NumberUtilsTest.java b/solr/core/src/test/org/apache/solr/util/NumberUtilsTest.java
new file mode 100644
index 0000000..e249a64
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/util/NumberUtilsTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+package org.apache.solr.util;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.junit.Test;
+
+public class NumberUtilsTest extends SolrTestCaseJ4 {
+ @Test
+ public void testIntToBytes() {
+ assertEquals(0, NumberUtils.bytesToInt(null));
+ assertEquals(-1, encodeAndDecode(-1));
+ assertEquals(-100, encodeAndDecode(-100));
+ assertEquals(-1000, encodeAndDecode(-1000));
+ assertEquals(0, encodeAndDecode(0));
+ assertEquals(100, encodeAndDecode(100));
+ assertEquals(1000, encodeAndDecode(1000));
+ assertEquals(Integer.MAX_VALUE, encodeAndDecode(Integer.MAX_VALUE));
+ assertEquals(Integer.MIN_VALUE, encodeAndDecode(Integer.MIN_VALUE));
+ }
+
+ public int encodeAndDecode(int i) {
+ return NumberUtils.bytesToInt(NumberUtils.intToBytes(i));
+ }
+}