curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [1/3] git commit: CURATOR-124 - PathChildrenCache StartMode doc
Date Wed, 23 Jul 2014 22:33:50 GMT
Repository: curator
Updated Branches:
  refs/heads/master 5f5ee9665 -> 27a0dc86a


CURATOR-124 - PathChildrenCache StartMode doc

Updated PathChildrenCache.StartMode.NORMAL JavaDoc to
accurately depict the cache startup behavior.

Added test testChildrenInitializedNormal to assert
the startup behavior indicated in the JavaDoc.


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

Branch: refs/heads/master
Commit: e2eed55985b1d5efbc74ca04afcdac28c8400fe6
Parents: 5df92bf
Author: Patrick Peralta <pperalta@gopivotal.com>
Authored: Tue Jul 22 13:23:43 2014 -0400
Committer: Patrick Peralta <pperalta@gopivotal.com>
Committed: Tue Jul 22 13:23:43 2014 -0400

----------------------------------------------------------------------
 .../recipes/cache/PathChildrenCache.java        | 15 ++---
 .../recipes/cache/TestPathChildrenCache.java    | 59 ++++++++++++++++++--
 2 files changed, 62 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/e2eed559/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
index ad433d8..18e008b 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
@@ -253,20 +253,21 @@ public class PathChildrenCache implements Closeable
     public enum StartMode
     {
         /**
-         * cache will _not_ be primed. i.e. it will start empty and you will receive
-         * events for all nodes added, etc.
+         * The cache will be primed (in the background) with initial values.
+         * Events for existing and new nodes will be posted.
          */
         NORMAL,
 
         /**
-         * {@link PathChildrenCache#rebuild()} will be called before this method returns
in
-         * order to get an initial view of the node.
+         * The cache will be primed (in the foreground) with initial values.
+         * {@link PathChildrenCache#rebuild()} will be called before this
+         * method returns in order to get an initial view of the node.
          */
         BUILD_INITIAL_CACHE,
 
         /**
          * After cache is primed with initial values (in the background) a
-         * {@link PathChildrenCacheEvent.Type#INITIALIZED} will be posted
+         * {@link PathChildrenCacheEvent.Type#INITIALIZED} will be posted.
          */
         POST_INITIALIZED_EVENT
     }
@@ -767,9 +768,9 @@ public class PathChildrenCache implements Closeable
                             //so just ignore these events
                             if ( state.get() != State.CLOSED )
                             {
-                                handleException(e);    
+                                handleException(e);
                             }
-                            
+
                             Thread.currentThread().interrupt();
                         }
                         catch ( Exception e )

http://git-wip-us.apache.org/repos/asf/curator/blob/e2eed559/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
index 653a8b1..60f2e88 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java
@@ -172,6 +172,55 @@ public class TestPathChildrenCache extends BaseClassForTests
     }
 
     @Test
+    public void testChildrenInitializedNormal() throws Exception
+    {
+        Timing timing = new Timing();
+        PathChildrenCache cache = null;
+        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
timing.session(), timing.connection(), new RetryOneTime(1));
+        try
+        {
+            client.start();
+            client.create().forPath("/test");
+
+            cache = new PathChildrenCache(client, "/test", true);
+
+            final CountDownLatch addedLatch = new CountDownLatch(3);
+            cache.getListenable().addListener
+                    (
+                            new PathChildrenCacheListener()
+                            {
+                                @Override
+                                public void childEvent(CuratorFramework client, PathChildrenCacheEvent
event) throws Exception
+                                {
+                                    Assert.assertNotEquals(event.getType(), PathChildrenCacheEvent.Type.INITIALIZED);
+                                    if ( event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED
)
+                                    {
+                                        addedLatch.countDown();
+                                    }
+                                }
+                            }
+                    );
+
+            client.create().forPath("/test/1", "1".getBytes());
+            client.create().forPath("/test/2", "2".getBytes());
+            client.create().forPath("/test/3", "3".getBytes());
+
+            cache.start(PathChildrenCache.StartMode.NORMAL);
+
+            Assert.assertTrue(timing.awaitLatch(addedLatch));
+            Assert.assertEquals(cache.getCurrentData().size(), 3);
+            Assert.assertEquals(cache.getCurrentData().get(0).getData(), "1".getBytes());
+            Assert.assertEquals(cache.getCurrentData().get(1).getData(), "2".getBytes());
+            Assert.assertEquals(cache.getCurrentData().get(2).getData(), "3".getBytes());
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(cache);
+            CloseableUtils.closeQuietly(client);
+        }
+    }
+
+    @Test
     public void testUpdateWhenNotCachingData() throws Exception
     {
         Timing timing = new Timing();
@@ -841,7 +890,7 @@ public class TestPathChildrenCache extends BaseClassForTests
         }
 
     }
-    
+
     /**
      * Tests the case where there's an outstanding operation being executed when the cache
is
      * shut down. See CURATOR-121, this was causing misleading warning messages to be logged.
@@ -874,19 +923,19 @@ public class TestPathChildrenCache extends BaseClassForTests
                     Thread.sleep(5000);
                 }
             });
-            
+
             Thread.sleep(1000);
 
             cache.close();
-            
+
             latch.await(5, TimeUnit.SECONDS);
-            
+
             Assert.assertTrue(latch.getCount() == 1, "Unexpected exception occurred");
         } finally
         {
             CloseableUtils.closeQuietly(client);
         }
-    }    
+    }
 
     public static class ExecuteCalledWatchingExecutorService extends DelegatingExecutorService
     {


Mime
View raw message