curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [09/11] curator git commit: Merge branch 'master' into CURATOR-3.0
Date Mon, 18 Jan 2016 21:04:12 GMT
Merge branch 'master' into CURATOR-3.0

Conflicts:
	curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java
	curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionSetDataBuilder.java
	curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
	curator-framework/src/main/java/org/apache/curator/framework/imps/SetDataBuilderImpl.java
	curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java


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

Branch: refs/heads/CURATOR-3.0
Commit: ba38d4c5ea59466c4f1dcda6dadcab9bf3262257
Parents: 9a03ea9 5d485b0
Author: randgalt <randgalt@apache.org>
Authored: Mon Jan 18 15:57:02 2016 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Mon Jan 18 15:57:02 2016 -0500

----------------------------------------------------------------------
 .../framework/api/VersionPathAndBytesable.java  | 25 ++++++++
 .../transaction/TransactionCreateBuilder.java   |  2 +
 .../transaction/TransactionSetDataBuilder.java  |  2 +
 .../framework/imps/CreateBuilderImpl.java       | 10 +--
 .../framework/imps/SetDataBuilderImpl.java      |  2 +-
 .../framework/imps/TestTransactionsOld.java     | 46 +++++++++++++-
 .../recipes/cache/DefaultTreeCacheSelector.java | 37 +++++++++++
 .../framework/recipes/cache/TreeCache.java      | 39 +++++++++---
 .../recipes/cache/TreeCacheSelector.java        | 66 ++++++++++++++++++++
 .../framework/recipes/cache/TestTreeCache.java  | 57 +++++++++++++++--
 10 files changed, 264 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/ba38d4c5/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java
----------------------------------------------------------------------
diff --cc curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java
index cba0cba,f2ac146..d20c834
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java
@@@ -23,10 -24,10 +24,11 @@@ import org.apache.curator.framework.api
  import org.apache.curator.framework.api.CreateModable;
  import org.apache.curator.framework.api.PathAndBytesable;
  
 -public interface TransactionCreateBuilder extends
 -    PathAndBytesable<CuratorTransactionBridge>,
 -    CreateModable<ACLPathAndBytesable<CuratorTransactionBridge>>,
 -    ACLPathAndBytesable<CuratorTransactionBridge>,
 -    ACLCreateModePathAndBytesable<CuratorTransactionBridge>,
 -    Compressible<ACLCreateModePathAndBytesable<CuratorTransactionBridge>>  {
 +public interface TransactionCreateBuilder<T> extends
 +    PathAndBytesable<T>,
 +    CreateModable<ACLPathAndBytesable<T>>,
 +    ACLPathAndBytesable<T>,
++    ACLCreateModePathAndBytesable<T>,
 +    Compressible<ACLPathAndBytesable<T>>
 +{
  }

http://git-wip-us.apache.org/repos/asf/curator/blob/ba38d4c5/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionSetDataBuilder.java
----------------------------------------------------------------------
diff --cc curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionSetDataBuilder.java
index 2d4d255,cc9e01c..84b25bb
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionSetDataBuilder.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionSetDataBuilder.java
@@@ -20,11 -20,13 +20,13 @@@ package org.apache.curator.framework.ap
  
  import org.apache.curator.framework.api.Compressible;
  import org.apache.curator.framework.api.PathAndBytesable;
+ import org.apache.curator.framework.api.VersionPathAndBytesable;
  import org.apache.curator.framework.api.Versionable;
  
 -public interface TransactionSetDataBuilder extends
 -    PathAndBytesable<CuratorTransactionBridge>,
 -    Versionable<PathAndBytesable<CuratorTransactionBridge>>,
 -    VersionPathAndBytesable<CuratorTransactionBridge>,
 -    Compressible<VersionPathAndBytesable<CuratorTransactionBridge>>
 +public interface TransactionSetDataBuilder<T> extends
 +    PathAndBytesable<T>,
 +    Versionable<PathAndBytesable<T>>,
++    VersionPathAndBytesable<T>,
 +    Compressible<PathAndBytesable<T>>
  {
  }

http://git-wip-us.apache.org/repos/asf/curator/blob/ba38d4c5/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
----------------------------------------------------------------------
diff --cc curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
index ada4bae,e11d74f..4d532ff
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
@@@ -101,31 -89,31 +101,31 @@@ class CreateBuilderImpl implements Crea
                  CreateBuilderImpl.this.withMode(mode);
                  return this;
              }
-             
+ 
              @Override
 -            public ACLCreateModePathAndBytesable<CuratorTransactionBridge> compressed()
 +            public ACLPathAndBytesable<T> compressed()
              {
                  CreateBuilderImpl.this.compressed();
                  return this;
              }
-             
+ 
              @Override
 -            public CuratorTransactionBridge forPath(String path) throws Exception
 +            public T forPath(String path) throws Exception
              {
                  return forPath(path, client.getDefaultData());
              }
  
              @Override
 -            public CuratorTransactionBridge forPath(String path, byte[] data) throws Exception
 +            public T forPath(String path, byte[] data) throws Exception
-             {               
+             {
                  if ( compress )
                  {
                      data = client.getCompressionProvider().compress(path, data);
                  }
-                 
+ 
                  String fixedPath = client.fixForNamespace(path);
                  transaction.add(Op.create(fixedPath, data, acling.getAclList(path), createMode),
OperationType.CREATE, path);
 -                return curatorTransaction;
 +                return context;
              }
          };
      }

http://git-wip-us.apache.org/repos/asf/curator/blob/ba38d4c5/curator-framework/src/main/java/org/apache/curator/framework/imps/SetDataBuilderImpl.java
----------------------------------------------------------------------
diff --cc curator-framework/src/main/java/org/apache/curator/framework/imps/SetDataBuilderImpl.java
index 3ea704c,4117930..b150783
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/SetDataBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/SetDataBuilderImpl.java
@@@ -61,10 -64,10 +61,10 @@@ class SetDataBuilderImpl implements Set
                  {
                      data = client.getCompressionProvider().compress(path, data);
                  }
-                 
+ 
                  String      fixedPath = client.fixForNamespace(path);
                  transaction.add(Op.setData(fixedPath, data, version), OperationType.SET_DATA,
path);
 -                return curatorTransaction;
 +                return context;
              }
  
              @Override

http://git-wip-us.apache.org/repos/asf/curator/blob/ba38d4c5/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java
----------------------------------------------------------------------
diff --cc curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java
index f0147d5,0000000..2c42d61
mode 100644,000000..100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java
@@@ -1,141 -1,0 +1,185 @@@
 +/**
 + * 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.imps;
 +
 +import com.google.common.collect.Iterables;
 +import org.apache.curator.framework.CuratorFramework;
 +import org.apache.curator.framework.CuratorFrameworkFactory;
 +import org.apache.curator.framework.api.transaction.CuratorTransactionResult;
 +import org.apache.curator.framework.api.transaction.OperationType;
 +import org.apache.curator.retry.RetryOneTime;
 +import org.apache.curator.test.BaseClassForTests;
 +import org.apache.curator.utils.CloseableUtils;
 +import org.apache.zookeeper.CreateMode;
 +import org.apache.zookeeper.KeeperException;
++import org.apache.zookeeper.ZooDefs;
 +import org.apache.zookeeper.data.Stat;
 +import org.testng.Assert;
 +import org.testng.annotations.Test;
 +import java.util.Collection;
 +
 +@SuppressWarnings("deprecation")
 +public class TestTransactionsOld extends BaseClassForTests
 +{
 +    @Test
 +    public void     testCheckVersion() throws Exception
 +    {
 +        CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(),
new RetryOneTime(1));
 +        try
 +        {
 +            client.start();
 +            client.create().forPath("/foo");
 +            Stat        stat = client.setData().forPath("/foo", "new".getBytes());  // up
the version
 +
 +            try
 +            {
 +                client.inTransaction()
 +                    .check().withVersion(stat.getVersion() + 1).forPath("/foo") // force
a bad version
 +                .and()
 +                    .create().forPath("/bar")
 +                .and()
 +                    .commit();
 +
 +                Assert.fail();
 +            }
 +            catch ( KeeperException.BadVersionException correct )
 +            {
 +                // correct
 +            }
-             
++
 +            Assert.assertNull(client.checkExists().forPath("/bar"));
 +        }
 +        finally
 +        {
 +            CloseableUtils.closeQuietly(client);
 +        }
 +    }
 +
 +    @Test
 +    public void     testWithNamespace() throws Exception
 +    {
 +        CuratorFramework        client = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).retryPolicy(new
RetryOneTime(1)).namespace("galt").build();
 +        try
 +        {
 +            client.start();
 +            Collection<CuratorTransactionResult>    results =
 +                client.inTransaction()
 +                    .create().forPath("/foo", "one".getBytes())
 +                .and()
 +                    .create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath("/test-",
"one".getBytes())
 +                .and()
 +                    .setData().forPath("/foo", "two".getBytes())
 +                .and()
 +                    .create().forPath("/foo/bar")
 +                .and()
 +                    .delete().forPath("/foo/bar")
 +                .and()
 +                    .commit();
 +
 +            Assert.assertTrue(client.checkExists().forPath("/foo") != null);
 +            Assert.assertTrue(client.usingNamespace(null).checkExists().forPath("/galt/foo")
!= null);
 +            Assert.assertEquals(client.getData().forPath("/foo"), "two".getBytes());
 +            Assert.assertTrue(client.checkExists().forPath("/foo/bar") == null);
 +
 +            CuratorTransactionResult    ephemeralResult = Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE,
"/test-"));
 +            Assert.assertNotNull(ephemeralResult);
 +            Assert.assertNotEquals(ephemeralResult.getResultPath(), "/test-");
 +            Assert.assertTrue(ephemeralResult.getResultPath().startsWith("/test-"));
 +        }
 +        finally
 +        {
 +            CloseableUtils.closeQuietly(client);
 +        }
 +    }
 +
 +    @Test
++    public void     testWithCompression() throws Exception
++    {
++        CuratorFramework        client = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).retryPolicy(new
RetryOneTime(1)).namespace("galt").build();
++        client.start();
++        try
++        {
++            Collection<CuratorTransactionResult>    results =
++                    client.inTransaction()
++                        .create().compressed().forPath("/foo", "one".getBytes())
++                    .and()
++                        .create().compressed().withACL(ZooDefs.Ids.READ_ACL_UNSAFE).forPath("/bar",
"two".getBytes())
++                    .and()
++                        .create().compressed().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath("/test-",
"three".getBytes())
++                    .and()
++                        .create().compressed().withMode(CreateMode.PERSISTENT).withACL(ZooDefs.Ids.READ_ACL_UNSAFE).forPath("/baz",
"four".getBytes())
++                    .and()
++                        .setData().compressed().withVersion(0).forPath("/foo", "five".getBytes())
++                    .and()
++                        .commit();
++
++            Assert.assertTrue(client.checkExists().forPath("/foo") != null);
++            Assert.assertEquals(client.getData().decompressed().forPath("/foo"), "five".getBytes());
++
++            Assert.assertTrue(client.checkExists().forPath("/bar") != null);
++            Assert.assertEquals(client.getData().decompressed().forPath("/bar"), "two".getBytes());
++            Assert.assertEquals(client.getACL().forPath("/bar"), ZooDefs.Ids.READ_ACL_UNSAFE);
++
++            CuratorTransactionResult    ephemeralResult = Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE,
"/test-"));
++            Assert.assertNotNull(ephemeralResult);
++            Assert.assertNotEquals(ephemeralResult.getResultPath(), "/test-");
++            Assert.assertTrue(ephemeralResult.getResultPath().startsWith("/test-"));
++
++            Assert.assertTrue(client.checkExists().forPath("/baz") != null);
++            Assert.assertEquals(client.getData().decompressed().forPath("/baz"), "four".getBytes());
++            Assert.assertEquals(client.getACL().forPath("/baz"), ZooDefs.Ids.READ_ACL_UNSAFE);
++        }
++        finally
++        {
++            client.close();
++        }
++    }
++
++    @Test
 +    public void     testBasic() throws Exception
 +    {
 +        CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(),
new RetryOneTime(1));
 +        try
 +        {
 +            client.start();
 +            Collection<CuratorTransactionResult>    results =
 +                client.inTransaction()
 +                    .create().forPath("/foo")
 +                .and()
 +                    .create().forPath("/foo/bar", "snafu".getBytes())
 +                .and()
 +                    .commit();
 +
 +            Assert.assertTrue(client.checkExists().forPath("/foo/bar") != null);
 +            Assert.assertEquals(client.getData().forPath("/foo/bar"), "snafu".getBytes());
 +
 +            CuratorTransactionResult    fooResult = Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE,
"/foo"));
 +            CuratorTransactionResult    fooBarResult = Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE,
"/foo/bar"));
 +            Assert.assertNotNull(fooResult);
 +            Assert.assertNotNull(fooBarResult);
 +            Assert.assertNotSame(fooResult, fooBarResult);
 +            Assert.assertEquals(fooResult.getResultPath(), "/foo");
 +            Assert.assertEquals(fooBarResult.getResultPath(), "/foo/bar");
 +        }
 +        finally
 +        {
 +            CloseableUtils.closeQuietly(client);
 +        }
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/curator/blob/ba38d4c5/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------
diff --cc curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
index 2558984,4d00266..81590f7
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
@@@ -289,8 -296,9 +303,10 @@@ public class TreeCache implements Close
  
          void wasDeleted() throws Exception
          {
-             stat.set(null);
-             data.set(null);
+             Stat oldStat = stat.getAndSet(null);
+             byte[] oldData = data.getAndSet(null);
 -            client.clearWatcherReferences(this);
++            client.watches().remove(this).ofType(WatcherType.Any).inBackground().forPath(path);
++
              ConcurrentMap<String, TreeNode> childMap = children.getAndSet(null);
              if ( childMap != null )
              {
@@@ -532,12 -540,14 +548,15 @@@
       * @param dataIsCompressed if true, data in the path is compressed
       * @param executorService  Closeable ExecutorService to use for the TreeCache's background
thread
       * @param createParentNodes true to create parent nodes as containers
+      * @param selector         the selector to use
       */
-     TreeCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed,
int maxDepth, final CloseableExecutorService executorService, boolean createParentNodes)
+     TreeCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed,
int maxDepth, final CloseableExecutorService executorService, boolean createParentNodes, TreeCacheSelector
selector)
      {
          this.createParentNodes = createParentNodes;
+         this.selector = Preconditions.checkNotNull(selector, "selector cannot be null");
          this.root = new TreeNode(validatePath(path), null);
 -        this.client = Preconditions.checkNotNull(client, "client cannot be null");
++        Preconditions.checkNotNull(client, "client cannot be null");
 +        this.client = client.newWatcherRemoveCuratorFramework();
          this.cacheData = cacheData;
          this.dataIsCompressed = dataIsCompressed;
          this.maxDepth = maxDepth;

http://git-wip-us.apache.org/repos/asf/curator/blob/ba38d4c5/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
----------------------------------------------------------------------
diff --cc curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
index 151ea7e,ad7c417..173fcd7
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
@@@ -377,9 -424,10 +424,9 @@@ public class TestTreeCache extends Base
          assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/me");
  
          KillSession.kill(client.getZookeeperClient().getZooKeeper(), server.getConnectString());
 -        assertEvent(TreeCacheEvent.Type.CONNECTION_SUSPENDED);
          assertEvent(TreeCacheEvent.Type.CONNECTION_LOST);
          assertEvent(TreeCacheEvent.Type.CONNECTION_RECONNECTED);
-         assertEvent(TreeCacheEvent.Type.NODE_REMOVED, "/test/me");
+         assertEvent(TreeCacheEvent.Type.NODE_REMOVED, "/test/me", "data".getBytes());
  
          assertNoMoreEvents();
      }


Mime
View raw message