pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] merlimat closed pull request #979: MockZooKeeper watches for non-existing znode
Date Thu, 01 Jan 1970 00:00:00 GMT
merlimat closed pull request #979: MockZooKeeper watches for non-existing znode
URL: https://github.com/apache/incubator-pulsar/pull/979
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/managed-ledger/src/test/java/org/apache/zookeeper/MockZooKeeper.java b/managed-ledger/src/test/java/org/apache/zookeeper/MockZooKeeper.java
index 4d85c6250..9f1708204 100644
--- a/managed-ledger/src/test/java/org/apache/zookeeper/MockZooKeeper.java
+++ b/managed-ledger/src/test/java/org/apache/zookeeper/MockZooKeeper.java
@@ -159,15 +159,27 @@ public String create(String path, byte[] data, List<ACL> acl,
CreateMode createM
 
             tree.put(path, Pair.create(data, 0));
 
+            final Set<Watcher> toNotifyCreate = Sets.newHashSet();
+            toNotifyCreate.addAll(watchers.get(path));
+
+            final Set<Watcher> toNotifyParent = Sets.newHashSet();
             if (!parent.isEmpty()) {
-                final Set<Watcher> toNotifyParent = Sets.newHashSet();
                 toNotifyParent.addAll(watchers.get(parent));
-
-                executor.execute(() -> {
-                    toNotifyParent.forEach(watcher -> watcher.process(
-                            new WatchedEvent(EventType.NodeChildrenChanged, KeeperState.SyncConnected,
parent)));
-                });
             }
+            watchers.removeAll(path);
+            final String finalPath = path;
+            executor.execute(() -> {
+                    toNotifyCreate.forEach(
+                            watcher -> watcher.process(
+                                    new WatchedEvent(EventType.NodeCreated,
+                                                     KeeperState.SyncConnected,
+                                                     finalPath)));
+                    toNotifyParent.forEach(
+                            watcher -> watcher.process(
+                                    new WatchedEvent(EventType.NodeChildrenChanged,
+                                                     KeeperState.SyncConnected,
+                                                     parent)));
+                });
 
             return path;
         } finally {
@@ -184,9 +196,17 @@ public void create(final String path, final byte[] data, final List<ACL>
acl, Cr
             return;
         }
 
-        executor.execute(() -> {
-            String parent = path.substring(0, path.lastIndexOf("/"));
+        final Set<Watcher> toNotifyCreate = Sets.newHashSet();
+        toNotifyCreate.addAll(watchers.get(path));
+
+        final Set<Watcher> toNotifyParent = Sets.newHashSet();
+        final String parent = path.substring(0, path.lastIndexOf("/"));
+        if (!parent.isEmpty()) {
+            toNotifyParent.addAll(watchers.get(parent));
+        }
+        watchers.removeAll(path);
 
+        executor.execute(() -> {
             mutex.lock();
             if (getProgrammedFailStatus()) {
                 mutex.unlock();
@@ -204,10 +224,17 @@ public void create(final String path, final byte[] data, final List<ACL>
acl, Cr
                 tree.put(path, Pair.create(data, 0));
                 mutex.unlock();
                 cb.processResult(0, path, ctx, null);
-                if (!parent.isEmpty()) {
-                    watchers.get(parent).forEach(watcher -> watcher.process(
-                            new WatchedEvent(EventType.NodeChildrenChanged, KeeperState.SyncConnected,
parent)));
-                }
+
+                toNotifyCreate.forEach(
+                        watcher -> watcher.process(
+                                new WatchedEvent(EventType.NodeCreated,
+                                                 KeeperState.SyncConnected,
+                                                 path)));
+                toNotifyParent.forEach(
+                        watcher -> watcher.process(
+                                new WatchedEvent(EventType.NodeChildrenChanged,
+                                                 KeeperState.SyncConnected,
+                                                 parent)));
             }
         });
 
@@ -517,6 +544,34 @@ public void exists(String path, boolean watch, StatCallback cb, Object
ctx) {
         });
     }
 
+    @Override
+    public void exists(String path, Watcher watcher, StatCallback cb, Object ctx) {
+        executor.execute(() -> {
+            mutex.lock();
+            if (getProgrammedFailStatus()) {
+                mutex.unlock();
+                cb.processResult(failReturnCode.intValue(), path, ctx, null);
+                return;
+            } else if (stopped) {
+                mutex.unlock();
+                cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null);
+                return;
+            }
+
+            if (watcher != null) {
+                watchers.put(path, watcher);
+            }
+
+            if (tree.containsKey(path)) {
+                mutex.unlock();
+                cb.processResult(0, path, ctx, new Stat());
+            } else {
+                mutex.unlock();
+                cb.processResult(KeeperException.Code.NoNode, path, ctx, null);
+            }
+        });
+    }
+
     @Override
     public void sync(String path, VoidCallback cb, Object ctx) {
         executor.execute(() -> {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message