This is an automated email from the ASF dual-hosted git repository.
krathbun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new ad49659613 Remove uses of Thread.suspend and Thread.resume (#5880)
ad49659613 is described below
commit ad4965961331466ec564a81c273d3ebaa0555ead
Author: Kevin Rathbun <[email protected]>
AuthorDate: Mon Sep 15 11:22:55 2025 -0400
Remove uses of Thread.suspend and Thread.resume (#5880)
Removes uses of deprecated Java methods: Thread.suspend() and
Thread.resume(). There was only one use: in ZooCacheIT. Was being used
to simulate a ZooKeeper disconnect, replaced with the Watcher instead
processing a Disconnected event.
closes #5846
---
.../apache/accumulo/core/zookeeper/ZooCache.java | 4 +-
.../apache/accumulo/test/zookeeper/ZooCacheIT.java | 116 ++++++++++-----------
2 files changed, 57 insertions(+), 63 deletions(-)
diff --git
a/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java
b/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java
index b415e0ba0e..afb0b2cf90 100644
--- a/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java
+++ b/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java
@@ -64,7 +64,7 @@ public class ZooCache {
private final NavigableSet<String> watchedPaths;
// visible for tests
- protected final ZCacheWatcher watcher = new ZCacheWatcher();
+ public final ZCacheWatcher watcher = new ZCacheWatcher();
private final List<ZooCacheWatcher> externalWatchers =
Collections.synchronizedList(new ArrayList<>());
@@ -85,7 +85,7 @@ public class ZooCache {
private final AtomicLong zkClientTracker = new AtomicLong();
- class ZCacheWatcher implements Watcher {
+ public class ZCacheWatcher implements Watcher {
@Override
public void process(WatchedEvent event) {
if (log.isTraceEnabled()) {
diff --git
a/test/src/main/java/org/apache/accumulo/test/zookeeper/ZooCacheIT.java
b/test/src/main/java/org/apache/accumulo/test/zookeeper/ZooCacheIT.java
index 352cac37de..fdd70deaa4 100644
--- a/test/src/main/java/org/apache/accumulo/test/zookeeper/ZooCacheIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/zookeeper/ZooCacheIT.java
@@ -30,18 +30,17 @@ import java.io.File;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
import org.apache.accumulo.core.fate.zookeeper.ZooUtil;
-import org.apache.accumulo.core.util.UtilWaitThread;
import org.apache.accumulo.core.zookeeper.ZooCache;
import org.apache.accumulo.core.zookeeper.ZooSession;
import org.apache.accumulo.test.util.Wait;
-import org.apache.zookeeper.ClientCnxn;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
@@ -84,6 +83,21 @@ public class ZooCacheIT {
}
+ public abstract class ZkDisruptionRunnable implements Runnable {
+ final String root = Constants.ZROOT + UUID.randomUUID();
+ final String base = root + Constants.ZTSERVERS;
+ final String child;
+ final String fullPath;
+ final String data1 = "1234";
+ final String data2 = "4321";
+ final TestZooCache zooCache = new TestZooCache(zk, Set.of(base));
+
+ public ZkDisruptionRunnable(String child) {
+ this.child = child;
+ this.fullPath = base + "/" + child;
+ }
+ }
+
private ZooKeeperTestingServer szk;
private ZooSession zk;
private ZooReaderWriter zrw;
@@ -240,90 +254,70 @@ public class ZooCacheIT {
});
}
- private void testDisruptingZookeeper(String child, Runnable zkDisruption)
throws Exception {
- final String root = Constants.ZROOT + UUID.randomUUID();
- final String base = root + Constants.ZTSERVERS;
- final String fullPath = base + "/" + child;
- final String data1 = "1234";
- final String data2 = "4321";
- TestZooCache zooCache = new TestZooCache(zk, Set.of(base));
-
- zrw.mkdirs(base);
- zrw.putPersistentData(fullPath, data1.getBytes(UTF_8),
ZooUtil.NodeExistsPolicy.FAIL);
+ private void testDisruptingZookeeper(ZkDisruptionRunnable zkDisruption)
throws Exception {
+ zrw.mkdirs(zkDisruption.base);
+ zrw.putPersistentData(zkDisruption.fullPath,
zkDisruption.data1.getBytes(UTF_8),
+ ZooUtil.NodeExistsPolicy.FAIL);
- assertArrayEquals(data1.getBytes(UTF_8), zooCache.get(fullPath));
- assertEquals(List.of(child), zooCache.getChildren(base));
+ assertArrayEquals(zkDisruption.data1.getBytes(UTF_8),
+ zkDisruption.zooCache.get(zkDisruption.fullPath));
+ assertEquals(List.of(zkDisruption.child),
zkDisruption.zooCache.getChildren(zkDisruption.base));
- long uc1 = zooCache.getUpdateCount();
+ long uc1 = zkDisruption.zooCache.getUpdateCount();
- assertTrue(zooCache.dataCached(fullPath));
- assertTrue(zooCache.childrenCached(base));
+ assertTrue(zkDisruption.zooCache.dataCached(zkDisruption.fullPath));
+ assertTrue(zkDisruption.zooCache.childrenCached(zkDisruption.base));
- assertArrayEquals(data1.getBytes(UTF_8), zooCache.get(fullPath));
- assertEquals(List.of(child), zooCache.getChildren(base));
+ assertArrayEquals(zkDisruption.data1.getBytes(UTF_8),
+ zkDisruption.zooCache.get(zkDisruption.fullPath));
+ assertEquals(List.of(zkDisruption.child),
zkDisruption.zooCache.getChildren(zkDisruption.base));
- assertEquals(uc1, zooCache.getUpdateCount());
+ assertEquals(uc1, zkDisruption.zooCache.getUpdateCount());
// disrupt zookeeper in some way that should cause zoocache to be cleared
zkDisruption.run();
// clearing the cache should increment the update count
- Wait.waitFor(() -> uc1 != zooCache.getUpdateCount());
+ Wait.waitFor(() -> uc1 != zkDisruption.zooCache.getUpdateCount());
// The data and children previously cached should no longer be cached
- assertFalse(zooCache.dataCached(fullPath));
- assertFalse(zooCache.childrenCached(base));
+ assertFalse(zkDisruption.zooCache.dataCached(zkDisruption.fullPath));
+ assertFalse(zkDisruption.zooCache.childrenCached(zkDisruption.base));
- assertArrayEquals(data1.getBytes(UTF_8), zooCache.get(fullPath));
- assertEquals(List.of(child), zooCache.getChildren(base));
+ assertArrayEquals(zkDisruption.data1.getBytes(UTF_8),
+ zkDisruption.zooCache.get(zkDisruption.fullPath));
+ assertEquals(List.of(zkDisruption.child),
zkDisruption.zooCache.getChildren(zkDisruption.base));
// after the event, ensure that zoocache will still eventually see
updates. May have
// reregistered watchers.
- zrw.putPersistentData(fullPath, data2.getBytes(UTF_8),
ZooUtil.NodeExistsPolicy.OVERWRITE);
- Wait.waitFor(() -> Arrays.equals(data2.getBytes(UTF_8),
zooCache.get(fullPath)));
+ zrw.putPersistentData(zkDisruption.fullPath,
zkDisruption.data2.getBytes(UTF_8),
+ ZooUtil.NodeExistsPolicy.OVERWRITE);
+ Wait.waitFor(() -> Arrays.equals(zkDisruption.data2.getBytes(UTF_8),
+ zkDisruption.zooCache.get(zkDisruption.fullPath)));
}
@Test
public void testZookeeperRestart() throws Exception {
- testDisruptingZookeeper("restart", () -> {
- try {
- szk.restart();
- } catch (Exception e) {
- throw new IllegalStateException(e);
+ testDisruptingZookeeper(new ZkDisruptionRunnable("restart") {
+ @Override
+ public void run() {
+ try {
+ szk.restart();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
}
});
}
- @SuppressWarnings({"deprecation", "removal"})
@Test
public void testDisconnect() throws Exception {
- testDisruptingZookeeper("disconnect", () -> {
- try {
- // Find the zookeeper thread that sends stuff to the server and pause
it for longer than the
- // session timeout. This should cause the server to disconnect the
session which should
- // cause the cache to clear.
- Thread sendThread = findZookeeperSendThread();
- sendThread.suspend();
- UtilWaitThread.sleep(SESSION_TIMEOUT.plusSeconds(1).toMillis());
- sendThread.resume();
- } catch (Exception e) {
- throw new IllegalStateException(e);
+ testDisruptingZookeeper(new ZkDisruptionRunnable("disconnect") {
+ @Override
+ public void run() {
+ // Simulate a disconnect which should cause the cache to clear
+ this.zooCache.watcher.process(new
WatchedEvent(Watcher.Event.EventType.None,
+ Watcher.Event.KeeperState.Disconnected, null));
}
});
}
-
- private Thread findZookeeperSendThread() {
- Map<Thread,StackTraceElement[]> traces = Thread.getAllStackTraces();
- String className = ClientCnxn.class.getSimpleName() + "$SendThread";
- for (var entry : traces.entrySet()) {
- Thread thread = entry.getKey();
- StackTraceElement[] stackTrace = entry.getValue();
- for (var ste : stackTrace) {
- if (ste.getClassName().contains(className)) {
- return thread;
- }
- }
- }
-
- throw new IllegalStateException("Unable to find stack trace containing
class " + className);
- }
}