Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 749C2200AEE for ; Tue, 3 May 2016 17:20:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 71AC4160A04; Tue, 3 May 2016 17:20:55 +0200 (CEST) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C3F821609F7 for ; Tue, 3 May 2016 17:20:54 +0200 (CEST) Received: (qmail 77337 invoked by uid 500); 3 May 2016 15:20:53 -0000 Mailing-List: contact commits-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list commits@curator.apache.org Received: (qmail 77267 invoked by uid 99); 3 May 2016 15:20:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 May 2016 15:20:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 53339DFFF8; Tue, 3 May 2016 15:20:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: randgalt@apache.org To: commits@curator.apache.org Date: Tue, 03 May 2016 15:21:08 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [16/16] curator git commit: test transactions archived-at: Tue, 03 May 2016 15:20:55 -0000 test transactions Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/ae6cb4be Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/ae6cb4be Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/ae6cb4be Branch: refs/heads/CURATOR-322 Commit: ae6cb4be4ee56215bef26e8d7fb5139d9b81d026 Parents: 923a2d8 Author: randgalt Authored: Tue May 3 10:19:46 2016 -0500 Committer: randgalt Committed: Tue May 3 10:19:46 2016 -0500 ---------------------------------------------------------------------- .../curator/framework/schema/TestSchema.java | 83 ++++++++++++++++++++ .../src/test/resources/schema4.json | 14 ++++ 2 files changed, 97 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/ae6cb4be/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java b/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java index f3754f5..e094c0e 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java @@ -22,6 +22,7 @@ import com.google.common.base.Charsets; import com.google.common.io.Resources; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.framework.api.transaction.CuratorOp; import org.apache.curator.retry.RetryOneTime; import org.apache.curator.test.BaseClassForTests; import org.apache.curator.utils.CloseableUtils; @@ -139,6 +140,88 @@ public class TestSchema extends BaseClassForTests } } + @Test + public void testTransaction() throws Exception + { + final DataValidator dataValidator = new DataValidator() + { + @Override + public boolean isValid(String path, byte[] data) + { + return data.length > 0; + } + }; + SchemaSetLoader.DataValidatorMapper dataValidatorMapper = new SchemaSetLoader.DataValidatorMapper() + { + @Override + public DataValidator getDataValidator(String name) + { + return dataValidator; + } + }; + SchemaSet schemaSet = loadSchemaSet("schema4.json", dataValidatorMapper); + CuratorFramework client = newClient(schemaSet); + try + { + client.start(); + + CuratorOp createAPersistent = client.transactionOp().create().forPath("/a"); + CuratorOp createAEphemeral = client.transactionOp().create().withMode(CreateMode.EPHEMERAL).forPath("/a"); + CuratorOp deleteA = client.transactionOp().delete().forPath("/a"); + CuratorOp createBEmptyData = client.transactionOp().create().forPath("/b", new byte[0]); + CuratorOp createBWithData = client.transactionOp().create().forPath("/b", new byte[10]); + CuratorOp setBEmptyData = client.transactionOp().setData().forPath("/b", new byte[0]); + CuratorOp setBWithData = client.transactionOp().setData().forPath("/b", new byte[10]); + + try + { + client.transaction().forOperations(createAPersistent, createAEphemeral); + Assert.fail("Should've violated schema"); + } + catch ( SchemaViolation dummy ) + { + // expected + } + client.transaction().forOperations(createAEphemeral); + + try + { + client.transaction().forOperations(deleteA); + Assert.fail("Should've violated schema"); + } + catch ( SchemaViolation dummy ) + { + // expected + } + + try + { + client.transaction().forOperations(createBEmptyData); + Assert.fail("Should've violated schema"); + } + catch ( SchemaViolation dummy ) + { + // expected + } + client.transaction().forOperations(createBWithData); + + try + { + client.transaction().forOperations(setBEmptyData); + Assert.fail("Should've violated schema"); + } + catch ( SchemaViolation dummy ) + { + // expected + } + client.transaction().forOperations(setBWithData); + } + finally + { + CloseableUtils.closeQuietly(client); + } + } + @Override protected boolean enabledSessionExpiredStateAware() { http://git-wip-us.apache.org/repos/asf/curator/blob/ae6cb4be/curator-framework/src/test/resources/schema4.json ---------------------------------------------------------------------- diff --git a/curator-framework/src/test/resources/schema4.json b/curator-framework/src/test/resources/schema4.json new file mode 100644 index 0000000..6fec36d --- /dev/null +++ b/curator-framework/src/test/resources/schema4.json @@ -0,0 +1,14 @@ +[ + { + "name": "testa", + "path": "/a", + "ephemeral": "must", + "canBeDeleted": false + }, + + { + "name": "testb", + "path": "/b", + "dataValidator": "test" + } +] \ No newline at end of file