lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject [2/2] lucene-solr git commit: SOLR-8752: Add a test for SizeLimitedDistributedMap and improve javadocs
Date Sat, 27 Feb 2016 07:06:27 GMT
SOLR-8752: Add a test for SizeLimitedDistributedMap and improve javadocs


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/06053fc0
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/06053fc0
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/06053fc0

Branch: refs/heads/master
Commit: 06053fc01cf149553d2cb18535f692fab5699420
Parents: c2bc938
Author: Shalin Shekhar Mangar <shalin@apache.org>
Authored: Sat Feb 27 12:35:58 2016 +0530
Committer: Shalin Shekhar Mangar <shalin@apache.org>
Committed: Sat Feb 27 12:35:58 2016 +0530

----------------------------------------------------------------------
 .../solr/cloud/SizeLimitedDistributedMap.java   |  5 +-
 .../cloud/TestSizeLimitedDistributedMap.java    | 58 ++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/06053fc0/solr/core/src/java/org/apache/solr/cloud/SizeLimitedDistributedMap.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/SizeLimitedDistributedMap.java b/solr/core/src/java/org/apache/solr/cloud/SizeLimitedDistributedMap.java
index 3326dca..82ab141 100644
--- a/solr/core/src/java/org/apache/solr/cloud/SizeLimitedDistributedMap.java
+++ b/solr/core/src/java/org/apache/solr/cloud/SizeLimitedDistributedMap.java
@@ -27,7 +27,10 @@ import org.apache.zookeeper.data.Stat;
 
 /**
  * A size limited distributed map maintained in zk.
- * Oldest znodes (as per modification time) are evicted as newer ones come in. 
+ * Oldest znodes (as per modification time) are evicted as newer ones come in.
+ *
+ * When the map hits the specified maximum size, the oldest <code>maxSize / 10</code>
items
+ * are evicted on the next {@link #put(String, byte[])} invocation.
  */
 public class SizeLimitedDistributedMap extends DistributedMap {
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/06053fc0/solr/core/src/test/org/apache/solr/cloud/TestSizeLimitedDistributedMap.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestSizeLimitedDistributedMap.java b/solr/core/src/test/org/apache/solr/cloud/TestSizeLimitedDistributedMap.java
new file mode 100644
index 0000000..2131f48
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/cloud/TestSizeLimitedDistributedMap.java
@@ -0,0 +1,58 @@
+package org.apache.solr.cloud;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.cloud.SolrZkClient;
+
+public class TestSizeLimitedDistributedMap extends SolrTestCaseJ4 {
+
+  public void testCleanup() throws Exception {
+    String zkDir = createTempDir("TestSizeLimitedDistributedMap").toFile().getAbsolutePath();
+
+    ZkTestServer server = new ZkTestServer(zkDir);
+    try {
+      server.run();
+
+      AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
+      AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
+
+      try (SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), 10000)) {
+        DistributedMap map = Overseer.getCompletedMap(zkClient);
+        assertTrue(map instanceof SizeLimitedDistributedMap);
+        for (int i = 0; i < Overseer.NUM_RESPONSES_TO_STORE; i++) {
+          map.put("xyz_" + i, new byte[0]);
+        }
+
+        assertEquals("Number of items do not match", Overseer.NUM_RESPONSES_TO_STORE, map.size());
+        // add another to trigger cleanup
+        map.put("xyz_10000", new byte[0]);
+        assertEquals("Distributed queue was not cleaned up",
+            Overseer.NUM_RESPONSES_TO_STORE - (Overseer.NUM_RESPONSES_TO_STORE / 10) + 1,
map.size());
+        for (int i = Overseer.NUM_RESPONSES_TO_STORE; i >= Overseer.NUM_RESPONSES_TO_STORE
/ 10; i--) {
+          assertTrue(map.contains("xyz_" + i));
+        }
+        for (int i = Overseer.NUM_RESPONSES_TO_STORE / 10 - 1; i >= 0; i--) {
+          assertFalse(map.contains("xyz_" + i));
+        }
+      }
+    } finally {
+      server.shutdown();
+    }
+  }
+}


Mime
View raw message