curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dragonsinth <...@git.apache.org>
Subject [GitHub] curator pull request: CURATOR-33 recursive TreeCache recipe
Date Thu, 07 Aug 2014 02:02:19 GMT
Github user dragonsinth commented on a diff in the pull request:

    https://github.com/apache/curator/pull/17#discussion_r15915313
  
    --- Diff: curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
---
    @@ -0,0 +1,335 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.curator.framework.recipes.cache;
    +
    +import com.google.common.collect.ImmutableSet;
    +import org.apache.curator.framework.CuratorFramework;
    +import org.apache.curator.test.KillSession;
    +import org.apache.curator.utils.CloseableUtils;
    +import org.apache.zookeeper.CreateMode;
    +import org.testng.Assert;
    +import org.testng.annotations.Test;
    +import java.util.concurrent.Semaphore;
    +
    +public class TestTreeCache extends BaseTestTreeCache
    +{
    +    @Test
    +    public void testStartup() throws Exception
    +    {
    +        client.create().forPath("/test");
    +        client.create().forPath("/test/1", "one".getBytes());
    +        client.create().forPath("/test/2", "two".getBytes());
    +        client.create().forPath("/test/3", "three".getBytes());
    +        client.create().forPath("/test/2/sub", "two-sub".getBytes());
    +
    +        cache.start();
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/1", "one".getBytes());
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/2", "two".getBytes());
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/3", "three".getBytes());
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/2/sub", "two-sub".getBytes());
    +        assertEvent(TreeCacheEvent.Type.INITIALIZED);
    +        assertNoMoreEvents();
    +
    +        Assert.assertEquals(cache.getCurrentChildren("/test").keySet(), ImmutableSet.of("1",
"2", "3"));
    +        Assert.assertEquals(cache.getCurrentChildren("/test/1").keySet(), ImmutableSet.of());
    +        Assert.assertEquals(cache.getCurrentChildren("/test/2").keySet(), ImmutableSet.of("sub"));
    +        Assert.assertNull(cache.getCurrentChildren("/test/non_exist"));
    +    }
    +
    +    @Test
    +    public void testStartEmpty() throws Exception
    +    {
    +        cache.start();
    +        assertEvent(TreeCacheEvent.Type.INITIALIZED);
    +
    +        client.create().forPath("/test");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
    +        assertNoMoreEvents();
    +    }
    +
    +    @Test
    +    public void testAsyncInitialPopulation() throws Exception
    +    {
    +        client.create().forPath("/test");
    +        client.create().forPath("/test/one", "hey there".getBytes());
    +
    +        cache.start();
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/one");
    +        assertEvent(TreeCacheEvent.Type.INITIALIZED);
    +        assertNoMoreEvents();
    +    }
    +
    +    @Test
    +    public void testFromRoot() throws Exception
    +    {
    +        client.create().forPath("/test");
    +        client.create().forPath("/test/one", "hey there".getBytes());
    +
    +        cache = new TreeCache(client, "/", true);
    +        cache.start();
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/one");
    +        assertEvent(TreeCacheEvent.Type.INITIALIZED);
    +        assertNoMoreEvents();
    +
    +        Assert.assertTrue(cache.getCurrentChildren("/").keySet().contains("test"));
    +        Assert.assertEquals(cache.getCurrentChildren("/test").keySet(), ImmutableSet.of("one"));
    +        Assert.assertEquals(cache.getCurrentChildren("/test/one").keySet(), ImmutableSet.of());
    +        Assert.assertEquals(new String(cache.getCurrentData("/test/one").getData()),
"hey there");
    +    }
    +
    +    @Test
    +    public void testWithNamespace() throws Exception
    +    {
    +        client.create().forPath("/outer");
    +        client.create().forPath("/outer/foo");
    +        client.create().forPath("/outer/test");
    +        client.create().forPath("/outer/test/one", "hey there".getBytes());
    +
    +        cache = new TreeCache(client.usingNamespace("outer"), "/test", true);
    +        cache.start();
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/one");
    +        assertEvent(TreeCacheEvent.Type.INITIALIZED);
    +        assertNoMoreEvents();
    +
    +        Assert.assertEquals(cache.getCurrentChildren("/test").keySet(), ImmutableSet.of("one"));
    +        Assert.assertEquals(cache.getCurrentChildren("/test/one").keySet(), ImmutableSet.of());
    +        Assert.assertEquals(new String(cache.getCurrentData("/test/one").getData()),
"hey there");
    +    }
    +
    +    @Test
    +    public void testWithNamespaceAtRoot() throws Exception
    +    {
    +        client.create().forPath("/outer");
    +        client.create().forPath("/outer/foo");
    +        client.create().forPath("/outer/test");
    +        client.create().forPath("/outer/test/one", "hey there".getBytes());
    +
    +        cache = new TreeCache(client.usingNamespace("outer"), "/", true);
    +        cache.start();
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/foo");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/one");
    +        assertEvent(TreeCacheEvent.Type.INITIALIZED);
    +        assertNoMoreEvents();
    +        Assert.assertEquals(cache.getCurrentChildren("/").keySet(), ImmutableSet.of("foo",
"test"));
    +        Assert.assertEquals(cache.getCurrentChildren("/foo").keySet(), ImmutableSet.of());
    +        Assert.assertEquals(cache.getCurrentChildren("/test").keySet(), ImmutableSet.of("one"));
    +        Assert.assertEquals(cache.getCurrentChildren("/test/one").keySet(), ImmutableSet.of());
    +        Assert.assertEquals(new String(cache.getCurrentData("/test/one").getData()),
"hey there");
    +    }
    +
    +    @Test
    +    public void testSyncInitialPopulation() throws Exception
    +    {
    +        cache.start();
    +        assertEvent(TreeCacheEvent.Type.INITIALIZED);
    +
    +        client.create().forPath("/test");
    +        client.create().forPath("/test/one", "hey there".getBytes());
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/one");
    +        assertNoMoreEvents();
    +    }
    +
    +    @Test
    +    public void testChildrenInitialized() throws Exception
    +    {
    +        client.create().forPath("/test", "".getBytes());
    +        client.create().forPath("/test/1", "1".getBytes());
    +        client.create().forPath("/test/2", "2".getBytes());
    +        client.create().forPath("/test/3", "3".getBytes());
    +
    +        cache.start();
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/1");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/2");
    +        assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/3");
    +        assertEvent(TreeCacheEvent.Type.INITIALIZED);
    +        assertNoMoreEvents();
    +    }
    +
    +    @Test
    +    public void testUpdateWhenNotCachingData() throws Exception
    +    {
    +        client.create().forPath("/test");
    +
    +        cache = new TreeCache(client, "/test", false);
    --- End diff --
    
    Fixed to never initialize client for less confusion.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message