You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ca...@apache.org on 2015/04/22 01:06:59 UTC
[02/50] curator git commit: Look for connection errors and merely log
when starting. Also, reset instances on initial connection
Look for connection errors and merely log when starting. Also, reset instances on initial connection
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/94fce2ca
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/94fce2ca
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/94fce2ca
Branch: refs/heads/CURATOR-154
Commit: 94fce2ca94f827cd3d3c793dbf044bff39ef52a7
Parents: 40b2cd8
Author: randgalt <ra...@apache.org>
Authored: Mon Jan 12 15:28:56 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Mon Jan 12 15:28:56 2015 -0500
----------------------------------------------------------------------
.../discovery/details/ServiceDiscoveryImpl.java | 11 +++++--
.../x/discovery/TestServiceDiscovery.java | 33 ++++++++++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/94fce2ca/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 3a92e7a..6472262 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
{
@@ -111,8 +111,15 @@ public class ServiceDiscoveryImpl<T> implements ServiceDiscovery<T>
@Override
public void start() throws Exception
{
+ try
+ {
+ reRegisterServices();
+ }
+ catch ( KeeperException e )
+ {
+ log.error("Could not register instances - will try again later", e);
+ }
client.getConnectionStateListenable().addListener(connectionStateListener);
- reRegisterServices();
}
@Override
http://git-wip-us.apache.org/repos/asf/curator/blob/94fce2ca/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 0465599..6eb9ebb 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
@@ -264,4 +264,37 @@ 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 RetryOneTime(1));
+ 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);
+ }
+ }
+ }
}