You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2017/07/21 19:27:17 UTC

[02/18] curator git commit: 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 majo

http://git-wip-us.apache.org/repos/asf/curator/blob/58bc969f/curator-test/src/main/java/org/apache/curator/test/KillSession.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/KillSession.java b/curator-test/src/main/java/org/apache/curator/test/KillSession.java
deleted file mode 100644
index ce2b7e6..0000000
--- a/curator-test/src/main/java/org/apache/curator/test/KillSession.java
+++ /dev/null
@@ -1,67 +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.ZooKeeper;
-
-/**
- * <p>
- *     Utility to simulate a ZK session dying.
- * </p>
- */
-public class KillSession
-{
-    /**
-     * 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);
-    }
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/58bc969f/curator-test/src/main/java/org/apache/curator/test/Timing.java
----------------------------------------------------------------------
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 242aa50..f29b1c5 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
@@ -130,32 +127,6 @@ public class Timing
     }
 
     /**
-     * Try to take an item from the given queue
-     *
-     * @param queue queue
-     * @return item
-     * @throws Exception interrupted or timed out
-     */
-    public <T> T takeFromQueue(BlockingQueue<T> 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
      *
      * @param semaphore the semaphore
@@ -208,18 +179,6 @@ public class Timing
     }
 
     /**
-     * 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.
      *
      * @return this timing multiplied
@@ -231,43 +190,13 @@ public class Timing
     }
 
     /**
-     * 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
      *
      * @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);
+        unit.sleep(value / 4);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/curator/blob/58bc969f/curator-x-async/src/test/java/org/apache/curator/x/async/CompletableBaseClassForTests.java
----------------------------------------------------------------------
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 4a964b1..28c9f11 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 @@ package org.apache.curator.x.async;
 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 @@ import java.util.function.BiConsumer;
 
 public abstract class CompletableBaseClassForTests extends BaseClassForTests
 {
-    protected static final Timing timing = new Timing();
+    protected static final Timing2 timing = new Timing2();
 
     protected <T, U> void complete(CompletionStage<T> stage)
     {

http://git-wip-us.apache.org/repos/asf/curator/blob/58bc969f/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/details/TestServiceDiscovery.java
----------------------------------------------------------------------
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 47c74d5..a2cf157 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.CuratorFramework;
 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 @@ public class TestServiceDiscovery extends BaseClassForTests
             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 @@ public class TestServiceDiscovery extends BaseClassForTests
             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 class TestServiceDiscovery extends BaseClassForTests
 
             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);

http://git-wip-us.apache.org/repos/asf/curator/blob/58bc969f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b816d36..5a8045e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,6 +80,7 @@
         <maven-shade-plugin-version>2.4.3</maven-shade-plugin-version>
         <slf4j-version>1.7.6</slf4j-version>
         <clirr-maven-plugin-version>2.8</clirr-maven-plugin-version>
+        <build-helper-maven-plugin-version>3.0.0</build-helper-maven-plugin-version>
 
         <!-- OSGi Properties -->
         <osgi.export.package />
@@ -867,6 +868,12 @@
                     </execution>
                 </executions>
             </plugin>
+
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>${build-helper-maven-plugin-version}</version>
+            </plugin>
         </plugins>
     </build>
 </project>