From 58bc969fecc01a1947dd272300d4fb305d221ea2 Mon Sep 17 00:00:00 2001
From: randgalt
Date: Thu, 20 Jul 2017 01:48:40 -0500
Subject: [PATCH] Basic concept of zk 3.4.x compatibility proven. The
Compatibility class checks for a well-known 3.5 class and sets a static that
advertises whether the ZK lib is 3.4.x or 3.5.x. Then, the code "ifs" using
this static. The major work was emulating the kill session injection (that
emulation is done using reflection) and testing. The curator-test-zk module
runs the framework and recipe tests but forces ZooKeeper 3.4.x and uses the
Curator 2.x version of curator-test. This requires a few tricks as the new
code uses new methods/classes on the Curator 3.x version of curator-test.
I'll write a readme documenting how this is done.
---
.../apache/curator/utils/Compatibility.java | 76 +++++
.../utils/InjectSessionExpiration.java | 107 +++++++
.../java/org/apache/curator/BasicTests.java | 4 +-
.../curator/TestSessionFailRetryLoop.java | 11 +-
.../framework/CuratorFrameworkFactory.java | 30 +-
.../curator/framework/SafeIsTtlMode.java | 3 +-
.../framework/imps/CreateBuilderImpl.java | 9 +-
.../imps/CuratorMultiTransactionImpl.java | 18 +-
.../state/ConnectionStateManager.java | 6 +-
.../framework/imps/TestCleanState.java | 7 +
.../imps/TestCreateReturningStat.java | 13 +-
.../imps/TestEnabledSessionExpiredState.java | 8 +-
.../curator/framework/imps/TestFramework.java | 3 +-
.../framework/imps/TestFrameworkEdges.java | 8 +-
.../framework/imps/TestReconfiguration.java | 9 +-
.../framework/imps/TestRemoveWatches.java | 6 +-
.../curator/framework/imps/TestTtlNodes.java | 5 +-
.../imps/TestWatcherRemovalManager.java | 5 +-
.../recipes/cache/TestEventOrdering.java | 3 +-
.../recipes/cache/TestNodeCache.java | 4 +-
.../recipes/cache/TestPathChildrenCache.java | 4 +-
.../recipes/cache/TestTreeCache.java | 4 +-
.../recipes/leader/TestLeaderLatch.java | 3 +-
.../recipes/leader/TestLeaderSelector.java | 9 +-
.../recipes/locks/TestInterProcessMutex.java | 5 +-
.../locks/TestInterProcessMutexBase.java | 7 +-
.../nodes/TestPersistentEphemeralNode.java | 14 +-
.../recipes/nodes/TestPersistentNode.java | 3 +-
curator-test-zk34/pom.xml | 44 +++
.../framework/imps/TestCleanState.java | 25 --
.../apache/curator/test/Compatibility.java | 35 ++
curator-test/pom.xml | 19 ++
.../apache/curator/test/CuratorTestBase.java | 27 ++
.../apache/curator/test/KillSession2.java} | 32 +-
.../java/org/apache/curator/test/Timing2.java | 299 ++++++++++++++++++
.../curator/test/Zk35MethodInterceptor.java | 55 ++++
.../apache/curator/test/Compatibility.java | 34 ++
.../curator/test/KillServerSession.java | 122 -------
.../java/org/apache/curator/test/Timing.java | 75 +----
.../x/async/CompletableBaseClassForTests.java | 3 +-
.../details/TestServiceDiscovery.java | 8 +-
pom.xml | 7 +
42 files changed, 822 insertions(+), 347 deletions(-)
create mode 100644 curator-client/src/main/java/org/apache/curator/utils/Compatibility.java
create mode 100644 curator-client/src/main/java/org/apache/curator/utils/InjectSessionExpiration.java
delete mode 100644 curator-test-zk34/src/test/java/org/apache/curator/framework/imps/TestCleanState.java
create mode 100644 curator-test-zk34/src/test/java/org/apache/curator/test/Compatibility.java
create mode 100644 curator-test/src/compatibility/java/org/apache/curator/test/CuratorTestBase.java
rename curator-test/src/{main/java/org/apache/curator/test/KillSession.java => compatibility/java/org/apache/curator/test/KillSession2.java} (55%)
create mode 100644 curator-test/src/compatibility/java/org/apache/curator/test/Timing2.java
create mode 100644 curator-test/src/compatibility/java/org/apache/curator/test/Zk35MethodInterceptor.java
create mode 100644 curator-test/src/main/java/org/apache/curator/test/Compatibility.java
delete mode 100644 curator-test/src/main/java/org/apache/curator/test/KillServerSession.java
diff --git a/curator-client/src/main/java/org/apache/curator/utils/Compatibility.java b/curator-client/src/main/java/org/apache/curator/utils/Compatibility.java
new file mode 100644
index 0000000000..58b62a771c
--- /dev/null
+++ b/curator-client/src/main/java/org/apache/curator/utils/Compatibility.java
@@ -0,0 +1,76 @@
+/**
+ * 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.utils;
+
+import org.apache.zookeeper.ZooKeeper;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utils to help with ZK 3.4.x compatibility
+ */
+public class Compatibility
+{
+ private static final boolean hasZooKeeperAdmin;
+ static
+ {
+ boolean hasIt;
+ try
+ {
+ Class.forName("org.apache.zookeeper.admin.ZooKeeperAdmin");
+ hasIt = true;
+ }
+ catch ( ClassNotFoundException e )
+ {
+ hasIt = false;
+ LoggerFactory.getLogger(Compatibility.class).info("Running in ZooKeeper 3.4.x compatibility mode");
+ }
+ hasZooKeeperAdmin = hasIt;
+ }
+
+ /**
+ * Return true if the classpath ZooKeeper library is 3.4.x
+ *
+ * @return true/false
+ */
+ public static boolean isZK34()
+ {
+ return !hasZooKeeperAdmin;
+ }
+
+ /**
+ * For ZooKeeper 3.5.x, use the supported zooKeeper.getTestable().injectSessionExpiration().
+ * For ZooKeeper 3.4.x do the equivalent via reflection
+ *
+ * @param zooKeeper client
+ */
+ public static void injectSessionExpiration(ZooKeeper zooKeeper)
+ {
+ if ( isZK34() )
+ {
+ InjectSessionExpiration.injectSessionExpiration(zooKeeper);
+ }
+ else
+ {
+ // LOL - this method was proposed by me (JZ) in 2013 for totally unrelated reasons
+ // it got added to ZK 3.5 and now does exactly what we need
+ // https://issues.apache.org/jira/browse/ZOOKEEPER-1730
+ zooKeeper.getTestable().injectSessionExpiration();
+ }
+ }
+}
diff --git a/curator-client/src/main/java/org/apache/curator/utils/InjectSessionExpiration.java b/curator-client/src/main/java/org/apache/curator/utils/InjectSessionExpiration.java
new file mode 100644
index 0000000000..996e9a2e1b
--- /dev/null
+++ b/curator-client/src/main/java/org/apache/curator/utils/InjectSessionExpiration.java
@@ -0,0 +1,107 @@
+/**
+ * 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.utils;
+
+import org.apache.zookeeper.ClientCnxn;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooKeeper;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+// reflective version of zooKeeper.getTestable().injectSessionExpiration();
+@SuppressWarnings("JavaReflectionMemberAccess")
+public class InjectSessionExpiration
+{
+ private static final Field cnxnField;
+ private static final Field stateField;
+ private static final Field eventThreadField;
+ private static final Field sendThreadField;
+ private static final Method queueEventMethod;
+ private static final Method queueEventOfDeathMethod;
+ private static final Method getClientCnxnSocketMethod;
+ private static final Method wakeupCnxnMethod;
+ static
+ {
+ Field localCnxnField;
+ Field localStateField;
+ Field localEventThreadField;
+ Field localSendThreadField;
+ Method localQueueEventMethod;
+ Method localEventOfDeathMethod;
+ Method localGetClientCnxnSocketMethod;
+ Method localWakeupCnxnMethod;
+ try
+ {
+ Class> eventThreadClass = Class.forName("org.apache.zookeeper.ClientCnxn$EventThread");
+ Class> sendThreadClass = Class.forName("org.apache.zookeeper.ClientCnxn$SendThread");
+ Class> clientCnxnSocketClass = Class.forName("org.apache.zookeeper.ClientCnxnSocket");
+
+ localCnxnField = ZooKeeper.class.getDeclaredField("cnxn");
+ localCnxnField.setAccessible(true);
+ localStateField = ClientCnxn.class.getDeclaredField("state");
+ localStateField.setAccessible(true);
+ localEventThreadField = ClientCnxn.class.getDeclaredField("eventThread");
+ localEventThreadField.setAccessible(true);
+ localSendThreadField = ClientCnxn.class.getDeclaredField("sendThread");
+ localSendThreadField.setAccessible(true);
+ localQueueEventMethod = eventThreadClass.getDeclaredMethod("queueEvent", WatchedEvent.class);
+ localQueueEventMethod.setAccessible(true);
+ localEventOfDeathMethod = eventThreadClass.getDeclaredMethod("queueEventOfDeath");
+ localEventOfDeathMethod.setAccessible(true);
+ localGetClientCnxnSocketMethod = sendThreadClass.getDeclaredMethod("getClientCnxnSocket");
+ localGetClientCnxnSocketMethod.setAccessible(true);
+ localWakeupCnxnMethod = clientCnxnSocketClass.getDeclaredMethod("wakeupCnxn");
+ localWakeupCnxnMethod.setAccessible(true);
+ }
+ catch ( ReflectiveOperationException e )
+ {
+ throw new RuntimeException("Could not access internal ZooKeeper fields", e);
+ }
+ cnxnField = localCnxnField;
+ stateField = localStateField;
+ eventThreadField = localEventThreadField;
+ sendThreadField = localSendThreadField;
+ queueEventMethod = localQueueEventMethod;
+ queueEventOfDeathMethod = localEventOfDeathMethod;
+ getClientCnxnSocketMethod = localGetClientCnxnSocketMethod;
+ wakeupCnxnMethod = localWakeupCnxnMethod;
+ }
+
+ public static void injectSessionExpiration(ZooKeeper zooKeeper)
+ {
+ try
+ {
+ WatchedEvent event = new WatchedEvent(Watcher.Event.EventType.None, Watcher.Event.KeeperState.Expired, null);
+
+ ClientCnxn clientCnxn = (ClientCnxn)cnxnField.get(zooKeeper);
+ Object eventThread = eventThreadField.get(clientCnxn);
+ queueEventMethod.invoke(eventThread, event);
+ queueEventOfDeathMethod.invoke(eventThread);
+ stateField.set(clientCnxn, ZooKeeper.States.CLOSED);
+ Object sendThread = sendThreadField.get(clientCnxn);
+ Object clientCnxnSocket = getClientCnxnSocketMethod.invoke(sendThread);
+ wakeupCnxnMethod.invoke(clientCnxnSocket);
+ }
+ catch ( ReflectiveOperationException e )
+ {
+ throw new RuntimeException("Could not inject session expiration using reflection", e);
+ }
+ }
+}
diff --git a/curator-client/src/test/java/org/apache/curator/BasicTests.java b/curator-client/src/test/java/org/apache/curator/BasicTests.java
index eee5047def..94d418b90a 100644
--- a/curator-client/src/test/java/org/apache/curator/BasicTests.java
+++ b/curator-client/src/test/java/org/apache/curator/BasicTests.java
@@ -21,7 +21,7 @@
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
-import org.apache.curator.test.KillSession;
+import org.apache.curator.test.KillSession2;
import org.apache.curator.test.Timing;
import org.apache.curator.utils.ZookeeperFactory;
import org.apache.zookeeper.CreateMode;
@@ -100,7 +100,7 @@ public Object call() throws Exception
// ignore
}
- KillSession.kill(client.getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZooKeeper());
Assert.assertTrue(timing.awaitLatch(latch));
}
diff --git a/curator-client/src/test/java/org/apache/curator/TestSessionFailRetryLoop.java b/curator-client/src/test/java/org/apache/curator/TestSessionFailRetryLoop.java
index b33939f342..e56f4d454a 100644
--- a/curator-client/src/test/java/org/apache/curator/TestSessionFailRetryLoop.java
+++ b/curator-client/src/test/java/org/apache/curator/TestSessionFailRetryLoop.java
@@ -20,9 +20,8 @@
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.test.BaseClassForTests;
+import org.apache.curator.test.KillSession2;
import org.apache.curator.utils.CloseableUtils;
-import org.apache.curator.retry.RetryOneTime;
-import org.apache.curator.test.KillSession;
import org.apache.curator.test.Timing;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -58,7 +57,7 @@ public Void call() throws Exception
if ( firstTime.compareAndSet(true, false) )
{
Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
- KillSession.kill(client.getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZooKeeper());
client.getZooKeeper();
client.blockUntilConnectedOrTimedOut();
}
@@ -132,7 +131,7 @@ public Void call() throws Exception
if ( firstTime.compareAndSet(true, false) )
{
Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
- KillSession.kill(client.getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZooKeeper());
client.getZooKeeper();
client.blockUntilConnectedOrTimedOut();
}
@@ -197,7 +196,7 @@ public void testBasic() throws Exception
public Void call() throws Exception
{
Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
- KillSession.kill(client.getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZooKeeper());
timing.sleepABit();
@@ -259,7 +258,7 @@ public Object call() throws Exception
public Void call() throws Exception
{
Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
- KillSession.kill(client.getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZooKeeper());
client.getZooKeeper();
client.blockUntilConnectedOrTimedOut();
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
index 5ce7762e29..18011aaf5b 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
@@ -44,7 +44,6 @@
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
-import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
@@ -52,6 +51,8 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
+import static org.apache.curator.utils.Compatibility.isZK34;
+
/**
* Factory methods for creating framework-style clients
*/
@@ -68,33 +69,6 @@ public class CuratorFrameworkFactory
private static final long DEFAULT_INACTIVE_THRESHOLD_MS = (int)TimeUnit.MINUTES.toMillis(3);
private static final int DEFAULT_CLOSE_WAIT_MS = (int)TimeUnit.SECONDS.toMillis(1);
- private static final boolean hasZooKeeperAdmin;
- static
- {
- boolean hasIt;
- try
- {
- Class.forName("org.apache.zookeeper.admin.ZooKeeperAdmin");
- hasIt = true;
- }
- catch ( ClassNotFoundException e )
- {
- hasIt = false;
- LoggerFactory.getLogger(CuratorFrameworkFactory.class).info("Running in ZooKeeper 3.4.x compatibility mode");
- }
- hasZooKeeperAdmin = hasIt;
- }
-
- /**
- * Return true if the classpath ZooKeeper library is 3.4.x
- *
- * @return true/false
- */
- public static boolean isZK34()
- {
- return !hasZooKeeperAdmin;
- }
-
/**
* Return a new builder that builds a CuratorFramework
*
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/SafeIsTtlMode.java b/curator-framework/src/main/java/org/apache/curator/framework/SafeIsTtlMode.java
index 3c4b9e67a7..e499a7b9d8 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/SafeIsTtlMode.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/SafeIsTtlMode.java
@@ -18,6 +18,7 @@
*/
package org.apache.curator.framework;
+import org.apache.curator.utils.Compatibility;
import org.apache.zookeeper.CreateMode;
public class SafeIsTtlMode
@@ -34,7 +35,7 @@ public boolean isTtl(CreateMode mode)
public static boolean isTtl(CreateMode mode)
{
- return !CuratorFrameworkFactory.isZK34() && Internal.instance.isTtl(mode);
+ return !Compatibility.isZK34() && Internal.instance.isTtl(mode);
}
private SafeIsTtlMode()
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
index b58084f00a..1487d6b4d9 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
@@ -176,7 +176,14 @@ public T forPath(String path, byte[] data) throws Exception
}
String fixedPath = client.fixForNamespace(path);
- transaction.add(Op.create(fixedPath, data, acling.getAclList(path), createMode, ttl), OperationType.CREATE, path);
+ if ( client.isZk34CompatibilityMode() )
+ {
+ transaction.add(Op.create(fixedPath, data, acling.getAclList(path), createMode), OperationType.CREATE, path);
+ }
+ else
+ {
+ transaction.add(Op.create(fixedPath, data, acling.getAclList(path), createMode, ttl), OperationType.CREATE, path);
+ }
return context;
}
};
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorMultiTransactionImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorMultiTransactionImpl.java
index bdab158aa4..90579343a6 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorMultiTransactionImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorMultiTransactionImpl.java
@@ -35,6 +35,7 @@
import org.apache.curator.framework.schema.Schema;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.OpResult;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.proto.CreateRequest;
@@ -135,7 +136,22 @@ public List forOperations(List operations)
if ( (curatorOp.get().getType() == ZooDefs.OpCode.create) || (curatorOp.get().getType() == ZooDefs.OpCode.createContainer) )
{
CreateRequest createRequest = (CreateRequest)curatorOp.get().toRequestRecord();
- CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags(), CreateMode.PERSISTENT);
+ CreateMode createMode;
+ if ( client.isZk34CompatibilityMode() )
+ {
+ try
+ {
+ createMode = CreateMode.fromFlag(createRequest.getFlags());
+ }
+ catch ( KeeperException.BadArgumentsException dummy )
+ {
+ createMode = CreateMode.PERSISTENT;
+ }
+ }
+ else
+ {
+ createMode = CreateMode.fromFlag(createRequest.getFlags(), CreateMode.PERSISTENT);
+ }
schema.validateCreate(createMode, createRequest.getPath(), createRequest.getData(), createRequest.getAcl());
}
else if ( (curatorOp.get().getType() == ZooDefs.OpCode.delete) || (curatorOp.get().getType() == ZooDefs.OpCode.deleteContainer) )
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
index 56c2250c69..251baa98e2 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
@@ -23,6 +23,7 @@
import com.google.common.base.Preconditions;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.listen.ListenerContainer;
+import org.apache.curator.utils.Compatibility;
import org.apache.curator.utils.ThreadUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -306,10 +307,7 @@ private void checkSessionExpiration()
log.warn(String.format("Session timeout has elapsed while SUSPENDED. Injecting a session expiration. Elapsed ms: %d. Adjusted session timeout ms: %d", elapsedMs, useSessionTimeoutMs));
try
{
- // LOL - this method was proposed by me (JZ) in 2013 for totally unrelated reasons
- // it got added to ZK 3.5 and now does exactly what we need
- // https://issues.apache.org/jira/browse/ZOOKEEPER-1730
- client.getZookeeperClient().getZooKeeper().getTestable().injectSessionExpiration();
+ Compatibility.injectSessionExpiration(client.getZookeeperClient().getZooKeeper());
}
catch ( Exception e )
{
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCleanState.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCleanState.java
index 9d90616a92..7a61eea96e 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCleanState.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCleanState.java
@@ -21,6 +21,7 @@
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.test.WatchersDebug;
import org.apache.curator.utils.CloseableUtils;
+import org.apache.curator.utils.Compatibility;
import org.apache.zookeeper.ZooKeeper;
import java.util.concurrent.Callable;
@@ -33,6 +34,12 @@ public static void closeAndTestClean(CuratorFramework client)
return;
}
+ if ( Compatibility.isZK34() )
+ {
+ CloseableUtils.closeQuietly(client);
+ return;
+ }
+
try
{
CuratorFrameworkImpl internalClient = (CuratorFrameworkImpl)client;
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCreateReturningStat.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCreateReturningStat.java
index 4e9e78c196..bef143f3cc 100755
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCreateReturningStat.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCreateReturningStat.java
@@ -18,25 +18,24 @@
*/
package org.apache.curator.framework.imps;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicReference;
-
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.BackgroundCallback;
import org.apache.curator.framework.api.CuratorEvent;
import org.apache.curator.framework.api.CuratorEventType;
-import org.apache.curator.framework.api.ExistsBuilder;
-import org.apache.curator.framework.api.PathAndBytesable;
import org.apache.curator.retry.RetryOneTime;
-import org.apache.curator.test.BaseClassForTests;
+import org.apache.curator.test.CuratorTestBase;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Zk35MethodInterceptor;
import org.apache.curator.utils.CloseableUtils;
import org.apache.zookeeper.data.Stat;
import org.testng.Assert;
import org.testng.annotations.Test;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
-public class TestCreateReturningStat extends BaseClassForTests
+@Test(groups = Zk35MethodInterceptor.zk35Group)
+public class TestCreateReturningStat extends CuratorTestBase
{
private CuratorFramework createClient()
{
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestEnabledSessionExpiredState.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestEnabledSessionExpiredState.java
index f96592a6b1..63fd36e3ac 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestEnabledSessionExpiredState.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestEnabledSessionExpiredState.java
@@ -25,8 +25,8 @@
import org.apache.curator.framework.state.ConnectionStateListener;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
-import org.apache.curator.test.KillSession;
-import org.apache.curator.test.Timing;
+import org.apache.curator.test.KillSession2;
+import org.apache.curator.test.Timing2;
import org.apache.curator.utils.CloseableUtils;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
@@ -41,7 +41,7 @@
public class TestEnabledSessionExpiredState extends BaseClassForTests
{
- private final Timing timing = new Timing();
+ private final Timing2 timing = new Timing2();
private CuratorFramework client;
private BlockingQueue states;
@@ -127,7 +127,7 @@ public void testKillSession() throws Exception
{
Assert.assertEquals(states.poll(timing.milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.CONNECTED);
- KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
Assert.assertEquals(states.poll(timing.forSessionSleep().milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.LOST);
Assert.assertEquals(states.poll(timing.milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.RECONNECTED);
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 5d0c5ed8f2..70ae2eac8b 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
@@ -31,6 +31,7 @@
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Timing2;
import org.apache.curator.utils.CloseableUtils;
import org.apache.curator.utils.EnsurePath;
import org.apache.curator.utils.ZKPaths;
@@ -261,7 +262,7 @@ public void process(WatchedEvent event)
client.getChildren().usingWatcher(watcher).forPath("/base");
client.create().forPath("/base/child");
- String path = new Timing().takeFromQueue(queue);
+ String path = new Timing2().takeFromQueue(queue);
Assert.assertEquals(path, "/base");
}
finally
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
index 8fee2d30a2..42e9afaf36 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
@@ -33,9 +33,9 @@
import org.apache.curator.retry.RetryNTimes;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
-import org.apache.curator.test.KillSession;
+import org.apache.curator.test.KillSession2;
import org.apache.curator.test.TestingServer;
-import org.apache.curator.test.Timing;
+import org.apache.curator.test.Timing2;
import org.apache.curator.utils.CloseableUtils;
import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.CreateMode;
@@ -57,7 +57,7 @@
public class TestFrameworkEdges extends BaseClassForTests
{
- private final Timing timing = new Timing();
+ private final Timing2 timing = new Timing2();
@Test
public void testCreateContainersForBadConnect() throws Exception
@@ -391,7 +391,7 @@ public void process(WatchedEvent event)
}
};
client.checkExists().usingWatcher(watcher).forPath("/sessionTest");
- KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
Assert.assertNotNull(client.checkExists().forPath("/sessionTest"));
Assert.assertTrue(sessionDied.get());
}
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
index ef2faede27..567d71d85a 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -27,11 +27,13 @@
import org.apache.curator.framework.api.CuratorEvent;
import org.apache.curator.framework.api.CuratorEventType;
import org.apache.curator.retry.ExponentialBackoffRetry;
-import org.apache.curator.test.BaseClassForTests;
+import org.apache.curator.test.CuratorTestBase;
import org.apache.curator.test.InstanceSpec;
import org.apache.curator.test.TestingCluster;
import org.apache.curator.test.TestingZooKeeperServer;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Timing2;
+import org.apache.curator.test.Zk35MethodInterceptor;
import org.apache.curator.utils.CloseableUtils;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -56,9 +58,10 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
-public class TestReconfiguration extends BaseClassForTests
+@Test(groups = Zk35MethodInterceptor.zk35Group)
+public class TestReconfiguration extends CuratorTestBase
{
- private final Timing timing = new Timing();
+ private final Timing2 timing = new Timing2();
private TestingCluster cluster;
private EnsembleProvider ensembleProvider;
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 4ac68d382a..66f5703d1f 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
@@ -30,8 +30,9 @@
import org.apache.curator.framework.state.ConnectionStateListener;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryOneTime;
-import org.apache.curator.test.BaseClassForTests;
+import org.apache.curator.test.CuratorTestBase;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Zk35MethodInterceptor;
import org.apache.curator.utils.CloseableUtils;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
@@ -44,7 +45,8 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
-public class TestRemoveWatches extends BaseClassForTests
+@Test(groups = Zk35MethodInterceptor.zk35Group)
+public class TestRemoveWatches extends CuratorTestBase
{
private AtomicReference registerConnectionStateListener(CuratorFramework client)
{
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTtlNodes.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTtlNodes.java
index c544474cda..297399db9f 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTtlNodes.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTtlNodes.java
@@ -24,7 +24,9 @@
import org.apache.curator.framework.api.CuratorEvent;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
+import org.apache.curator.test.CuratorTestBase;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Zk35MethodInterceptor;
import org.apache.zookeeper.CreateMode;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
@@ -32,7 +34,8 @@
import org.testng.annotations.Test;
import java.util.concurrent.CountDownLatch;
-public class TestTtlNodes extends BaseClassForTests
+@Test(groups = Zk35MethodInterceptor.zk35Group)
+public class TestTtlNodes extends CuratorTestBase
{
@BeforeMethod
@Override
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 9c405a2d8c..d3ad66fa98 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
@@ -25,8 +25,10 @@
import org.apache.curator.framework.api.CuratorEvent;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
+import org.apache.curator.test.CuratorTestBase;
import org.apache.curator.test.Timing;
import org.apache.curator.test.WatchersDebug;
+import org.apache.curator.test.Zk35MethodInterceptor;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -36,7 +38,8 @@
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
-public class TestWatcherRemovalManager extends BaseClassForTests
+@Test(groups = Zk35MethodInterceptor.zk35Group)
+public class TestWatcherRemovalManager extends CuratorTestBase
{
@Test
public void testSameWatcherDifferentPaths1Triggered() throws Exception
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
index 7b3a07e117..c50474daca 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
@@ -25,6 +25,7 @@
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Timing2;
import org.apache.curator.utils.CloseableUtils;
import org.apache.zookeeper.KeeperException;
import org.testng.Assert;
@@ -41,7 +42,7 @@
public abstract class TestEventOrdering extends BaseClassForTests
{
- private final Timing timing = new Timing();
+ private final Timing2 timing = new Timing2();
private final long start = System.currentTimeMillis();
private static final int THREAD_QTY = 100;
private static final int ITERATIONS = 100;
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestNodeCache.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestNodeCache.java
index d6d495a8a3..52c76adda2 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestNodeCache.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestNodeCache.java
@@ -20,12 +20,12 @@
import org.apache.curator.framework.imps.TestCleanState;
import org.apache.curator.test.BaseClassForTests;
+import org.apache.curator.test.KillSession2;
import org.apache.curator.utils.CloseableUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.UnhandledErrorListener;
import org.apache.curator.retry.RetryOneTime;
-import org.apache.curator.test.KillSession;
import org.apache.curator.test.Timing;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -194,7 +194,7 @@ public void nodeChanged() throws Exception
}
);
- KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
Thread.sleep(timing.multiple(1.5).session());
Assert.assertEquals(cache.getCurrentData().getData(), "start".getBytes());
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 a09c878ceb..f24b84667d 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
@@ -29,7 +29,7 @@
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.test.ExecuteCalledWatchingExecutorService;
-import org.apache.curator.test.KillSession;
+import org.apache.curator.test.KillSession2;
import org.apache.curator.test.TestingServer;
import org.apache.curator.test.Timing;
import org.apache.curator.utils.CloseableUtils;
@@ -715,7 +715,7 @@ else if ( event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED )
client.create().withMode(CreateMode.EPHEMERAL).forPath("/test/me", "data".getBytes());
Assert.assertTrue(timing.awaitLatch(childAddedLatch));
- KillSession.kill(client.getZookeeperClient().getZooKeeper());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
Assert.assertTrue(timing.awaitLatch(lostLatch));
Assert.assertTrue(timing.awaitLatch(reconnectedLatch));
Assert.assertTrue(timing.awaitLatch(removedLatch));
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
index c9c22dd35e..1e203b703e 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
@@ -21,9 +21,9 @@
import com.google.common.collect.ImmutableSet;
import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.test.KillServerSession;
import org.apache.curator.framework.api.UnhandledErrorListener;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type;
+import org.apache.curator.test.KillSession2;
import org.apache.curator.utils.CloseableUtils;
import org.apache.zookeeper.CreateMode;
import org.testng.Assert;
@@ -423,7 +423,7 @@ public void testKilledSession() throws Exception
client.create().withMode(CreateMode.EPHEMERAL).forPath("/test/me", "data".getBytes());
assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/me");
- KillServerSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
assertEvent(TreeCacheEvent.Type.CONNECTION_SUSPENDED);
assertEvent(TreeCacheEvent.Type.CONNECTION_LOST);
assertEvent(TreeCacheEvent.Type.CONNECTION_RECONNECTED);
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
index 991e6fc4bd..93c955b093 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
@@ -35,6 +35,7 @@
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.test.TestingServer;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Timing2;
import org.apache.curator.utils.CloseableUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -136,7 +137,7 @@ public void notLeader()
@Test
public void testErrorPolicies() throws Exception
{
- Timing timing = new Timing();
+ Timing2 timing = new Timing2();
LeaderLatch latch = null;
CuratorFramework client = CuratorFrameworkFactory.builder()
.connectString(server.getConnectString())
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java
index 60619d05b8..79fcdb30c0 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java
@@ -30,9 +30,10 @@
import org.apache.curator.framework.state.StandardConnectionStateErrorPolicy;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
-import org.apache.curator.test.KillSession;
+import org.apache.curator.test.KillSession2;
import org.apache.curator.test.TestingServer;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Timing2;
import org.apache.curator.utils.CloseableUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -56,7 +57,7 @@ public class TestLeaderSelector extends BaseClassForTests
@Test
public void testErrorPolicies() throws Exception
{
- Timing timing = new Timing();
+ Timing2 timing = new Timing2();
LeaderSelector selector = null;
CuratorFramework client = CuratorFrameworkFactory
.builder()
@@ -147,7 +148,7 @@ public void takeLeadership(CuratorFramework client) throws Exception
@Test
public void testLeaderNodeDeleteOnInterrupt() throws Exception
{
- Timing timing = new Timing();
+ Timing2 timing = new Timing2();
LeaderSelector selector = null;
CuratorFramework client = null;
try
@@ -486,7 +487,7 @@ public void takeLeadership(CuratorFramework client) throws Exception
Assert.assertTrue(timing.acquireSemaphore(semaphore, 1));
- KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
Assert.assertTrue(timing.awaitLatch(interruptedLatch));
timing.sleepABit();
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java
index 68daeb7851..cf82c570c9 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java
@@ -26,7 +26,7 @@
import org.apache.curator.framework.schema.Schema;
import org.apache.curator.framework.schema.SchemaSet;
import org.apache.curator.retry.RetryOneTime;
-import org.apache.curator.test.KillSession;
+import org.apache.curator.test.KillSession2;
import org.apache.curator.utils.CloseableUtils;
import org.apache.zookeeper.CreateMode;
import org.testng.Assert;
@@ -38,7 +38,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import java.util.regex.Pattern;
public class TestInterProcessMutex extends TestInterProcessMutexBase
{
@@ -173,7 +172,7 @@ public String createsTheLock(CuratorFramework client, String path, byte[] lockNo
Assert.assertTrue(lock.isAcquiredInThisProcess());
// Kill the session, check that lock node still exists
- KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
Assert.assertNotNull(client.checkExists().forPath(LOCK_PATH));
// Release the lock and verify that the actual lock node created no longer exists
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutexBase.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutexBase.java
index febf4997f6..43ded2ee15 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutexBase.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutexBase.java
@@ -27,9 +27,10 @@
import org.apache.curator.framework.state.ConnectionStateListener;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.test.BaseClassForTests;
-import org.apache.curator.test.KillSession;
+import org.apache.curator.test.KillSession2;
import org.apache.curator.test.TestingServer;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Timing2;
import org.apache.curator.utils.CloseableUtils;
import org.apache.curator.utils.ZKPaths;
import org.testng.Assert;
@@ -149,7 +150,7 @@ public Object call() throws Exception
@Test
public void testKilledSession() throws Exception
{
- final Timing timing = new Timing();
+ final Timing2 timing = new Timing2();
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new ExponentialBackoffRetry(100, 3));
client.start();
@@ -191,7 +192,7 @@ public Object call() throws Exception
);
Assert.assertTrue(timing.acquireSemaphore(semaphore, 1));
- KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
Assert.assertTrue(timing.forSessionSleep().acquireSemaphore(semaphore, 1));
}
finally
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
index 7d52b5812c..0ce61d5482 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
@@ -31,8 +31,8 @@
import org.apache.curator.framework.state.ConnectionStateListener;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
-import org.apache.curator.test.KillSession;
-import org.apache.curator.test.Timing;
+import org.apache.curator.test.KillSession2;
+import org.apache.curator.test.Timing2;
import org.apache.curator.utils.CloseableUtils;
import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.CreateMode;
@@ -69,7 +69,7 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
private final Collection curatorInstances = Lists.newArrayList();
private final Collection createdNodes = Lists.newArrayList();
- private final Timing timing = new Timing();
+ private final Timing2 timing = new Timing2();
@AfterMethod
@Override
@@ -329,7 +329,7 @@ public void testDeletesNodeWhenSessionDisconnects() throws Exception
observer.checkExists().usingWatcher(deletedTrigger).forPath(node.getActualPath());
node.debugCreateNodeLatch = new CountDownLatch(1);
- KillSession.kill(curator.getZookeeperClient().getZooKeeper());
+ KillSession2.kill(curator.getZookeeperClient().getZooKeeper());
// Make sure the node got deleted
assertTrue(deletedTrigger.firedWithin(timing.forSessionSleep().seconds(), TimeUnit.SECONDS));
@@ -359,7 +359,7 @@ public void testRecreatesNodeWhenSessionReconnects() throws Exception
observer.checkExists().usingWatcher(deletedTrigger).forPath(node.getActualPath());
node.debugCreateNodeLatch = new CountDownLatch(1);
- KillSession.kill(curator.getZookeeperClient().getZooKeeper());
+ KillSession2.kill(curator.getZookeeperClient().getZooKeeper());
// Make sure the node got deleted...
assertTrue(deletedTrigger.firedWithin(timing.forSessionSleep().seconds(), TimeUnit.SECONDS));
@@ -400,7 +400,7 @@ public void testRecreatesNodeWhenSessionReconnectsMultipleTimes() throws Excepti
node.debugCreateNodeLatch = new CountDownLatch(1);
// Kill the session, thus cleaning up the node...
- KillSession.kill(curator.getZookeeperClient().getZooKeeper());
+ KillSession2.kill(curator.getZookeeperClient().getZooKeeper());
// Make sure the node ended up getting deleted...
assertTrue(deletionTrigger.firedWithin(timing.multiple(1.5).forSessionSleep().seconds(), TimeUnit.SECONDS));
@@ -443,7 +443,7 @@ public void testRecreatesNodeWhenEphemeralOwnerSessionExpires() throws Exception
Trigger deletedTrigger = Trigger.deletedOrSetData();
observer.checkExists().usingWatcher(deletedTrigger).forPath(node.getActualPath());
- KillSession.kill(nodeCreator.getZookeeperClient().getZooKeeper());
+ KillSession2.kill(nodeCreator.getZookeeperClient().getZooKeeper());
// Make sure the node got deleted...
assertTrue(deletedTrigger.firedWithin(timing.forWaiting().seconds(), TimeUnit.SECONDS));
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentNode.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentNode.java
index 07d9083509..b848fe4407 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentNode.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentNode.java
@@ -23,6 +23,7 @@
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Timing2;
import org.apache.curator.utils.CloseableUtils;
import org.apache.zookeeper.CreateMode;
import org.testng.Assert;
@@ -67,7 +68,7 @@ public void testBasic() throws Exception
{
final byte[] TEST_DATA = "hey".getBytes();
- Timing timing = new Timing();
+ Timing2 timing = new Timing2();
PersistentNode pen = null;
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
try
diff --git a/curator-test-zk34/pom.xml b/curator-test-zk34/pom.xml
index fe5e21630e..8d2f07393e 100644
--- a/curator-test-zk34/pom.xml
+++ b/curator-test-zk34/pom.xml
@@ -56,6 +56,31 @@
test
+
+ org.apache.curator
+ curator-framework
+
+
+ org.apache.zookeeper
+ zookeeper
+
+
+ test
+
+
+
+ org.apache.curator
+ curator-framework
+
+
+ org.apache.zookeeper
+ zookeeper
+
+
+ test-jar
+ test
+
+
org.apache.curatorcurator-recipes
@@ -122,6 +147,25 @@
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+
+
+ add-compatibility
+
+ add-test-source
+
+ generate-test-sources
+
+
+ ../curator-test/src/compatibility/java
+
+
+
+
+
\ No newline at end of file
diff --git a/curator-test-zk34/src/test/java/org/apache/curator/framework/imps/TestCleanState.java b/curator-test-zk34/src/test/java/org/apache/curator/framework/imps/TestCleanState.java
deleted file mode 100644
index 9efeb90877..0000000000
--- a/curator-test-zk34/src/test/java/org/apache/curator/framework/imps/TestCleanState.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.apache.curator.framework.imps;
-
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.utils.CloseableUtils;
-import java.util.concurrent.Callable;
-
-public class TestCleanState
-{
- public static void closeAndTestClean(CuratorFramework client)
- {
- CloseableUtils.closeQuietly(client);
- }
-
- public static void test(CuratorFramework client, Callable proc) throws Exception
- {
- try
- {
- proc.call();
- }
- finally
- {
- CloseableUtils.closeQuietly(client);
- }
- }
-}
diff --git a/curator-test-zk34/src/test/java/org/apache/curator/test/Compatibility.java b/curator-test-zk34/src/test/java/org/apache/curator/test/Compatibility.java
new file mode 100644
index 0000000000..77ddf2c12c
--- /dev/null
+++ b/curator-test-zk34/src/test/java/org/apache/curator/test/Compatibility.java
@@ -0,0 +1,35 @@
+/**
+ * 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.curator.utils.InjectSessionExpiration;
+import org.apache.zookeeper.ZooKeeper;
+
+class Compatibility
+{
+ static boolean isZK34()
+ {
+ return true;
+ }
+
+ static void injectSessionExpiration(ZooKeeper zooKeeper)
+ {
+ InjectSessionExpiration.injectSessionExpiration(zooKeeper);
+ }
+}
diff --git a/curator-test/pom.xml b/curator-test/pom.xml
index fb28d53485..0ffe023080 100644
--- a/curator-test/pom.xml
+++ b/curator-test/pom.xml
@@ -95,6 +95,25 @@
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+
+
+ add-compatibility
+
+ add-source
+
+ generate-sources
+
+
+ src/compatibility/java
+
+
+
+
+
diff --git a/curator-test/src/compatibility/java/org/apache/curator/test/CuratorTestBase.java b/curator-test/src/compatibility/java/org/apache/curator/test/CuratorTestBase.java
new file mode 100644
index 0000000000..efa94a36b1
--- /dev/null
+++ b/curator-test/src/compatibility/java/org/apache/curator/test/CuratorTestBase.java
@@ -0,0 +1,27 @@
+/**
+ * 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.testng.annotations.Listeners;
+
+@Listeners(Zk35MethodInterceptor.class)
+public class CuratorTestBase extends BaseClassForTests
+{
+ protected final Timing2 timing = new Timing2();
+}
diff --git a/curator-test/src/main/java/org/apache/curator/test/KillSession.java b/curator-test/src/compatibility/java/org/apache/curator/test/KillSession2.java
similarity index 55%
rename from curator-test/src/main/java/org/apache/curator/test/KillSession.java
rename to curator-test/src/compatibility/java/org/apache/curator/test/KillSession2.java
index ce2b7e605f..52ab168c7f 100644
--- a/curator-test/src/main/java/org/apache/curator/test/KillSession.java
+++ b/curator-test/src/compatibility/java/org/apache/curator/test/KillSession2.java
@@ -25,43 +25,15 @@
* Utility to simulate a ZK session dying.
*
*/
-public class KillSession
+public class KillSession2
{
/**
* Kill the given ZK session
*
* @param client the client to kill
- * @since 3.0.0
*/
public static void kill(ZooKeeper client)
{
- client.getTestable().injectSessionExpiration();
- }
-
- /**
- * Kill the given ZK session
- *
- * @param client the client to kill
- * @param connectString server connection string
- * @throws Exception errors
- * @deprecated use {@link #kill(ZooKeeper)} instead
- */
- public static void kill(ZooKeeper client, String connectString) throws Exception
- {
- kill(client);
- }
-
- /**
- * Kill the given ZK session
- *
- * @param client the client to kill
- * @param connectString server connection string
- * @param maxMs max time ms to wait for kill
- * @throws Exception errors
- * @deprecated use {@link #kill(ZooKeeper)} instead
- */
- public static void kill(ZooKeeper client, String connectString, int maxMs) throws Exception
- {
- kill(client);
+ Compatibility.injectSessionExpiration(client);
}
}
diff --git a/curator-test/src/compatibility/java/org/apache/curator/test/Timing2.java b/curator-test/src/compatibility/java/org/apache/curator/test/Timing2.java
new file mode 100644
index 0000000000..02b71c4442
--- /dev/null
+++ b/curator-test/src/compatibility/java/org/apache/curator/test/Timing2.java
@@ -0,0 +1,299 @@
+/**
+ * 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 java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * Utility to get various testing times.
+ *
+ * Copied from the old Timing class which is now deprecated. Needed this to support ZK 3.4 compatibility
+ */
+public class Timing2
+{
+ private final long value;
+ private final TimeUnit unit;
+ private final int waitingMultiple;
+
+ private static final int DEFAULT_SECONDS = 10;
+ private static final int DEFAULT_WAITING_MULTIPLE = 5;
+ private static final double SESSION_MULTIPLE = 1.5;
+ private static final double SESSION_SLEEP_MULTIPLE = SESSION_MULTIPLE * 1.75; // has to be at least session + 2/3 of a session to account for missed heartbeat then session expiration
+
+ /**
+ * Use the default base time
+ */
+ public Timing2()
+ {
+ this(Integer.getInteger("timing-multiple", 1), getWaitingMultiple());
+ }
+
+ /**
+ * Use a multiple of the default base time
+ *
+ * @param multiple the multiple
+ */
+ public Timing2(double multiple)
+ {
+ this((long)(DEFAULT_SECONDS * multiple), TimeUnit.SECONDS, getWaitingMultiple());
+ }
+
+ /**
+ * Use a multiple of the default base time
+ *
+ * @param multiple the multiple
+ * @param waitingMultiple multiple of main timing to use when waiting
+ */
+ public Timing2(double multiple, int waitingMultiple)
+ {
+ this((long)(DEFAULT_SECONDS * multiple), TimeUnit.SECONDS, waitingMultiple);
+ }
+
+ /**
+ * @param value base time
+ * @param unit base time unit
+ */
+ public Timing2(long value, TimeUnit unit)
+ {
+ this(value, unit, getWaitingMultiple());
+ }
+
+ /**
+ * @param value base time
+ * @param unit base time unit
+ * @param waitingMultiple multiple of main timing to use when waiting
+ */
+ public Timing2(long value, TimeUnit unit, int waitingMultiple)
+ {
+ this.value = value;
+ this.unit = unit;
+ this.waitingMultiple = waitingMultiple;
+ }
+
+ /**
+ * Return the base time in milliseconds
+ *
+ * @return time ms
+ */
+ public int milliseconds()
+ {
+ return (int)TimeUnit.MILLISECONDS.convert(value, unit);
+ }
+
+ /**
+ * Return the base time in seconds
+ *
+ * @return time secs
+ */
+ public int seconds()
+ {
+ return (int)value;
+ }
+
+ /**
+ * Wait on the given latch
+ *
+ * @param latch latch to wait on
+ * @return result of {@link java.util.concurrent.CountDownLatch#await(long, java.util.concurrent.TimeUnit)}
+ */
+ public boolean awaitLatch(CountDownLatch latch)
+ {
+ Timing2 m = forWaiting();
+ try
+ {
+ return latch.await(m.value, m.unit);
+ }
+ catch ( InterruptedException e )
+ {
+ Thread.currentThread().interrupt();
+ }
+ return false;
+ }
+
+ /**
+ * Try to take an item from the given queue
+ *
+ * @param queue queue
+ * @return item
+ * @throws Exception interrupted or timed out
+ */
+ public T takeFromQueue(BlockingQueue queue) throws Exception
+ {
+ Timing2 m = forWaiting();
+ try
+ {
+ T value = queue.poll(m.value, m.unit);
+ if ( value == null )
+ {
+ throw new TimeoutException("Timed out trying to take from queue");
+ }
+ return value;
+ }
+ catch ( InterruptedException e )
+ {
+ Thread.currentThread().interrupt();
+ throw e;
+ }
+ }
+
+ /**
+ * Wait on the given semaphore
+ *
+ * @param semaphore the semaphore
+ * @return result of {@link java.util.concurrent.Semaphore#tryAcquire()}
+ */
+ public boolean acquireSemaphore(Semaphore semaphore)
+ {
+ Timing2 m = forWaiting();
+ try
+ {
+ return semaphore.tryAcquire(m.value, m.unit);
+ }
+ catch ( InterruptedException e )
+ {
+ Thread.currentThread().interrupt();
+ }
+ return false;
+ }
+
+ /**
+ * Wait on the given semaphore
+ *
+ * @param semaphore the semaphore
+ * @param n number of permits to acquire
+ * @return result of {@link java.util.concurrent.Semaphore#tryAcquire(int, long, java.util.concurrent.TimeUnit)}
+ */
+ public boolean acquireSemaphore(Semaphore semaphore, int n)
+ {
+ Timing2 m = forWaiting();
+ try
+ {
+ return semaphore.tryAcquire(n, m.value, m.unit);
+ }
+ catch ( InterruptedException e )
+ {
+ Thread.currentThread().interrupt();
+ }
+ return false;
+ }
+
+ /**
+ * Return a new timing that is a multiple of the this timing
+ *
+ * @param n the multiple
+ * @return this timing times the multiple
+ */
+ public Timing2 multiple(double n)
+ {
+ return new Timing2((int)(value * n), unit);
+ }
+
+ /**
+ * Return a new timing that is a multiple of the this timing
+ *
+ * @param n the multiple
+ * @param waitingMultiple new waitingMultiple
+ * @return this timing times the multiple
+ */
+ public Timing2 multiple(double n, int waitingMultiple)
+ {
+ return new Timing2((int)(value * n), unit, waitingMultiple);
+ }
+
+ /**
+ * Return a new timing with the standard multiple for waiting on latches, etc.
+ *
+ * @return this timing multiplied
+ */
+ @SuppressWarnings("PointlessArithmeticExpression")
+ public Timing2 forWaiting()
+ {
+ return multiple(waitingMultiple);
+ }
+
+ /**
+ * Return a new timing with a multiple that ensures a ZK session timeout
+ *
+ * @return this timing multiplied
+ */
+ public Timing2 forSessionSleep()
+ {
+ return multiple(SESSION_SLEEP_MULTIPLE, 1);
+ }
+
+ /**
+ * Return a new timing with a multiple for sleeping a smaller amount of time
+ *
+ * @return this timing multiplied
+ */
+ public Timing2 forSleepingABit()
+ {
+ return multiple(.25);
+ }
+
+ /**
+ * Sleep for a small amount of time
+ *
+ * @throws InterruptedException if interrupted
+ */
+ public void sleepABit() throws InterruptedException
+ {
+ forSleepingABit().sleep();
+ }
+
+ /**
+ * Sleep for a the full amount of time
+ *
+ * @throws InterruptedException if interrupted
+ */
+ public void sleep() throws InterruptedException
+ {
+ unit.sleep(value);
+ }
+
+ /**
+ * Return the value to use for ZK session timeout
+ *
+ * @return session timeout
+ */
+ public int session()
+ {
+ return multiple(SESSION_MULTIPLE).milliseconds();
+ }
+
+ /**
+ * Return the value to use for ZK connection timeout
+ *
+ * @return connection timeout
+ */
+ public int connection()
+ {
+ return milliseconds();
+ }
+
+ private static Integer getWaitingMultiple()
+ {
+ return Integer.getInteger("timing-waiting-multiple", DEFAULT_WAITING_MULTIPLE);
+ }
+}
diff --git a/curator-test/src/compatibility/java/org/apache/curator/test/Zk35MethodInterceptor.java b/curator-test/src/compatibility/java/org/apache/curator/test/Zk35MethodInterceptor.java
new file mode 100644
index 0000000000..290910c1f8
--- /dev/null
+++ b/curator-test/src/compatibility/java/org/apache/curator/test/Zk35MethodInterceptor.java
@@ -0,0 +1,55 @@
+/**
+ * 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.testng.IMethodInstance;
+import org.testng.IMethodInterceptor;
+import org.testng.ITestContext;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class Zk35MethodInterceptor implements IMethodInterceptor
+{
+ public static final String zk35Group = "zk35";
+
+ @Override
+ public List intercept(List methods, ITestContext context)
+ {
+ if ( !Compatibility.isZK34() )
+ {
+ return methods;
+ }
+
+ List filteredMethods = new ArrayList<>();
+ for ( IMethodInstance method : methods )
+ {
+ if ( !isInGroup(method.getMethod().getGroups()) )
+ {
+ filteredMethods.add(method);
+ }
+ }
+ return filteredMethods;
+ }
+
+ private boolean isInGroup(String[] groups)
+ {
+ return (groups != null) && Arrays.asList(groups).contains(zk35Group);
+ }
+}
diff --git a/curator-test/src/main/java/org/apache/curator/test/Compatibility.java b/curator-test/src/main/java/org/apache/curator/test/Compatibility.java
new file mode 100644
index 0000000000..87eb33ef43
--- /dev/null
+++ b/curator-test/src/main/java/org/apache/curator/test/Compatibility.java
@@ -0,0 +1,34 @@
+/**
+ * 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;
+
+class Compatibility
+{
+ static boolean isZK34()
+ {
+ return false;
+ }
+
+ static void injectSessionExpiration(ZooKeeper zooKeeper)
+ {
+ zooKeeper.getTestable().injectSessionExpiration();
+ }
+}
diff --git a/curator-test/src/main/java/org/apache/curator/test/KillServerSession.java b/curator-test/src/main/java/org/apache/curator/test/KillServerSession.java
deleted file mode 100644
index ab5fa32040..0000000000
--- a/curator-test/src/main/java/org/apache/curator/test/KillServerSession.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * 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.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooKeeper;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-/**
- *
- * Utility to simulate a ZK session dying. See: ZooKeeper FAQ
- *
- *
- *
- * In the case of testing we want to cause a problem, so to explicitly expire a session an
- * application connects to ZooKeeper, saves the session id and password, creates another
- * ZooKeeper handle with that id and password, and then closes the new handle. Since both
- * handles reference the same session, the close on second handle will invalidate the session
- * causing a SESSION_EXPIRED on the first handle.
- *
- */
-public class KillServerSession
-{
- /**
- * Kill the given ZK session
- *
- * @param client the client to kill
- * @param connectString server connection string
- * @throws Exception errors
- */
- public static void kill(ZooKeeper client, String connectString) throws Exception
- {
- kill(client, connectString, new Timing().forWaiting().milliseconds());
- }
-
- /**
- * Kill the given ZK session
- *
- * @param client the client to kill
- * @param connectString server connection string
- * @param maxMs max time ms to wait for kill
- * @throws Exception errors
- */
- public static void kill(ZooKeeper client, String connectString, int maxMs) throws Exception
- {
- long startTicks = System.currentTimeMillis();
-
- final CountDownLatch sessionLostLatch = new CountDownLatch(1);
- Watcher sessionLostWatch = new Watcher()
- {
- @Override
- public void process(WatchedEvent event)
- {
- sessionLostLatch.countDown();
- }
- };
- client.exists("/___CURATOR_KILL_SESSION___" + System.nanoTime(), sessionLostWatch);
-
- final CountDownLatch connectionLatch = new CountDownLatch(1);
- Watcher connectionWatcher = new Watcher()
- {
- @Override
- public void process(WatchedEvent event)
- {
- if ( event.getState() == Event.KeeperState.SyncConnected )
- {
- connectionLatch.countDown();
- }
- }
- };
- ZooKeeper zk = new ZooKeeper(connectString, maxMs, connectionWatcher, client.getSessionId(), client.getSessionPasswd());
- try
- {
- if ( !connectionLatch.await(maxMs, TimeUnit.MILLISECONDS) )
- {
- throw new Exception("KillSession could not establish duplicate session");
- }
- try
- {
- zk.close();
- }
- finally
- {
- zk = null;
- }
-
- while ( client.getState().isConnected() && !sessionLostLatch.await(100, TimeUnit.MILLISECONDS) )
- {
- long elapsed = System.currentTimeMillis() - startTicks;
- if ( elapsed > maxMs )
- {
- throw new Exception("KillSession timed out waiting for session to expire");
- }
- }
- }
- finally
- {
- if ( zk != null )
- {
- zk.close();
- }
- }
- }
-}
diff --git a/curator-test/src/main/java/org/apache/curator/test/Timing.java b/curator-test/src/main/java/org/apache/curator/test/Timing.java
index 242aa50175..f29b1c5e18 100644
--- a/curator-test/src/main/java/org/apache/curator/test/Timing.java
+++ b/curator-test/src/main/java/org/apache/curator/test/Timing.java
@@ -19,11 +19,9 @@
package org.apache.curator.test;
-import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
/**
* Utility to get various testing times
@@ -36,8 +34,7 @@ public class Timing
private static final int DEFAULT_SECONDS = 10;
private static final int DEFAULT_WAITING_MULTIPLE = 5;
- private static final double SESSION_MULTIPLE = 1.5;
- private static final double SESSION_SLEEP_MULTIPLE = SESSION_MULTIPLE * 1.75; // has to be at least session + 2/3 of a session to account for missed heartbeat then session expiration
+ private static final double SESSION_MULTIPLE = .25;
/**
* Use the default base time
@@ -129,32 +126,6 @@ public boolean awaitLatch(CountDownLatch latch)
return false;
}
- /**
- * Try to take an item from the given queue
- *
- * @param queue queue
- * @return item
- * @throws Exception interrupted or timed out
- */
- public T takeFromQueue(BlockingQueue queue) throws Exception
- {
- Timing m = forWaiting();
- try
- {
- T value = queue.poll(m.value, m.unit);
- if ( value == null )
- {
- throw new TimeoutException("Timed out trying to take from queue");
- }
- return value;
- }
- catch ( InterruptedException e )
- {
- Thread.currentThread().interrupt();
- throw e;
- }
- }
-
/**
* Wait on the given semaphore
*
@@ -207,18 +178,6 @@ public Timing multiple(double n)
return new Timing((int)(value * n), unit);
}
- /**
- * Return a new timing that is a multiple of the this timing
- *
- * @param n the multiple
- * @param waitingMultiple new waitingMultiple
- * @return this timing times the multiple
- */
- public Timing multiple(double n, int waitingMultiple)
- {
- return new Timing((int)(value * n), unit, waitingMultiple);
- }
-
/**
* Return a new timing with the standard multiple for waiting on latches, etc.
*
@@ -230,26 +189,6 @@ public Timing forWaiting()
return multiple(waitingMultiple);
}
- /**
- * Return a new timing with a multiple that ensures a ZK session timeout
- *
- * @return this timing multiplied
- */
- public Timing forSessionSleep()
- {
- return multiple(SESSION_SLEEP_MULTIPLE, 1);
- }
-
- /**
- * Return a new timing with a multiple for sleeping a smaller amount of time
- *
- * @return this timing multiplied
- */
- public Timing forSleepingABit()
- {
- return multiple(.25);
- }
-
/**
* Sleep for a small amount of time
*
@@ -257,17 +196,7 @@ public Timing forSleepingABit()
*/
public void sleepABit() throws InterruptedException
{
- forSleepingABit().sleep();
- }
-
- /**
- * Sleep for a the full amount of time
- *
- * @throws InterruptedException if interrupted
- */
- public void sleep() throws InterruptedException
- {
- unit.sleep(value);
+ unit.sleep(value / 4);
}
/**
diff --git a/curator-x-async/src/test/java/org/apache/curator/x/async/CompletableBaseClassForTests.java b/curator-x-async/src/test/java/org/apache/curator/x/async/CompletableBaseClassForTests.java
index 4a964b108c..28c9f11335 100644
--- a/curator-x-async/src/test/java/org/apache/curator/x/async/CompletableBaseClassForTests.java
+++ b/curator-x-async/src/test/java/org/apache/curator/x/async/CompletableBaseClassForTests.java
@@ -21,6 +21,7 @@
import com.google.common.base.Throwables;
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.test.Timing;
+import org.apache.curator.test.Timing2;
import org.testng.Assert;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
@@ -30,7 +31,7 @@
public abstract class CompletableBaseClassForTests extends BaseClassForTests
{
- protected static final Timing timing = new Timing();
+ protected static final Timing2 timing = new Timing2();
protected void complete(CompletionStage stage)
{
diff --git a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/details/TestServiceDiscovery.java b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/details/TestServiceDiscovery.java
index 47c74d5313..a2cf157b7b 100644
--- a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/details/TestServiceDiscovery.java
+++ b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/details/TestServiceDiscovery.java
@@ -25,7 +25,7 @@
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
-import org.apache.curator.test.KillSession;
+import org.apache.curator.test.KillSession2;
import org.apache.curator.test.Timing;
import org.apache.curator.utils.CloseableUtils;
import org.apache.curator.x.discovery.ServiceDiscovery;
@@ -79,7 +79,7 @@ protected void internalRegisterService(ServiceInstance service) throws E
timing.acquireSemaphore(semaphore, 2);
Assert.assertEquals(discovery.queryForInstances("test").size(), 2);
- KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
server.stop();
server.restart();
@@ -121,7 +121,7 @@ protected void internalRegisterService(ServiceInstance service) throws E
timing.acquireSemaphore(semaphore);
Assert.assertEquals(discovery.queryForInstances("test").size(), 1);
- KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
server.stop();
server.restart();
@@ -154,7 +154,7 @@ public void testCrashedInstance() throws Exception
Assert.assertEquals(discovery.queryForInstances("test").size(), 1);
- KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
+ KillSession2.kill(client.getZookeeperClient().getZooKeeper());
Thread.sleep(timing.multiple(1.5).session());
Assert.assertEquals(discovery.queryForInstances("test").size(), 1);
diff --git a/pom.xml b/pom.xml
index b816d3646a..5a8045ea1d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,6 +80,7 @@
2.4.31.7.62.8
+ 3.0.0
@@ -867,6 +868,12 @@
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ ${build-helper-maven-plugin-version}
+