curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [3/3] git commit: Added getAllInstances() to ServiceProvider
Date Thu, 06 Feb 2014 19:30:51 GMT
Added getAllInstances() to ServiceProvider


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

Branch: refs/heads/master
Commit: 1ecaef6570650b58fac97e3d03bf2cf8a541502b
Parents: eb67ad6
Author: randgalt <randgalt@apache.org>
Authored: Thu Feb 6 14:30:11 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Thu Feb 6 14:30:11 2014 -0500

----------------------------------------------------------------------
 .../apache/curator/x/discovery/ServiceProvider.java   | 10 ++++++++++
 .../x/discovery/details/ServiceProviderImpl.java      | 14 ++++++++++++++
 .../apache/curator/x/discovery/TestServiceCache.java  | 12 +++++++++++-
 3 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/1ecaef65/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceProvider.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceProvider.java
b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceProvider.java
index e8fcdcf..d606649 100644
--- a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceProvider.java
+++ b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceProvider.java
@@ -21,6 +21,7 @@ package org.apache.curator.x.discovery;
 
 import org.apache.curator.x.discovery.details.InstanceProvider;
 import java.io.Closeable;
+import java.util.Collection;
 
 /**
  * The main API for Discovery. This class is essentially a facade over a {@link ProviderStrategy}
@@ -45,6 +46,15 @@ public interface ServiceProvider<T> extends Closeable
     public ServiceInstance<T> getInstance() throws Exception;
 
     /**
+     * Return the current available set of instances <b>IMPORTANT: </b> users
+     * should not hold on to the instance returned. They should always get a fresh list.
+     *
+     * @return all known instances
+     * @throws Exception any errors
+     */
+    public Collection<ServiceInstance<T>> getAllInstances() throws Exception;
+
+    /**
      * Take note of an error connecting to the given instance. The instance will potentially
      * be marked as "down" depending on the {@link DownInstancePolicy}.
      *

http://git-wip-us.apache.org/repos/asf/curator/blob/1ecaef65/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceProviderImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceProviderImpl.java
b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceProviderImpl.java
index 40dcf59..5c63836 100644
--- a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceProviderImpl.java
+++ b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceProviderImpl.java
@@ -27,6 +27,7 @@ import org.apache.curator.x.discovery.ServiceInstance;
 import org.apache.curator.x.discovery.ServiceProvider;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.ThreadFactory;
 
@@ -78,6 +79,19 @@ public class ServiceProviderImpl<T> implements ServiceProvider<T>
     }
 
     /**
+     * Return the current available set of instances <b>IMPORTANT: </b> users
+     * should not hold on to the instance returned. They should always get a fresh list.
+     *
+     * @return all known instances
+     * @throws Exception any errors
+     */
+    @Override
+    public Collection<ServiceInstance<T>> getAllInstances() throws Exception
+    {
+        return instanceProvider.getInstances();
+    }
+
+    /**
      * Return an instance for a single use. <b>IMPORTANT: </b> users
      * should not hold on to the instance returned. They should always get a fresh instance.
      *

http://git-wip-us.apache.org/repos/asf/curator/blob/1ecaef65/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceCache.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceCache.java
b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceCache.java
index 3f4346b..d1dc3bd 100644
--- a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceCache.java
+++ b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceCache.java
@@ -19,6 +19,7 @@
 package org.apache.curator.x.discovery;
 
 import com.google.common.collect.Lists;
+import org.apache.curator.test.Timing;
 import org.apache.curator.utils.CloseableUtils;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -29,6 +30,7 @@ import org.apache.curator.x.discovery.details.ServiceCacheListener;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 import java.io.Closeable;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
@@ -101,6 +103,8 @@ public class TestServiceCache
     @Test
     public void     testViaProvider() throws Exception
     {
+        Timing timing = new Timing();
+
         List<Closeable> closeables = Lists.newArrayList();
         TestingServer server = new TestingServer();
         closeables.add(server);
@@ -127,9 +131,15 @@ public class TestServiceCache
             {
                 Assert.assertTrue(count++ < 5);
                 foundInstance = serviceProvider.getInstance();
-                Thread.sleep(1000);
+                timing.sleepABit();
             }
             Assert.assertEquals(foundInstance, instance);
+
+            ServiceInstance<String>     instance2 = ServiceInstance.<String>builder().address("foo").payload("thing").name("test").port(10064).build();
+            discovery.registerService(instance2);
+            timing.sleepABit();
+            Collection<ServiceInstance<String>> allInstances = serviceProvider.getAllInstances();
+            Assert.assertEquals(allInstances.size(), 2);
         }
         finally
         {


Mime
View raw message