keith-turner commented on code in PR #5765:
URL: https://github.com/apache/accumulo/pull/5765#discussion_r2237399109


##########
test/src/main/java/org/apache/accumulo/test/zookeeper/ZooCacheIT.java:
##########
@@ -228,4 +238,105 @@ public void testGetChildren() throws Exception {
           && zooCache.childrenCached(base + "/test3") == false;
     });
   }
+
+  @Test
+  public void testZookeeperRestart() throws Exception {
+    final String root = Constants.ZROOT + UUID.randomUUID();
+    final String base = root + Constants.ZTSERVERS;
+    TestZooCache zooCache = new TestZooCache(zk, Set.of(base));
+
+    zrw.mkdirs(base);
+    zrw.putPersistentData(base + "/test2", new byte[] {1, 2, 3, 4}, 
ZooUtil.NodeExistsPolicy.FAIL);
+
+    assertArrayEquals(new byte[] {1, 2, 3, 4}, zooCache.get(base + "/test2"));
+    assertEquals(List.of("test2"), zooCache.getChildren(base));
+
+    long uc1 = zooCache.getUpdateCount();
+
+    assertTrue(zooCache.dataCached(base + "/test2"));
+    assertTrue(zooCache.childrenCached(base));
+
+    assertArrayEquals(new byte[] {1, 2, 3, 4}, zooCache.get(base + "/test2"));
+    assertEquals(List.of("test2"), zooCache.getChildren(base));
+
+    assertEquals(uc1, zooCache.getUpdateCount());
+
+    // restarting zookeeper should cause the cache to be cleared
+    szk.restart();
+
+    // clearing the cache should increment the update count
+    Wait.waitFor(() -> uc1 != zooCache.getUpdateCount());
+    // The data and children previously cached should no longer be cached
+    assertFalse(zooCache.dataCached(base + "/test2"));
+    assertFalse(zooCache.childrenCached(base));
+
+    assertArrayEquals(new byte[] {1, 2, 3, 4}, zooCache.get(base + "/test2"));
+    assertEquals(List.of("test2"), zooCache.getChildren(base));
+
+    // after the event, ensure that zoocache will still eventually see 
updates. May have
+    // reregistered watchers.
+    zrw.putPersistentData(base + "/test2", new byte[] {4, 3, 2, 1},
+        ZooUtil.NodeExistsPolicy.OVERWRITE);
+    Wait.waitFor(() -> Arrays.equals(new byte[] {4, 3, 2, 1}, 
zooCache.get(base + "/test2")));
+  }
+
+  @SuppressWarnings("deprecation")
+  @Test
+  public void testDisconnect() throws Exception {
+    final String root = Constants.ZROOT + UUID.randomUUID();
+    final String base = root + Constants.ZTSERVERS;
+    TestZooCache zooCache = new TestZooCache(zk, Set.of(base));

Review Comment:
   Made some changes to consolidate duplicate code rather then copy the changes 
you made in the other method.  



##########
test/src/main/java/org/apache/accumulo/test/zookeeper/ZooCacheIT.java:
##########
@@ -228,4 +238,105 @@ public void testGetChildren() throws Exception {
           && zooCache.childrenCached(base + "/test3") == false;
     });
   }
+
+  @Test
+  public void testZookeeperRestart() throws Exception {
+    final String root = Constants.ZROOT + UUID.randomUUID();
+    final String base = root + Constants.ZTSERVERS;
+    TestZooCache zooCache = new TestZooCache(zk, Set.of(base));
+
+    zrw.mkdirs(base);
+    zrw.putPersistentData(base + "/test2", new byte[] {1, 2, 3, 4}, 
ZooUtil.NodeExistsPolicy.FAIL);
+
+    assertArrayEquals(new byte[] {1, 2, 3, 4}, zooCache.get(base + "/test2"));
+    assertEquals(List.of("test2"), zooCache.getChildren(base));
+
+    long uc1 = zooCache.getUpdateCount();
+
+    assertTrue(zooCache.dataCached(base + "/test2"));
+    assertTrue(zooCache.childrenCached(base));
+
+    assertArrayEquals(new byte[] {1, 2, 3, 4}, zooCache.get(base + "/test2"));
+    assertEquals(List.of("test2"), zooCache.getChildren(base));
+
+    assertEquals(uc1, zooCache.getUpdateCount());
+
+    // restarting zookeeper should cause the cache to be cleared
+    szk.restart();
+
+    // clearing the cache should increment the update count
+    Wait.waitFor(() -> uc1 != zooCache.getUpdateCount());
+    // The data and children previously cached should no longer be cached
+    assertFalse(zooCache.dataCached(base + "/test2"));
+    assertFalse(zooCache.childrenCached(base));
+
+    assertArrayEquals(new byte[] {1, 2, 3, 4}, zooCache.get(base + "/test2"));
+    assertEquals(List.of("test2"), zooCache.getChildren(base));
+
+    // after the event, ensure that zoocache will still eventually see 
updates. May have
+    // reregistered watchers.
+    zrw.putPersistentData(base + "/test2", new byte[] {4, 3, 2, 1},
+        ZooUtil.NodeExistsPolicy.OVERWRITE);
+    Wait.waitFor(() -> Arrays.equals(new byte[] {4, 3, 2, 1}, 
zooCache.get(base + "/test2")));
+  }
+
+  @SuppressWarnings("deprecation")
+  @Test
+  public void testDisconnect() throws Exception {
+    final String root = Constants.ZROOT + UUID.randomUUID();
+    final String base = root + Constants.ZTSERVERS;
+    TestZooCache zooCache = new TestZooCache(zk, Set.of(base));

Review Comment:
   Made some changes to consolidate duplicate code rather than copy the changes 
you made in the other method.  



-- 
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