You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by dr...@apache.org on 2015/08/19 01:18:26 UTC
[10/31] curator git commit: wip
wip
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/d3672a5a
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/d3672a5a
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/d3672a5a
Branch: refs/heads/CURATOR-3.0
Commit: d3672a5acbd2bdf0f8caa9b7c8ea07e9d4e4dd2a
Parents: 58fcc54
Author: randgalt <ra...@apache.org>
Authored: Mon May 11 16:19:45 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Mon May 11 16:19:45 2015 -0500
----------------------------------------------------------------------
.../WatcherRemoveCuratorFramework.java | 18 +++
.../api/BackgroundPathableQuietly.java | 18 +++
.../apache/curator/framework/api/Quietly.java | 18 +++
.../framework/api/RemoveWatchesBuilder.java | 18 +++
.../framework/api/RemoveWatchesLocal.java | 18 +++
.../framework/api/RemoveWatchesType.java | 18 +++
.../curator/framework/imps/NamespaceFacade.java | 6 -
.../imps/RemoveWatchesBuilderImpl.java | 20 +++-
.../framework/imps/WatcherRemovalFacade.java | 4 +-
.../framework/imps/WatcherRemovalManager.java | 20 +++-
.../framework/imps/TestRemoveWatches.java | 18 +++
.../imps/TestWatcherRemovalManager.java | 113 +++++++++++++++----
.../recipes/cache/PathChildrenCache.java | 9 +-
.../curator/framework/imps/TestCleanState.java | 68 +++++++++++
.../recipes/cache/TestPathChildrenCache.java | 60 +++++-----
.../org/apache/curator/test/WatchersDebug.java | 18 +++
16 files changed, 385 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/main/java/org/apache/curator/framework/WatcherRemoveCuratorFramework.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/WatcherRemoveCuratorFramework.java b/curator-framework/src/main/java/org/apache/curator/framework/WatcherRemoveCuratorFramework.java
index 58b4bf8..e41b186 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/WatcherRemoveCuratorFramework.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/WatcherRemoveCuratorFramework.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.framework;
public interface WatcherRemoveCuratorFramework extends CuratorFramework
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundPathableQuietly.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundPathableQuietly.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundPathableQuietly.java
index 1174067..13202aa 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundPathableQuietly.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundPathableQuietly.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.framework.api;
public interface BackgroundPathableQuietly<T> extends BackgroundPathable<T>, Quietly<BackgroundPathable<T>>
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/main/java/org/apache/curator/framework/api/Quietly.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Quietly.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Quietly.java
index cf4edc8..ad3762f 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/Quietly.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Quietly.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.framework.api;
public interface Quietly<T>
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesBuilder.java
index 5d48a9e..6cc0b05 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesBuilder.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesBuilder.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.framework.api;
import org.apache.zookeeper.Watcher;
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java
index d183a6a..de6ad9b 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.framework.api;
/**
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesType.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesType.java b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesType.java
index 3c58b7b..4885423 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesType.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesType.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.framework.api;
import org.apache.zookeeper.Watcher.WatcherType;
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceFacade.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceFacade.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceFacade.java
index 8dc7ae1..c8b952a 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceFacade.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceFacade.java
@@ -42,12 +42,6 @@ class NamespaceFacade extends CuratorFrameworkImpl
}
@Override
- public WatcherRemoveCuratorFramework newWatcherRemoveCuratorFramework()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
public CuratorFramework nonNamespaceView()
{
return usingNamespace(null);
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java
index ab977a9..10d58d0 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.framework.imps;
import java.util.concurrent.Callable;
@@ -157,7 +175,7 @@ public class RemoveWatchesBuilderImpl implements RemoveWatchesBuilder, RemoveWat
client.processBackgroundOperation(new OperationAndData<String>(this, path, backgrounding.getCallback(), errorCallback, backgrounding.getContext()), null);
}
- private void pathInForeground(final String path) throws Exception
+ void pathInForeground(final String path) throws Exception
{
RetryLoop.callWithRetry(client.getZookeeperClient(),
new Callable<Void>()
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalFacade.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalFacade.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalFacade.java
index a11ca5d..664c9b0 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalFacade.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalFacade.java
@@ -63,13 +63,13 @@ class WatcherRemovalFacade extends CuratorFrameworkImpl implements WatcherRemove
@Override
public CuratorFramework nonNamespaceView()
{
- return client.usingNamespace(null);
+ return client.nonNamespaceView();
}
@Override
public CuratorFramework usingNamespace(String newNamespace)
{
- return client.getNamespaceFacadeCache().get(newNamespace);
+ return client.usingNamespace(newNamespace);
}
@Override
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalManager.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalManager.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalManager.java
index 9461de5..689ade2 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalManager.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/WatcherRemovalManager.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.framework.imps;
import com.google.common.collect.Maps;
@@ -36,7 +54,7 @@ class WatcherRemovalManager
log.debug("Removing watcher for path: " + path);
RemoveWatchesBuilderImpl builder = new RemoveWatchesBuilderImpl(client);
builder.prepInternalRemoval(watcher);
- builder.forPath(path);
+ builder.pathInForeground(path);
}
catch ( Exception e )
{
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java
index 28799f7..0533b25 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.framework.imps;
import java.util.concurrent.CountDownLatch;
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherRemovalManager.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherRemovalManager.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherRemovalManager.java
index 9a5dbdc..6e28bea 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherRemovalManager.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherRemovalManager.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.framework.imps;
import org.apache.curator.framework.CuratorFramework;
@@ -23,32 +41,89 @@ public class TestWatcherRemovalManager extends BaseClassForTests
try
{
client.start();
+ internalTryBasic(client);
+ }
+ finally
+ {
+ CloseableUtils.closeQuietly(client);
+ }
+ }
- WatcherRemoveCuratorFramework removerClient = client.newWatcherRemoveCuratorFramework();
-
- Watcher watcher = new Watcher()
- {
- @Override
- public void process(WatchedEvent event)
- {
- // NOP
- }
- };
- removerClient.checkExists().usingWatcher(watcher).forPath("/hey");
-
- List<String> existWatches = WatchersDebug.getExistWatches(client.getZookeeperClient().getZooKeeper());
- Assert.assertEquals(existWatches.size(), 1);
-
- removerClient.removeWatchers();
+ @Test
+ public void testBasicNamespace1() throws Exception
+ {
+ CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
+ try
+ {
+ client.start();
+ internalTryBasic(client.usingNamespace("foo"));
+ }
+ finally
+ {
+ CloseableUtils.closeQuietly(client);
+ }
+ }
- new Timing().sleepABit();
+ @Test
+ public void testBasicNamespace2() throws Exception
+ {
+ CuratorFramework client = CuratorFrameworkFactory.builder()
+ .connectString(server.getConnectString())
+ .retryPolicy(new RetryOneTime(1))
+ .namespace("hey")
+ .build();
+ try
+ {
+ client.start();
+ internalTryBasic(client);
+ }
+ finally
+ {
+ CloseableUtils.closeQuietly(client);
+ }
+ }
- existWatches = WatchersDebug.getExistWatches(client.getZookeeperClient().getZooKeeper());
- Assert.assertEquals(existWatches.size(), 0);
+ @Test
+ public void testBasicNamespace3() throws Exception
+ {
+ CuratorFramework client = CuratorFrameworkFactory.builder()
+ .connectString(server.getConnectString())
+ .retryPolicy(new RetryOneTime(1))
+ .namespace("hey")
+ .build();
+ try
+ {
+ client.start();
+ internalTryBasic(client.usingNamespace("lakjsf"));
}
finally
{
CloseableUtils.closeQuietly(client);
}
}
+
+ private void internalTryBasic(CuratorFramework client) throws Exception
+ {
+ WatcherRemoveCuratorFramework removerClient = client.newWatcherRemoveCuratorFramework();
+
+ Watcher watcher = new Watcher()
+ {
+ @Override
+ public void process(WatchedEvent event)
+ {
+ // NOP
+ }
+ };
+ removerClient.checkExists().usingWatcher(watcher).forPath("/hey");
+
+ List<String> existWatches = WatchersDebug.getExistWatches(client.getZookeeperClient().getZooKeeper());
+ Assert.assertEquals(existWatches.size(), 1);
+
+ removerClient.removeWatchers();
+
+ new Timing().sleepABit();
+
+ existWatches = WatchersDebug.getExistWatches(client.getZookeeperClient().getZooKeeper());
+ Assert.assertEquals(existWatches.size(), 0);
+ }
}
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
index 71d83fe..5c413b6 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
@@ -24,10 +24,10 @@ import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.WatcherRemoveCuratorFramework;
import org.apache.curator.framework.api.BackgroundCallback;
import org.apache.curator.framework.api.CuratorEvent;
import org.apache.curator.framework.listen.ListenerContainer;
@@ -35,6 +35,7 @@ import org.apache.curator.framework.state.ConnectionState;
import org.apache.curator.framework.state.ConnectionStateListener;
import org.apache.curator.utils.CloseableExecutorService;
import org.apache.curator.utils.EnsurePath;
+import org.apache.curator.utils.PathUtils;
import org.apache.curator.utils.ThreadUtils;
import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.KeeperException;
@@ -54,7 +55,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.curator.utils.PathUtils;
/**
* <p>A utility that attempts to keep all data from all children of a ZK path locally cached. This class
@@ -69,7 +69,7 @@ import org.apache.curator.utils.PathUtils;
public class PathChildrenCache implements Closeable
{
private final Logger log = LoggerFactory.getLogger(getClass());
- private final CuratorFramework client;
+ private final WatcherRemoveCuratorFramework client;
private final String path;
private final CloseableExecutorService executorService;
private final boolean cacheData;
@@ -216,7 +216,7 @@ public class PathChildrenCache implements Closeable
*/
public PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final CloseableExecutorService executorService)
{
- this.client = client;
+ this.client = client.newWatcherRemoveCuratorFramework();
this.path = PathUtils.validatePath(path);
this.cacheData = cacheData;
this.dataIsCompressed = dataIsCompressed;
@@ -375,6 +375,7 @@ public class PathChildrenCache implements Closeable
executorService.close();
client.clearWatcherReferences(childrenWatcher);
client.clearWatcherReferences(dataWatcher);
+ client.removeWatchers();
// TODO
// This seems to enable even more GC - I'm not sure why yet - it
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-recipes/src/test/java/org/apache/curator/framework/imps/TestCleanState.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/imps/TestCleanState.java b/curator-recipes/src/test/java/org/apache/curator/framework/imps/TestCleanState.java
new file mode 100644
index 0000000..95a1088
--- /dev/null
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/imps/TestCleanState.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.test.WatchersDebug;
+import org.apache.curator.utils.CloseableUtils;
+import org.apache.zookeeper.ZooKeeper;
+
+public class TestCleanState
+{
+ public static void closeAndTestClean(CuratorFramework client)
+ {
+ if ( client == null )
+ {
+ return;
+ }
+
+ try
+ {
+ CuratorFrameworkImpl internalClient = (CuratorFrameworkImpl)client;
+ ZooKeeper zooKeeper = internalClient.getZooKeeper();
+ if ( zooKeeper != null )
+ {
+ if ( WatchersDebug.getChildWatches(zooKeeper).size() != 0 )
+ {
+ throw new AssertionError("One or more child watchers are still registered");
+ }
+ if ( WatchersDebug.getExistWatches(zooKeeper).size() != 0 )
+ {
+ throw new AssertionError("One or more exists watchers are still registered");
+ }
+ if ( WatchersDebug.getDataWatches(zooKeeper).size() != 0 )
+ {
+ throw new AssertionError("One or more data watchers are still registered");
+ }
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace(); // not sure what to do here
+ }
+ finally
+ {
+ CloseableUtils.closeQuietly(client);
+ }
+ }
+
+ private TestCleanState()
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
index b904bdc..ffcf251 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
@@ -28,7 +28,7 @@ import org.apache.curator.framework.api.BackgroundCallback;
import org.apache.curator.framework.api.CuratorEvent;
import org.apache.curator.framework.api.Pathable;
import org.apache.curator.framework.api.UnhandledErrorListener;
-import org.apache.curator.framework.imps.CuratorFrameworkImpl;
+import org.apache.curator.framework.imps.TestCleanState;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.test.KillSession;
@@ -96,15 +96,13 @@ public class TestPathChildrenCache extends BaseClassForTests
finally
{
CloseableUtils.closeQuietly(cache);
- CloseableUtils.closeQuietly(client);
+ TestCleanState.closeAndTestClean(client);
}
}
@Test
public void testClientClosedDuringRefreshErrorMessage() throws Exception
{
- Timing timing = new Timing();
-
// Fiddle with logging so we can intercept the error events for org.apache.curator
final List<LoggingEvent> events = Lists.newArrayList();
Collection<String> messages = Collections2.transform(events, new Function<LoggingEvent, String>() {
@@ -216,7 +214,7 @@ public class TestPathChildrenCache extends BaseClassForTests
finally
{
CloseableUtils.closeQuietly(cache);
- CloseableUtils.closeQuietly(client);
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -270,7 +268,7 @@ public class TestPathChildrenCache extends BaseClassForTests
finally
{
CloseableUtils.closeQuietly(cache);
- CloseableUtils.closeQuietly(client);
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -319,7 +317,7 @@ public class TestPathChildrenCache extends BaseClassForTests
finally
{
CloseableUtils.closeQuietly(cache);
- CloseableUtils.closeQuietly(client);
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -328,6 +326,7 @@ public class TestPathChildrenCache extends BaseClassForTests
{
Timing timing = new Timing();
+ PathChildrenCache cache = null;
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
try
@@ -335,7 +334,7 @@ public class TestPathChildrenCache extends BaseClassForTests
final CountDownLatch updatedLatch = new CountDownLatch(1);
final CountDownLatch addedLatch = new CountDownLatch(1);
client.create().creatingParentsIfNeeded().forPath("/test");
- PathChildrenCache cache = new PathChildrenCache(client, "/test", false);
+ cache = new PathChildrenCache(client, "/test", false);
cache.getListenable().addListener
(
new PathChildrenCacheListener()
@@ -364,7 +363,8 @@ public class TestPathChildrenCache extends BaseClassForTests
}
finally
{
- CloseableUtils.closeQuietly(client);
+ CloseableUtils.closeQuietly(cache);
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -392,7 +392,7 @@ public class TestPathChildrenCache extends BaseClassForTests
}
finally
{
- CloseableUtils.closeQuietly(client);
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -468,7 +468,7 @@ public class TestPathChildrenCache extends BaseClassForTests
}
finally
{
- client.close();
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -562,7 +562,7 @@ public class TestPathChildrenCache extends BaseClassForTests
}
finally
{
- client.close();
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -571,6 +571,7 @@ public class TestPathChildrenCache extends BaseClassForTests
public void testIssue27() throws Exception
{
Timing timing = new Timing();
+ PathChildrenCache cache = null;
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
try
@@ -584,7 +585,7 @@ public class TestPathChildrenCache extends BaseClassForTests
final List<PathChildrenCacheEvent.Type> events = Lists.newArrayList();
final Semaphore semaphore = new Semaphore(0);
- PathChildrenCache cache = new PathChildrenCache(client, "/base", true);
+ cache = new PathChildrenCache(client, "/base", true);
cache.getListenable().addListener
(
new PathChildrenCacheListener()
@@ -619,7 +620,8 @@ public class TestPathChildrenCache extends BaseClassForTests
}
finally
{
- client.close();
+ CloseableUtils.closeQuietly(cache);
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -628,6 +630,7 @@ public class TestPathChildrenCache extends BaseClassForTests
public void testIssue27Alt() throws Exception
{
Timing timing = new Timing();
+ PathChildrenCache cache = null;
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
try
@@ -641,7 +644,7 @@ public class TestPathChildrenCache extends BaseClassForTests
final List<PathChildrenCacheEvent.Type> events = Lists.newArrayList();
final Semaphore semaphore = new Semaphore(0);
- PathChildrenCache cache = new PathChildrenCache(client, "/base", true);
+ cache = new PathChildrenCache(client, "/base", true);
cache.getListenable().addListener
(
new PathChildrenCacheListener()
@@ -671,7 +674,8 @@ public class TestPathChildrenCache extends BaseClassForTests
}
finally
{
- client.close();
+ CloseableUtils.closeQuietly(cache);
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -679,6 +683,7 @@ public class TestPathChildrenCache extends BaseClassForTests
public void testKilledSession() throws Exception
{
Timing timing = new Timing();
+ PathChildrenCache cache = null;
CuratorFramework client = null;
try
{
@@ -686,7 +691,7 @@ public class TestPathChildrenCache extends BaseClassForTests
client.start();
client.create().forPath("/test");
- PathChildrenCache cache = new PathChildrenCache(client, "/test", true);
+ cache = new PathChildrenCache(client, "/test", true);
cache.start();
final CountDownLatch childAddedLatch = new CountDownLatch(1);
@@ -730,7 +735,8 @@ public class TestPathChildrenCache extends BaseClassForTests
}
finally
{
- CloseableUtils.closeQuietly(client);
+ CloseableUtils.closeQuietly(cache);
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -754,7 +760,7 @@ public class TestPathChildrenCache extends BaseClassForTests
}
finally
{
- client.close();
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -798,7 +804,7 @@ public class TestPathChildrenCache extends BaseClassForTests
finally
{
CloseableUtils.closeQuietly(cache);
- CloseableUtils.closeQuietly(client);
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -886,7 +892,7 @@ public class TestPathChildrenCache extends BaseClassForTests
}
finally
{
- client.close();
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -955,7 +961,7 @@ public class TestPathChildrenCache extends BaseClassForTests
}
finally
{
- client.close();
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -988,8 +994,9 @@ public class TestPathChildrenCache extends BaseClassForTests
timing.sleepABit();
Assert.assertFalse(exec.isExecuteCalled());
}
- finally {
- client.close();
+ finally
+ {
+ TestCleanState.closeAndTestClean(client);
}
}
@@ -1034,9 +1041,10 @@ public class TestPathChildrenCache extends BaseClassForTests
latch.await(5, TimeUnit.SECONDS);
Assert.assertTrue(latch.getCount() == 1, "Unexpected exception occurred");
- } finally
+ }
+ finally
{
- CloseableUtils.closeQuietly(client);
+ TestCleanState.closeAndTestClean(client);
}
}
http://git-wip-us.apache.org/repos/asf/curator/blob/d3672a5a/curator-test/src/main/java/org/apache/curator/test/WatchersDebug.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/WatchersDebug.java b/curator-test/src/main/java/org/apache/curator/test/WatchersDebug.java
index a97e5c1..e4c3b7e 100644
--- a/curator-test/src/main/java/org/apache/curator/test/WatchersDebug.java
+++ b/curator-test/src/main/java/org/apache/curator/test/WatchersDebug.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.curator.test;
import org.apache.zookeeper.ZooKeeper;