curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [1/4] git commit: CURATOR-93 - Added compress() option for transactions.
Date Fri, 20 Jun 2014 14:09:36 GMT
Repository: curator
Updated Branches:
  refs/heads/master b04c8b5af -> 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/master
Commit: 30e66cfa3e8e7d09f553adbaa699edbd05993a4e
Parents: 6e98562
Author: Cameron McKenzie <cameron@unico.com.au>
Authored: Wed Jun 18 11:28:23 2014 +1000
Committer: Cameron McKenzie <cameron@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);
+        }
+    }
+}


Mime
View raw message