curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [1/6] curator git commit: If zookeeper is down when discovery is started, it fails to register when the zookeeper comes up for the first time. This commit has fix for this issue
Date Mon, 12 Jan 2015 20:31:26 GMT
Repository: curator
Updated Branches:
  refs/heads/master 40b2cd802 -> 7a97315dd


If zookeeper is down when discovery is started, it fails to register
when the zookeeper comes up for the first time. This commit has fix for
this issue

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

Branch: refs/heads/master
Commit: 4190147dbedb350ce1d42eb1ace86de0d0c9aef9
Parents: ef2ca57
Author: gopi <gopi.kori@gmail.com>
Authored: Sun Dec 28 19:23:26 2014 +0530
Committer: gopi <gopi.kori@gmail.com>
Committed: Sun Dec 28 19:23:26 2014 +0530

----------------------------------------------------------------------
 .../discovery/details/ServiceDiscoveryImpl.java |  8 +++--
 .../x/discovery/TestServiceDiscovery.java       | 35 ++++++++++++++++++++
 2 files changed, 41 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/4190147d/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java
b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java
index ad6ce89..5f001a1 100644
--- a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java
+++ b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java
@@ -69,7 +69,7 @@ public class ServiceDiscoveryImpl<T> implements ServiceDiscovery<T>
         @Override
         public void stateChanged(CuratorFramework client, ConnectionState newState)
         {
-            if ( newState == ConnectionState.RECONNECTED )
+            if ( newState == ConnectionState.RECONNECTED || newState == ConnectionState.CONNECTED
)
             {
                 try
                 {
@@ -109,8 +109,12 @@ public class ServiceDiscoveryImpl<T> implements ServiceDiscovery<T>
     @Override
     public void start() throws Exception
     {
+        try {
+    	    reRegisterServices();
+        } catch (Exception ex) {
+            log.error("Could not register instances", ex);
+        }
         client.getConnectionStateListenable().addListener(connectionStateListener);
-        reRegisterServices();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/curator/blob/4190147d/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceDiscovery.java
b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceDiscovery.java
index 73de7fc..a9a8896 100644
--- a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceDiscovery.java
+++ b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceDiscovery.java
@@ -24,6 +24,7 @@ import org.apache.curator.test.BaseClassForTests;
 import org.apache.curator.utils.CloseableUtils;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.RetryNTimes;
 import org.apache.curator.retry.RetryOneTime;
 import org.apache.curator.test.KillSession;
 import org.apache.curator.test.Timing;
@@ -263,4 +264,38 @@ public class TestServiceDiscovery extends BaseClassForTests
             }
         }
     }
+    
+    @Test
+    public void         testNoServerOnStart() throws Exception
+    {
+        server.stop();
+        List<Closeable>     closeables = Lists.newArrayList();
+        try
+        {
+            CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
new RetryNTimes(0,1000));
+            closeables.add(client);
+            client.start();
+            
+            ServiceInstance<String>     instance = ServiceInstance.<String>builder().payload("thing").name("test").port(10064).build();
+            ServiceDiscovery<String>    discovery = ServiceDiscoveryBuilder.builder(String.class).basePath("/test").client(client).thisInstance(instance).build();
+            closeables.add(discovery);
+            discovery.start();
+
+            server.restart();
+            Assert.assertEquals(discovery.queryForNames(), Arrays.asList("test"));
+
+            List<ServiceInstance<String>> list = Lists.newArrayList();
+            list.add(instance);
+            Assert.assertEquals(discovery.queryForInstances("test"), list);
+        }
+        finally
+        {
+            Collections.reverse(closeables);
+            for ( Closeable c : closeables )
+            {
+                CloseableUtils.closeQuietly(c);
+            }
+        }
+    }
+
 }


Mime
View raw message