Return-Path: X-Original-To: apmail-curator-commits-archive@minotaur.apache.org Delivered-To: apmail-curator-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 09BCE17D18 for ; Mon, 12 Jan 2015 20:31:10 +0000 (UTC) Received: (qmail 50059 invoked by uid 500); 12 Jan 2015 20:31:11 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 50022 invoked by uid 500); 12 Jan 2015 20:31:11 -0000 Mailing-List: contact commits-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list commits@curator.apache.org Received: (qmail 49976 invoked by uid 99); 12 Jan 2015 20:31:11 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Jan 2015 20:31:11 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 18BAFA02570; Mon, 12 Jan 2015 20:31:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: randgalt@apache.org To: commits@curator.apache.org Date: Mon, 12 Jan 2015 20:31:11 -0000 Message-Id: <6c6fe48489414d15af98b7fce38ac61e@git.apache.org> X-Mailer: ASF-Git Admin Mailer 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 Repository: curator Updated Branches: refs/heads/CURATOR-175 [created] 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/CURATOR-175 Commit: 4190147dbedb350ce1d42eb1ace86de0d0c9aef9 Parents: ef2ca57 Author: gopi Authored: Sun Dec 28 19:23:26 2014 +0530 Committer: gopi 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 implements ServiceDiscovery @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 implements ServiceDiscovery @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 closeables = Lists.newArrayList(); + try + { + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryNTimes(0,1000)); + closeables.add(client); + client.start(); + + ServiceInstance instance = ServiceInstance.builder().payload("thing").name("test").port(10064).build(); + ServiceDiscovery 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> list = Lists.newArrayList(); + list.add(instance); + Assert.assertEquals(discovery.queryForInstances("test"), list); + } + finally + { + Collections.reverse(closeables); + for ( Closeable c : closeables ) + { + CloseableUtils.closeQuietly(c); + } + } + } + }