dlmarion commented on code in PR #5256:
URL: https://github.com/apache/accumulo/pull/5256#discussion_r1929607254


##########
core/src/test/java/org/apache/accumulo/core/zookeeper/ZooCacheTest.java:
##########
@@ -16,86 +16,118 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.accumulo.core.fate.zookeeper;
+package org.apache.accumulo.core.zookeeper;
 
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.List;
+import java.util.Set;
+import java.util.UUID;
 
-import org.apache.accumulo.core.fate.zookeeper.ZooCache.ZcStat;
-import org.apache.accumulo.core.fate.zookeeper.ZooCache.ZooCacheWatcher;
-import org.apache.accumulo.core.zookeeper.ZooSession;
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.zookeeper.ZooCache.ZooCacheWatcher;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.data.Stat;
-import org.easymock.Capture;
-import org.easymock.EasyMock;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 public class ZooCacheTest {
-  private static final String ZPATH = "/some/path/in/zk";
+
+  /**
+   * Test class that extends ZooCache to suppress the creation of the 
persistent recursive watchers
+   * that are created in the constructor and to provide access to the watcher.
+   */
+  private static class TestZooCache extends ZooCache {
+
+    public TestZooCache(ZooSession zk, Set<String> pathsToWatch) {
+      super(zk, pathsToWatch);
+    }
+
+    @Override
+    protected void setupWatchers() {
+      clear();
+    }
+
+    public void executeWatcher(WatchedEvent event) {
+      // simulate ZooKeeper calling our Watcher
+      watcher.process(event);
+    }
+
+    @Override
+    long getZKClientObjectVersion() {
+      return 1L;
+    }
+
+  }
+
+  private static final String root =
+      Constants.ZROOT + "/" + UUID.randomUUID().toString() + 
Constants.ZTSERVERS;
+  private static final String ZPATH = root + "/testPath";
   private static final byte[] DATA = {(byte) 1, (byte) 2, (byte) 3, (byte) 4};
   private static final List<String> CHILDREN = java.util.Arrays.asList("huey", 
"dewey", "louie");
 
   private ZooSession zk;
-  private ZooCache zc;
+  private TestZooCache zc;
 
   @BeforeEach
   public void setUp() {
     zk = createStrictMock(ZooSession.class);
-    zc = new ZooCache(zk);
+    zc = new TestZooCache(zk, Set.of(root));
   }
 
+  @SuppressWarnings("unchecked")
   @Test
-  public void testGet() throws Exception {
-    testGet(false);
+  public void testOverlappingPaths() throws Exception {
+    expect(zk.getConnectionCounter()).andReturn(2L).times(2);
+    zk.addPersistentRecursiveWatchers(isA(Set.class), isA(Watcher.class));
+    replay(zk);
+    assertThrows(IllegalArgumentException.class,
+        () -> new ZooCache(zk, Set.of(root, root + "/localhost:9995")));
+
+    Set<String> goodPaths = 
Set.of("/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/compactors",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/dead/tservers",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/gc/lock",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/managers/lock",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/namespaces",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/recovery",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/root_tablet",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/sservers",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/tables",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/tservers",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/users",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/mini",
+        "/accumulo/8247eee6-a176-4e19-baf7-e3da965fe050/monitor/lock");
+    new ZooCache(zk, goodPaths);
+    verify(zk);

Review Comment:
   Added test for unwatched paths in ddeee6b



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to