curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [01/11] curator git commit: CURATOR-278: In transactions compressed option does not work with some fluent api combinations
Date Mon, 18 Jan 2016 21:04:04 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-3.0 9a03ea939 -> ae8dc466c


CURATOR-278: In transactions compressed option does not work with some fluent api combinations


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

Branch: refs/heads/CURATOR-3.0
Commit: c1e2a308d891cba4251adcb18a91d074077979b9
Parents: 31c0465
Author: Grant Henke <granthenke@gmail.com>
Authored: Sat Nov 7 13:39:54 2015 -0600
Committer: Grant Henke <granthenke@gmail.com>
Committed: Sat Nov 7 13:39:54 2015 -0600

----------------------------------------------------------------------
 .../framework/api/VersionPathAndBytesable.java  | 25 +++++++++++
 .../transaction/TransactionCreateBuilder.java   |  5 ++-
 .../transaction/TransactionSetDataBuilder.java  |  4 +-
 .../framework/imps/CreateBuilderImpl.java       | 12 ++---
 .../framework/imps/SetDataBuilderImpl.java      |  8 ++--
 .../framework/imps/TestTransactions.java        | 46 +++++++++++++++++++-
 6 files changed, 86 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/c1e2a308/curator-framework/src/main/java/org/apache/curator/framework/api/VersionPathAndBytesable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/VersionPathAndBytesable.java
b/curator-framework/src/main/java/org/apache/curator/framework/api/VersionPathAndBytesable.java
new file mode 100644
index 0000000..556fc67
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/VersionPathAndBytesable.java
@@ -0,0 +1,25 @@
+/**
+ * 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.api;
+
+public interface VersionPathAndBytesable<T> extends
+        Versionable<PathAndBytesable<T>>,
+        PathAndBytesable<T>
+{
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/c1e2a308/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionCreateBuilder.java
----------------------------------------------------------------------
diff --git 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
index 6ac3069..f2ac146 100644
--- 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
@@ -18,6 +18,7 @@
  */
 package org.apache.curator.framework.api.transaction;
 
+import org.apache.curator.framework.api.ACLCreateModePathAndBytesable;
 import org.apache.curator.framework.api.ACLPathAndBytesable;
 import org.apache.curator.framework.api.Compressible;
 import org.apache.curator.framework.api.CreateModable;
@@ -27,6 +28,6 @@ public interface TransactionCreateBuilder extends
     PathAndBytesable<CuratorTransactionBridge>,
     CreateModable<ACLPathAndBytesable<CuratorTransactionBridge>>,
     ACLPathAndBytesable<CuratorTransactionBridge>,
-    Compressible<ACLPathAndBytesable<CuratorTransactionBridge>>
-{
+    ACLCreateModePathAndBytesable<CuratorTransactionBridge>,
+    Compressible<ACLCreateModePathAndBytesable<CuratorTransactionBridge>>  {
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/c1e2a308/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/TransactionSetDataBuilder.java
----------------------------------------------------------------------
diff --git 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
index 777537a..cc9e01c 100644
--- 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 @@ package org.apache.curator.framework.api.transaction;
 
 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>>,
-    Compressible<PathAndBytesable<CuratorTransactionBridge>>
+    VersionPathAndBytesable<CuratorTransactionBridge>,
+    Compressible<VersionPathAndBytesable<CuratorTransactionBridge>>
 {
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/c1e2a308/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
----------------------------------------------------------------------
diff --git 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
index b72b7b6..39dd871 100644
--- 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
@@ -89,14 +89,14 @@ class CreateBuilderImpl implements CreateBuilder, BackgroundOperation<PathAndByt
                 CreateBuilderImpl.this.withMode(mode);
                 return this;
             }
-            
+
             @Override
-            public ACLPathAndBytesable<CuratorTransactionBridge> compressed()
+            public ACLCreateModePathAndBytesable<CuratorTransactionBridge> compressed()
             {
                 CreateBuilderImpl.this.compressed();
                 return this;
             }
-            
+
             @Override
             public CuratorTransactionBridge forPath(String path) throws Exception
             {
@@ -105,12 +105,12 @@ class CreateBuilderImpl implements CreateBuilder, BackgroundOperation<PathAndByt
 
             @Override
             public CuratorTransactionBridge 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;
@@ -493,7 +493,7 @@ class CreateBuilderImpl implements CreateBuilder, BackgroundOperation<PathAndByt
                 */
                 protectedId = UUID.randomUUID().toString();
             }
-            
+
             throw e;
         }
     }

http://git-wip-us.apache.org/repos/asf/curator/blob/c1e2a308/curator-framework/src/main/java/org/apache/curator/framework/imps/SetDataBuilderImpl.java
----------------------------------------------------------------------
diff --git 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
index 8e93cbf..4117930 100644
--- 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
@@ -20,7 +20,6 @@ package org.apache.curator.framework.imps;
 
 import org.apache.curator.RetryLoop;
 import org.apache.curator.TimeTrace;
-import org.apache.curator.framework.api.ACLPathAndBytesable;
 import org.apache.curator.framework.api.BackgroundCallback;
 import org.apache.curator.framework.api.BackgroundPathAndBytesable;
 import org.apache.curator.framework.api.CuratorEvent;
@@ -28,6 +27,7 @@ import org.apache.curator.framework.api.CuratorEventType;
 import org.apache.curator.framework.api.PathAndBytesable;
 import org.apache.curator.framework.api.SetDataBackgroundVersionable;
 import org.apache.curator.framework.api.SetDataBuilder;
+import org.apache.curator.framework.api.VersionPathAndBytesable;
 import org.apache.curator.framework.api.transaction.CuratorTransactionBridge;
 import org.apache.curator.framework.api.transaction.OperationType;
 import org.apache.curator.framework.api.transaction.TransactionSetDataBuilder;
@@ -64,7 +64,7 @@ class SetDataBuilderImpl implements SetDataBuilder, BackgroundOperation<PathAndB
                 {
                     data = client.getCompressionProvider().compress(path, data);
                 }
-                
+
                 String      fixedPath = client.fixForNamespace(path);
                 transaction.add(Op.setData(fixedPath, data, version), OperationType.SET_DATA,
path);
                 return curatorTransaction;
@@ -84,9 +84,9 @@ class SetDataBuilderImpl implements SetDataBuilder, BackgroundOperation<PathAndB
             }
 
             @Override
-            public PathAndBytesable<CuratorTransactionBridge> compressed() {
+            public VersionPathAndBytesable<CuratorTransactionBridge> compressed() {
                 compress = true;
-                
+
                 return this;
             }
         };

http://git-wip-us.apache.org/repos/asf/curator/blob/c1e2a308/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactions.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactions.java
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactions.java
index ae2cf1d..fedc779 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactions.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactions.java
@@ -27,6 +27,7 @@ import org.apache.curator.retry.RetryOneTime;
 import org.apache.curator.test.BaseClassForTests;
 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;
@@ -59,7 +60,7 @@ public class TestTransactions extends BaseClassForTests
             {
                 // correct
             }
-            
+
             Assert.assertNull(client.checkExists().forPath("/bar"));
         }
         finally
@@ -106,6 +107,49 @@ public class TestTransactions extends BaseClassForTests
     }
 
     @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));


Mime
View raw message