You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2014/06/19 04:55:20 UTC

[1/4] git commit: CURATOR-93 - Added compress() option for transactions.

Repository: curator
Updated Branches:
  refs/heads/CURATOR-93 [created] 2f751df40


CURATOR-93 - Added compress() option for transactions.

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

Branch: refs/heads/CURATOR-93
Commit: 30e66cfa3e8e7d09f553adbaa699edbd05993a4e
Parents: 6e98562
Author: Cameron McKenzie <ca...@unico.com.au>
Authored: Wed Jun 18 11:28:23 2014 +1000
Committer: Cameron McKenzie <ca...@unico.com.au>
Committed: Wed Jun 18 11:28:23 2014 +1000

----------------------------------------------------------------------
 .../transaction/TransactionCreateBuilder.java   |  5 +-
 .../framework/imps/CreateBuilderImpl.java       | 18 +++++-
 .../imps/TestCompressionInTransaction.java      | 61 ++++++++++++++++++++
 3 files changed, 80 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/30e66cfa/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 f269daf..51f4cb7 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
@@ -19,12 +19,15 @@
 package org.apache.curator.framework.api.transaction;
 
 import org.apache.curator.framework.api.ACLPathAndBytesable;
+import org.apache.curator.framework.api.Compressible;
+import org.apache.curator.framework.api.CreateBackgroundModeACLable;
 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>
+    ACLPathAndBytesable<CuratorTransactionBridge>,
+    Compressible<ACLPathAndBytesable<CuratorTransactionBridge>>
 {
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/30e66cfa/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 fa95b2c..b5d5f97 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
@@ -87,16 +87,28 @@ class CreateBuilderImpl implements CreateBuilder, BackgroundOperation<PathAndByt
                 CreateBuilderImpl.this.withMode(mode);
                 return this;
             }
-
+            
+            @Override
+            public ACLPathAndBytesable<CuratorTransactionBridge> compressed()
+            {
+                CreateBuilderImpl.this.compressed();
+                return this;
+            }
+            
             @Override
             public CuratorTransactionBridge forPath(String path) throws Exception
             {
                 return forPath(path, client.getDefaultData());
-            }
+            }            
 
             @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;

http://git-wip-us.apache.org/repos/asf/curator/blob/30e66cfa/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCompressionInTransaction.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCompressionInTransaction.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCompressionInTransaction.java
new file mode 100644
index 0000000..f5adaff
--- /dev/null
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCompressionInTransaction.java
@@ -0,0 +1,61 @@
+/**
+ * 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 org.apache.curator.test.BaseClassForTests;
+import org.apache.curator.utils.CloseableUtils;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.api.CompressionProvider;
+import org.apache.curator.retry.RetryOneTime;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class TestCompressionInTransaction extends BaseClassForTests
+{
+    @Test
+    public void testSimple() throws Exception
+    {
+        final String path1 = "/a";
+        final String path2 = "/a/b";
+        
+        final byte[]            data1 = "here's a string".getBytes();
+        final byte[]            data2 = "here's another string".getBytes();
+
+        CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
+        try
+        {
+            client.start();
+
+            client.inTransaction().create().compressed().forPath(path1, data1).and().
+            create().compressed().forPath(path2, data2).and().commit();
+
+            Assert.assertNotEquals(data1, client.getData().forPath(path1));
+            Assert.assertEquals(data1.length, client.getData().decompressed().forPath(path1).length);
+            
+            Assert.assertNotEquals(data2, client.getData().forPath(path2));
+            Assert.assertEquals(data2.length, client.getData().decompressed().forPath(path2).length);            
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(client);
+        }
+    }
+}


[2/4] git commit: Merge branch 'CURATOR-93' of github.com:cammckenzie/curator into CURATOR-93

Posted by ra...@apache.org.
Merge branch 'CURATOR-93' of github.com:cammckenzie/curator into CURATOR-93


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

Branch: refs/heads/CURATOR-93
Commit: 7d192424d06a04f27c4efc8cac27762ad841b532
Parents: b04c8b5 30e66cf
Author: randgalt <ra...@apache.org>
Authored: Wed Jun 18 12:00:12 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Wed Jun 18 12:00:12 2014 -0500

----------------------------------------------------------------------
 .../transaction/TransactionCreateBuilder.java   |  5 +-
 .../framework/imps/CreateBuilderImpl.java       | 18 +++++-
 .../imps/TestCompressionInTransaction.java      | 61 ++++++++++++++++++++
 3 files changed, 80 insertions(+), 4 deletions(-)
----------------------------------------------------------------------



[4/4] git commit: Merge branch 'CURATOR-93' of github.com:cammckenzie/curator into CURATOR-93

Posted by ra...@apache.org.
Merge branch 'CURATOR-93' of github.com:cammckenzie/curator into CURATOR-93


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

Branch: refs/heads/CURATOR-93
Commit: 2f751df40a79e67c2d42fe44e02a67f1fba0b184
Parents: 7d19242 2df9b97
Author: randgalt <ra...@apache.org>
Authored: Wed Jun 18 21:44:59 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Wed Jun 18 21:44:59 2014 -0500

----------------------------------------------------------------------
 .../transaction/TransactionCreateBuilder.java   |   1 -
 .../transaction/TransactionSetDataBuilder.java  |   4 +-
 .../framework/imps/CreateBuilderImpl.java       |   2 +-
 .../framework/imps/SetDataBuilderImpl.java      |  14 +++
 .../imps/TestCompressionInTransaction.java      | 100 ++++++++++++++++++-
 5 files changed, 116 insertions(+), 5 deletions(-)
----------------------------------------------------------------------



[3/4] git commit: CURATOR-93 - Added compression in transaction functionality to the TransationSetDataBuilder and added unit tests for setting compressed data in a transaction. Updated unit tests for the create compressed in transaction cases to explicit

Posted by ra...@apache.org.
CURATOR-93 - Added compression in transaction functionality to the
TransationSetDataBuilder and added unit tests for setting compressed
data in a transaction. Updated unit tests for the create compressed in
transaction cases to explicitly compare data rather than just the data's
length.

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

Branch: refs/heads/CURATOR-93
Commit: 2df9b97dfdd8f322efcb5facf0ba933c2125e4ef
Parents: 30e66cf
Author: Cameron McKenzie <ca...@unico.com.au>
Authored: Thu Jun 19 08:06:43 2014 +1000
Committer: Cameron McKenzie <ca...@unico.com.au>
Committed: Thu Jun 19 08:06:43 2014 +1000

----------------------------------------------------------------------
 .../transaction/TransactionCreateBuilder.java   |   1 -
 .../transaction/TransactionSetDataBuilder.java  |   4 +-
 .../framework/imps/CreateBuilderImpl.java       |   2 +-
 .../framework/imps/SetDataBuilderImpl.java      |  14 +++
 .../imps/TestCompressionInTransaction.java      | 100 ++++++++++++++++++-
 5 files changed, 116 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/2df9b97d/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 51f4cb7..6ac3069 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
@@ -20,7 +20,6 @@ package org.apache.curator.framework.api.transaction;
 
 import org.apache.curator.framework.api.ACLPathAndBytesable;
 import org.apache.curator.framework.api.Compressible;
-import org.apache.curator.framework.api.CreateBackgroundModeACLable;
 import org.apache.curator.framework.api.CreateModable;
 import org.apache.curator.framework.api.PathAndBytesable;
 

http://git-wip-us.apache.org/repos/asf/curator/blob/2df9b97d/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 14fd005..777537a 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
@@ -18,11 +18,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.Versionable;
 
 public interface TransactionSetDataBuilder extends
     PathAndBytesable<CuratorTransactionBridge>,
-    Versionable<PathAndBytesable<CuratorTransactionBridge>>
+    Versionable<PathAndBytesable<CuratorTransactionBridge>>,
+    Compressible<PathAndBytesable<CuratorTransactionBridge>>
 {
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/2df9b97d/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 b5d5f97..3cf23b8 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
@@ -99,7 +99,7 @@ class CreateBuilderImpl implements CreateBuilder, BackgroundOperation<PathAndByt
             public CuratorTransactionBridge forPath(String path) throws Exception
             {
                 return forPath(path, client.getDefaultData());
-            }            
+            }
 
             @Override
             public CuratorTransactionBridge forPath(String path, byte[] data) throws Exception

http://git-wip-us.apache.org/repos/asf/curator/blob/2df9b97d/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 c88ea55..8e93cbf 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,6 +20,7 @@ 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;
@@ -33,6 +34,7 @@ import org.apache.curator.framework.api.transaction.TransactionSetDataBuilder;
 import org.apache.zookeeper.AsyncCallback;
 import org.apache.zookeeper.Op;
 import org.apache.zookeeper.data.Stat;
+
 import java.util.concurrent.Callable;
 import java.util.concurrent.Executor;
 
@@ -58,6 +60,11 @@ class SetDataBuilderImpl implements SetDataBuilder, BackgroundOperation<PathAndB
             @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.setData(fixedPath, data, version), OperationType.SET_DATA, path);
                 return curatorTransaction;
@@ -75,6 +82,13 @@ class SetDataBuilderImpl implements SetDataBuilder, BackgroundOperation<PathAndB
                 SetDataBuilderImpl.this.withVersion(version);
                 return this;
             }
+
+            @Override
+            public PathAndBytesable<CuratorTransactionBridge> compressed() {
+                compress = true;
+                
+                return this;
+            }
         };
     }
 

http://git-wip-us.apache.org/repos/asf/curator/blob/2df9b97d/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCompressionInTransaction.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCompressionInTransaction.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCompressionInTransaction.java
index f5adaff..c18af99 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCompressionInTransaction.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestCompressionInTransaction.java
@@ -26,11 +26,74 @@ import org.apache.curator.framework.api.CompressionProvider;
 import org.apache.curator.retry.RetryOneTime;
 import org.testng.Assert;
 import org.testng.annotations.Test;
+
 import java.util.concurrent.atomic.AtomicInteger;
 
 public class TestCompressionInTransaction extends BaseClassForTests
 {
     @Test
+    public void testSetData() throws Exception
+    {
+        final String path = "/a";
+        final byte[]            data = "here's a string".getBytes();
+
+        CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
+        try
+        {
+            client.start();
+
+            //Create uncompressed data in a transaction
+            client.inTransaction().create().forPath(path, data).and().commit();
+            Assert.assertEquals(data, client.getData().forPath(path));
+
+            //Create compressed data in transaction
+            client.inTransaction().setData().compressed().forPath(path, data).and().commit();
+            Assert.assertEquals(data, client.getData().decompressed().forPath(path));
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(client);
+        }
+    }
+    
+    @Test
+    public void testSetCompressedAndUncompressed() throws Exception
+    {
+        final String path1 = "/a";
+        final String path2 = "/b";
+        
+        final byte[]            data1 = "here's a string".getBytes();
+        final byte[]            data2 = "here's another string".getBytes();
+
+        CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
+        try
+        {
+            client.start();
+
+            //Create the nodes
+            client.inTransaction().create().compressed().forPath(path1).and().
+            create().forPath(path2).and().commit();
+
+            //Check they exist
+            Assert.assertNotNull(client.checkExists().forPath(path1));
+            Assert.assertNotNull(client.checkExists().forPath(path2));
+            
+            //Set the nodes, path1 compressed, path2 uncompressed.
+            client.inTransaction().setData().compressed().forPath(path1, data1).and().
+            setData().forPath(path2, data2).and().commit();
+            
+            Assert.assertNotEquals(data1, client.getData().forPath(path1));
+            Assert.assertEquals(data1, client.getData().decompressed().forPath(path1));
+      
+            Assert.assertEquals(data2, client.getData().forPath(path2));            
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(client);
+        }
+    }    
+    
+    @Test
     public void testSimple() throws Exception
     {
         final String path1 = "/a";
@@ -48,10 +111,43 @@ public class TestCompressionInTransaction extends BaseClassForTests
             create().compressed().forPath(path2, data2).and().commit();
 
             Assert.assertNotEquals(data1, client.getData().forPath(path1));
-            Assert.assertEquals(data1.length, client.getData().decompressed().forPath(path1).length);
+            Assert.assertEquals(data1, client.getData().decompressed().forPath(path1));
             
             Assert.assertNotEquals(data2, client.getData().forPath(path2));
-            Assert.assertEquals(data2.length, client.getData().decompressed().forPath(path2).length);            
+            Assert.assertEquals(data2, client.getData().decompressed().forPath(path2));            
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(client);
+        }
+    }    
+    
+    /**
+     * Test the case where both uncompressed and compressed data is generated in
+     * the same transaction
+     * @throws Exception
+     */
+    @Test
+    public void testCreateCompressedAndUncompressed() throws Exception
+    {
+        final String path1 = "/a";
+        final String path2 = "/b";
+        
+        final byte[]            data1 = "here's a string".getBytes();
+        final byte[]            data2 = "here's another string".getBytes();
+
+        CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
+        try
+        {
+            client.start();
+
+            client.inTransaction().create().compressed().forPath(path1, data1).and().
+            create().forPath(path2, data2).and().commit();
+
+            Assert.assertNotEquals(data1, client.getData().forPath(path1));
+            Assert.assertEquals(data1, client.getData().decompressed().forPath(path1));
+      
+            Assert.assertEquals(data2, client.getData().forPath(path2));            
         }
         finally
         {