Skip to content

Commit

Permalink
TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
massakam committed Mar 25, 2024
1 parent 933d81f commit 5b7a7c7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,12 @@ public void killCluster() throws Exception {
public void sleepCluster(int time, TimeUnit timeUnit, CountDownLatch l) throws InterruptedException, IOException {
throw new UnsupportedOperationException("sleepServer operation is not supported for ZooKeeperClusterUtil");
}

public void stopPeer(int id) throws Exception {
quorumUtil.shutdown(id);
}

public void enableLocalSession(boolean localSessionEnabled) {
quorumUtil.enableLocalSession(localSessionEnabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -895,4 +895,32 @@ public void processResult(int rc, String path, Object ctx) {
logger.info("Delete children from znode " + path);
}

@Test
public void testAllowReadOnlyMode() throws Exception {
if (zkUtil instanceof ZooKeeperClusterUtil) {
System.setProperty("readonlymode.enabled", "true");
((ZooKeeperClusterUtil) zkUtil).enableLocalSession(true);
zkUtil.restartCluster();
Thread.sleep(2000);
((ZooKeeperClusterUtil) zkUtil).stopPeer(2);
((ZooKeeperClusterUtil) zkUtil).stopPeer(3);
}

try (ZooKeeperClient client = ZooKeeperClient.newBuilder()
.connectString(zkUtil.getZooKeeperConnectString())
.sessionTimeoutMs(100000)
.watchers(new HashSet<Watcher>())
.operationRetryPolicy(retryPolicy)
.allowReadOnlyMode(true)
.build()) {
Assert.assertTrue("Client failed to connect a ZooKeeper in read-only mode.",
client.getState().isConnected());
} finally {
if (zkUtil instanceof ZooKeeperClusterUtil) {
System.setProperty("readonlymode.enabled", "false");
((ZooKeeperClusterUtil) zkUtil).enableLocalSession(false);
}
}
}

}

0 comments on commit 5b7a7c7

Please sign in to comment.