You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ke...@apache.org on 2023/08/13 02:33:41 UTC
[curator] branch master updated: CURATOR-667: Fix abnormal event config path from getConfig (#474)
This is an automated email from the ASF dual-hosted git repository.
kezhuw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git
The following commit(s) were added to refs/heads/master by this push:
new abfa96f0 CURATOR-667: Fix abnormal event config path from getConfig (#474)
abfa96f0 is described below
commit abfa96f0622549f610eda08b62a1fead87452083
Author: Kezhu Wang <ke...@apache.org>
AuthorDate: Sun Aug 13 10:33:36 2023 +0800
CURATOR-667: Fix abnormal event config path from getConfig (#474)
`getConfig` will read data from path "/zookeeper/config" which belongs
to no namespace nor chroot in ZooKeeper side. Path in background event
or watch event should stick to "/zookeeper/config".
See also:
* https://issues.apache.org/jira/browse/ZOOKEEPER-4601
* https://lists.apache.org/thread/2tsg1hcopl80zot12tqrynrbg2h792jf
---
.../framework/imps/GetConfigBuilderImpl.java | 8 ++--
.../curator/framework/imps/TestFramework.java | 44 ++++++++++++++++++++++
2 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
index 0dca255f..91f20d4d 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
@@ -39,15 +39,15 @@ public class GetConfigBuilderImpl
private Stat stat;
public GetConfigBuilderImpl(CuratorFrameworkImpl client) {
- this.client = client;
+ this.client = (CuratorFrameworkImpl) client.usingNamespace(null);
backgrounding = new Backgrounding();
- watching = new Watching(client);
+ watching = new Watching(this.client);
}
public GetConfigBuilderImpl(CuratorFrameworkImpl client, Backgrounding backgrounding, Watcher watcher, Stat stat) {
- this.client = client;
+ this.client = (CuratorFrameworkImpl) client.usingNamespace(null);
this.backgrounding = backgrounding;
- this.watching = new Watching(client, watcher);
+ this.watching = new Watching(this.client, watcher);
this.stat = stat;
}
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
index 5c7fb1fa..63adc76c 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
@@ -77,6 +77,7 @@ import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.client.ZKClientConfig;
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Stat;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
@@ -89,10 +90,16 @@ import org.slf4j.LoggerFactory;
public class TestFramework extends BaseClassForTests {
private final Logger log = LoggerFactory.getLogger(getClass());
+ private static final String superUserPasswordDigest = "curator-test:zghsj3JfJqK7DbWf0RQ1BgbJH9w="; // ran from
+ // DigestAuthenticationProvider.generateDigest(superUserPassword);
+ private static final String superUserPassword = "curator-test";
+
@BeforeEach
@Override
public void setup() throws Exception {
System.setProperty("znode.container.checkIntervalMs", "1000");
+ QuorumPeerConfig.setReconfigEnabled(true);
+ System.setProperty("zookeeper.DigestAuthenticationProvider.superDigest", superUserPasswordDigest);
super.setup();
}
@@ -1124,6 +1131,43 @@ public class TestFramework extends BaseClassForTests {
}
}
+ @Test
+ public void testBackgroundConfigPathWithNamespace() throws Exception {
+ CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
+ try (CuratorFramework client = builder.connectString(server.getConnectString())
+ .retryPolicy(new RetryOneTime(1))
+ .authorization("digest", superUserPassword.getBytes())
+ .build()) {
+ client.start();
+ assertBackgroundConfigPath(client);
+ assertBackgroundConfigPath(client.usingNamespace("zoo"));
+ assertBackgroundConfigPath(client.usingNamespace("zookeeper"));
+ assertBackgroundConfigPath(client.usingNamespace("zookeeper/config"));
+ assertBackgroundConfigPath(client.usingNamespace("foo"));
+ assertBackgroundConfigPath(client.usingNamespace("foo/bar"));
+ }
+ }
+
+ private void assertBackgroundConfigPath(CuratorFramework client) throws Exception {
+ BlockingQueue<CuratorEvent> events = new LinkedBlockingQueue<>();
+ BlockingQueue<WatchedEvent> watchedEvents = new LinkedBlockingQueue<>();
+ BackgroundCallback callback = (CuratorFramework ignored, CuratorEvent event) -> {
+ events.add(event);
+ };
+ Watcher watcher = watchedEvents::add;
+
+ client.getConfig().usingWatcher(watcher).inBackground(callback).forEnsemble();
+ CuratorEvent event = events.poll(10, TimeUnit.SECONDS);
+ assertNotNull(event);
+ assertEquals("/zookeeper/config", event.getPath());
+
+ client.usingNamespace(null).setData().forPath("/zookeeper/config", event.getData());
+ WatchedEvent watchedEvent = watchedEvents.poll(10, TimeUnit.SECONDS);
+ assertNotNull(watchedEvent);
+ assertEquals(Watcher.Event.EventType.NodeDataChanged, watchedEvent.getType());
+ assertEquals("/zookeeper/config", watchedEvent.getPath());
+ }
+
@Test
public void testCreateModes() throws Exception {
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));