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 2014/07/23 00:46:42 UTC

[1/3] git commit: Test case that shows the problem

Repository: curator
Updated Branches:
  refs/heads/master 5df92bf88 -> 5f5ee9665


Test case that shows the problem


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/feb13e1c
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/feb13e1c
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/feb13e1c

Branch: refs/heads/master
Commit: feb13e1c16de7078dfc1310d9403441d1b2dae9e
Parents: 5df92bf
Author: randgalt <ra...@apache.org>
Authored: Tue Jul 22 16:05:19 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue Jul 22 16:05:19 2014 -0500

----------------------------------------------------------------------
 .../curator/framework/imps/TestReadOnly.java    | 165 +++++++++++++------
 1 file changed, 115 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/feb13e1c/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReadOnly.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReadOnly.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReadOnly.java
index 537617c..d6d63f8 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReadOnly.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReadOnly.java
@@ -16,93 +16,158 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.imps;
 
-import org.apache.curator.utils.CloseableUtils;
+import com.google.common.collect.Queues;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.framework.state.ConnectionState;
 import org.apache.curator.framework.state.ConnectionStateListener;
 import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.retry.RetryNTimes;
+import org.apache.curator.retry.RetryOneTime;
 import org.apache.curator.test.InstanceSpec;
 import org.apache.curator.test.TestingCluster;
 import org.apache.curator.test.Timing;
+import org.apache.curator.utils.CloseableUtils;
 import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import java.util.Iterator;
+import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 public class TestReadOnly
 {
-    @Test
-    public void     testReadOnly() throws Exception
+    @BeforeMethod
+    public void setup()
     {
         System.setProperty("readonlymode.enabled", "true");
+    }
+
+    @AfterMethod
+    public void tearDown()
+    {
+        System.setProperty("readonlymode.enabled", "false");
+    }
+
+    @Test
+    public void testConnectionStateNewClient() throws Exception
+    {
+        Timing timing = new Timing();
+        TestingCluster cluster = new TestingCluster(3);
+        CuratorFramework client = null;
         try
         {
-            Timing              timing = new Timing();
+            cluster.start();
+
+            client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(100));
+            client.start();
+            client.checkExists().forPath("/");
+            client.close();
+            client = null;
 
-            CuratorFramework    client = null;
-            TestingCluster      cluster = new TestingCluster(2);
-            try
+            System.out.println("killing 2 instances");
+            Iterator<InstanceSpec> iterator = cluster.getInstances().iterator();
+            for ( int i = 0; i < 2; ++i )
             {
-                cluster.start();
-
-                client = CuratorFrameworkFactory.builder()
-                    .connectString(cluster.getConnectString())
-                    .canBeReadOnly(true)
-                    .connectionTimeoutMs(timing.connection())
-                    .sessionTimeoutMs(timing.session())
-                    .retryPolicy(new ExponentialBackoffRetry(100, 3))
-                    .build();
-                client.start();
-
-                client.create().forPath("/test");
-
-                final CountDownLatch        readOnlyLatch = new CountDownLatch(1);
-                final CountDownLatch        reconnectedLatch = new CountDownLatch(1);
-                ConnectionStateListener     listener = new ConnectionStateListener()
+                cluster.killServer(iterator.next());
+            }
+
+            System.out.println("reconnecting client");
+            client = CuratorFrameworkFactory.builder()
+                .connectString(cluster.getConnectString())
+                .sessionTimeoutMs(timing.session())
+                .connectionTimeoutMs(timing.connection())
+                .retryPolicy(new RetryNTimes(3, timing.milliseconds()))
+                .canBeReadOnly(true)
+                .build();
+
+            final BlockingQueue<ConnectionState> states = Queues.newLinkedBlockingQueue();
+            client.getConnectionStateListenable().addListener
+            (
+                new ConnectionStateListener()
                 {
                     @Override
                     public void stateChanged(CuratorFramework client, ConnectionState newState)
                     {
-                        if ( newState == ConnectionState.READ_ONLY )
-                        {
-                            readOnlyLatch.countDown();
-                        }
-                        else if ( newState == ConnectionState.RECONNECTED )
-                        {
-                            reconnectedLatch.countDown();
-                        }
+                        states.add(newState);
                     }
-                };
-                client.getConnectionStateListenable().addListener(listener);
+                }
+            );
+            client.start();
+
+            System.out.println("making api call");
+            client.checkExists().forPath("/");
+
+            ConnectionState state = states.poll(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS);
+            Assert.assertEquals(state, ConnectionState.READ_ONLY);
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(client);
+            CloseableUtils.closeQuietly(cluster);
+        }
+    }
+
+    @Test
+    public void testReadOnly() throws Exception
+    {
+        Timing timing = new Timing();
+
+        CuratorFramework client = null;
+        TestingCluster cluster = new TestingCluster(2);
+        try
+        {
+            cluster.start();
+
+            client = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).canBeReadOnly(true).connectionTimeoutMs(timing.connection()).sessionTimeoutMs(timing.session()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
+            client.start();
 
-                InstanceSpec                ourInstance = cluster.findConnectionInstance(client.getZookeeperClient().getZooKeeper());
-                Iterator<InstanceSpec>      iterator = cluster.getInstances().iterator();
-                InstanceSpec                killInstance = iterator.next();
-                if ( killInstance.equals(ourInstance) )
+            client.create().forPath("/test");
+
+            final CountDownLatch readOnlyLatch = new CountDownLatch(1);
+            final CountDownLatch reconnectedLatch = new CountDownLatch(1);
+            ConnectionStateListener listener = new ConnectionStateListener()
+            {
+                @Override
+                public void stateChanged(CuratorFramework client, ConnectionState newState)
                 {
-                    killInstance = iterator.next(); // kill the instance we're not connected to
+                    if ( newState == ConnectionState.READ_ONLY )
+                    {
+                        readOnlyLatch.countDown();
+                    }
+                    else if ( newState == ConnectionState.RECONNECTED )
+                    {
+                        reconnectedLatch.countDown();
+                    }
                 }
-                cluster.killServer(killInstance);
-
-                Assert.assertEquals(reconnectedLatch.getCount(), 1);
-                Assert.assertTrue(timing.awaitLatch(readOnlyLatch));
+            };
+            client.getConnectionStateListenable().addListener(listener);
 
-                Assert.assertEquals(reconnectedLatch.getCount(), 1);
-                cluster.restartServer(killInstance);
-                Assert.assertTrue(timing.awaitLatch(reconnectedLatch));
-            }
-            finally
+            InstanceSpec ourInstance = cluster.findConnectionInstance(client.getZookeeperClient().getZooKeeper());
+            Iterator<InstanceSpec> iterator = cluster.getInstances().iterator();
+            InstanceSpec killInstance = iterator.next();
+            if ( killInstance.equals(ourInstance) )
             {
-                CloseableUtils.closeQuietly(client);
-                CloseableUtils.closeQuietly(cluster);
+                killInstance = iterator.next(); // kill the instance we're not connected to
             }
+            cluster.killServer(killInstance);
+
+            Assert.assertEquals(reconnectedLatch.getCount(), 1);
+            Assert.assertTrue(timing.awaitLatch(readOnlyLatch));
+
+            Assert.assertEquals(reconnectedLatch.getCount(), 1);
+            cluster.restartServer(killInstance);
+            Assert.assertTrue(timing.awaitLatch(reconnectedLatch));
         }
         finally
         {
-            System.clearProperty("readonlymode.enabled");
+            CloseableUtils.closeQuietly(client);
+            CloseableUtils.closeQuietly(cluster);
         }
     }
 }


[3/3] git commit: removed printlns

Posted by ra...@apache.org.
removed printlns


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/5f5ee966
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/5f5ee966
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/5f5ee966

Branch: refs/heads/master
Commit: 5f5ee966569064a8d75fd19f32cb7e7a2bd7b0e1
Parents: a86a667
Author: randgalt <ra...@apache.org>
Authored: Tue Jul 22 17:46:19 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue Jul 22 17:46:19 2014 -0500

----------------------------------------------------------------------
 .../test/java/org/apache/curator/framework/imps/TestReadOnly.java | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/5f5ee966/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReadOnly.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReadOnly.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReadOnly.java
index d6d63f8..13ceec6 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReadOnly.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReadOnly.java
@@ -70,14 +70,12 @@ public class TestReadOnly
             client.close();
             client = null;
 
-            System.out.println("killing 2 instances");
             Iterator<InstanceSpec> iterator = cluster.getInstances().iterator();
             for ( int i = 0; i < 2; ++i )
             {
                 cluster.killServer(iterator.next());
             }
 
-            System.out.println("reconnecting client");
             client = CuratorFrameworkFactory.builder()
                 .connectString(cluster.getConnectString())
                 .sessionTimeoutMs(timing.session())
@@ -100,7 +98,6 @@ public class TestReadOnly
             );
             client.start();
 
-            System.out.println("making api call");
             client.checkExists().forPath("/");
 
             ConnectionState state = states.poll(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS);


[2/3] git commit: Fix that causes CONNECT to be sent when the read/write connection is established. It can be argued that CONNECT should never be sent though. Discussing...

Posted by ra...@apache.org.
Fix that causes CONNECT to be sent when the read/write connection is established. It can be argued that CONNECT should never be sent though. Discussing...


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/a86a667b
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/a86a667b
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/a86a667b

Branch: refs/heads/master
Commit: a86a667bb1213fec26fbdb8354bdc01b9fe70396
Parents: feb13e1
Author: randgalt <ra...@apache.org>
Authored: Tue Jul 22 16:07:13 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue Jul 22 16:07:13 2014 -0500

----------------------------------------------------------------------
 .../org/apache/curator/framework/state/ConnectionStateManager.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/a86a667b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
----------------------------------------------------------------------
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 2a0cdd1..67ff13d 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
@@ -180,7 +180,7 @@ public class ConnectionStateManager implements Closeable
         currentConnectionState = newConnectionState;
 
         ConnectionState localState = newConnectionState;
-        boolean isNegativeMessage = ((newConnectionState == ConnectionState.LOST) || (newConnectionState == ConnectionState.SUSPENDED));
+        boolean isNegativeMessage = ((newConnectionState == ConnectionState.LOST) || (newConnectionState == ConnectionState.SUSPENDED) || (newConnectionState == ConnectionState.READ_ONLY));
         if ( !isNegativeMessage && initialConnectMessageSent.compareAndSet(false, true) )
         {
             localState = ConnectionState.CONNECTED;