org.apache.curator.framework.api.transaction.CuratorTransactionResult Java Examples

The following examples show how to use org.apache.curator.framework.api.transaction.CuratorTransactionResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionExample.java    From ZKRecipesByExample with Apache License 2.0 6 votes vote down vote up
public static Collection<CuratorTransactionResult> transaction(CuratorFramework client) throws Exception {
//		// this example shows how to use ZooKeeper's new transactions
//		Collection<CuratorTransactionResult> results = client.inTransaction().create().forPath("/a/path", "some data".getBytes())
//				.and().setData().forPath("/another/path", "other data".getBytes())
//				.and().delete().forPath("/yet/another/path")
//				.and().commit(); // IMPORTANT!

		//inTransaction is deprecated. use transaction() instead
		List<CuratorTransactionResult>  results = client.transaction().forOperations(
				client.transactionOp().create().forPath("/a/path", "some data".getBytes()),
				client.transactionOp().setData().forPath("/another/path", "other data".getBytes()),
				client.transactionOp().delete().forPath("/yet/another/path"));
		// called
		for (CuratorTransactionResult result : results) {
			System.out.println(result.getForPath() + " - " + result.getType());
		}
		return results;
	}
 
Example #2
Source File: TransactionExamples.java    From curator with Apache License 2.0 6 votes vote down vote up
public static Collection<CuratorTransactionResult>      transaction(CuratorFramework client) throws Exception
{
    // this example shows how to use ZooKeeper's transactions

    CuratorOp createOp = client.transactionOp().create().forPath("/a/path", "some data".getBytes());
    CuratorOp setDataOp = client.transactionOp().setData().forPath("/another/path", "other data".getBytes());
    CuratorOp deleteOp = client.transactionOp().delete().forPath("/yet/another/path");

    Collection<CuratorTransactionResult>    results = client.transaction().forOperations(createOp, setDataOp, deleteOp);

    for ( CuratorTransactionResult result : results )
    {
        System.out.println(result.getForPath() + " - " + result.getType());
    }

    return results;
}
 
Example #3
Source File: TransactionExamples.java    From xian with Apache License 2.0 6 votes vote down vote up
public static Collection<CuratorTransactionResult>      transaction(CuratorFramework client) throws Exception
{
    // this example shows how to use ZooKeeper's new transactions

    Collection<CuratorTransactionResult>    results = client.inTransaction()
            .create().forPath("/a/path", "some data".getBytes())
        .and()
            .setData().forPath("/another/path", "other data".getBytes())
        .and()
            .delete().forPath("/yet/another/path")
        .and()
            .commit();  // IMPORTANT! The transaction is not submitted until commit() is called

    for ( CuratorTransactionResult result : results )
    {
        System.out.println(result.getForPath() + " - " + result.getType());
    }

    return results;
}
 
Example #4
Source File: CrudDemo.java    From javabase with Apache License 2.0 6 votes vote down vote up
/**
 * Curator支持事务,一组crud操作同生同灭
 * @param client
 */
private static void transation(CuratorFramework client) {
    try {
        // 开启事务
        CuratorTransaction transaction = client.inTransaction();
        Collection<CuratorTransactionResult> results = transaction.create()
                .forPath("/root/transation", "transation".getBytes()).and().create()
                .forPath("/root/transation2", "transation2".getBytes()).and()
                .delete().forPath("/root/transation").and()
                .delete().forPath("/root/transation2").and().commit();
        for (CuratorTransactionResult result : results) {
            System.out.println(result.getForPath() + " - " + result.getType());
        }
    }catch (Exception e){
        log.error("transation exception ", e);
    }
}
 
Example #5
Source File: CuratorMultiTransactionImpl.java    From curator with Apache License 2.0 6 votes vote down vote up
@Override
public void performBackgroundOperation(final OperationAndData<CuratorMultiTransactionRecord> operationAndData) throws Exception
{
    try
    {
        final TimeTrace trace = client.getZookeeperClient().startTracer("CuratorMultiTransactionImpl-Background");
        AsyncCallback.MultiCallback callback = new AsyncCallback.MultiCallback()
        {
            @Override
            public void processResult(int rc, String path, Object ctx, List<OpResult> opResults)
            {
                trace.commit();
                List<CuratorTransactionResult> curatorResults = (opResults != null) ? CuratorTransactionImpl.wrapResults(client, opResults, operationAndData.getData()) : null;
                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.TRANSACTION, rc, path, null, ctx, null, null, null, null, null, curatorResults);
                client.processBackgroundOperation(operationAndData, event);
            }
        };
        client.getZooKeeper().multi(operationAndData.getData(), callback, backgrounding.getContext());
    }
    catch ( Throwable e )
    {
        backgrounding.checkError(e, null);
    }
}
 
Example #6
Source File: CuratorMultiTransactionImpl.java    From curator with Apache License 2.0 6 votes vote down vote up
private List<CuratorTransactionResult> forOperationsInForeground(final CuratorMultiTransactionRecord record) throws Exception
{
    TimeTrace trace = client.getZookeeperClient().startTracer("CuratorMultiTransactionImpl-Foreground");
    List<OpResult> responseData = RetryLoop.callWithRetry
    (
        client.getZookeeperClient(),
        new Callable<List<OpResult>>()
        {
            @Override
            public List<OpResult> call() throws Exception
            {
                return client.getZooKeeper().multi(record);
            }
        }
    );
    trace.commit();

    return CuratorTransactionImpl.wrapResults(client, responseData, record);
}
 
Example #7
Source File: TestTransactionsNew.java    From curator with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasic() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();
        CuratorOp createOp1 = client.transactionOp().create().forPath("/foo");
        CuratorOp createOp2 = client.transactionOp().create().forPath("/foo/bar", "snafu".getBytes());

        Collection<CuratorTransactionResult> results = client.transaction().forOperations(createOp1, createOp2);

        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);
    }
}
 
Example #8
Source File: BaragonRequestDatastore.java    From Baragon with Apache License 2.0 5 votes vote down vote up
@Timed
public QueuedRequestId enqueueRequest(BaragonRequest request, InternalRequestStates state) throws NodeExistsException {
  final long start = System.currentTimeMillis();

  final String queuedRequestPath = String.format(REQUEST_ENQUEUE_FORMAT, request.getLoadBalancerService().getServiceId(), request.getLoadBalancerRequestId());
  final String requestPath = String.format(REQUEST_FORMAT, request.getLoadBalancerRequestId());
  final String requestStatePath = String.format(REQUEST_STATE_FORMAT, request.getLoadBalancerRequestId());

  try {
    if (!nodeExists(REQUESTS_FORMAT)) {
      createNode(REQUESTS_FORMAT);
    }
    if (!nodeExists(REQUEST_QUEUE_FORMAT)) {
      createNode(REQUEST_QUEUE_FORMAT);
    }

    byte[] requestBytes = objectMapper.writeValueAsBytes(request);
    byte[] stateBytes = objectMapper.writeValueAsBytes(state);

    Collection<CuratorTransactionResult> results = curatorFramework.inTransaction()
        .create().forPath(requestPath, requestBytes).and()
        .create().forPath(requestStatePath, stateBytes).and()
        .create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(queuedRequestPath)
        .and().commit();

    log(OperationType.WRITE, Optional.of(3), Optional.of(requestBytes.length + stateBytes.length), start, String.format("Transaction Paths [%s + %s + %s]", requestPath, requestStatePath, queuedRequestPath));

    return QueuedRequestId.fromString(ZKPaths.getNodeFromPath(Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(org.apache.curator.framework.api.transaction.OperationType.CREATE, queuedRequestPath))
        .getResultPath()));
  } catch (NodeExistsException nee) {
    throw nee;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #9
Source File: AsyncCuratorFrameworkImpl.java    From curator with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncMultiTransaction transaction()
{
    return operations -> {
        BuilderCommon<List<CuratorTransactionResult>> common = new BuilderCommon<>(filters, opResultsProc);
        CuratorMultiTransactionImpl builder = new CuratorMultiTransactionImpl(client, common.backgrounding);
        return safeCall(common.internalCallback, () -> builder.forOperations(operations));
    };
}
 
Example #10
Source File: TestTransactionsOld.java    From curator with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #11
Source File: TestTransactionsOld.java    From curator with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #12
Source File: CuratorTransactionImpl.java    From xian with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<CuratorTransactionResult> commit() throws Exception
{
    Preconditions.checkState(!isCommitted, "transaction already committed");
    isCommitted = true;

    final AtomicBoolean firstTime = new AtomicBoolean(true);
    List<OpResult>      resultList = RetryLoop.callWithRetry
    (
        client.getZookeeperClient(),
        new Callable<List<OpResult>>()
        {
            @Override
            public List<OpResult> call() throws Exception
            {
                return doOperation(firstTime);
            }
        }
    );
    
    if ( resultList.size() != transaction.metadataSize() )
    {
        throw new IllegalStateException(String.format("Result size (%d) doesn't match input size (%d)", resultList.size(), transaction.metadataSize()));
    }

    ImmutableList.Builder<CuratorTransactionResult>     builder = ImmutableList.builder();
    for ( int i = 0; i < resultList.size(); ++i )
    {
        OpResult                                    opResult = resultList.get(i);
        CuratorMultiTransactionRecord.TypeAndPath   metadata = transaction.getMetadata(i);
        CuratorTransactionResult                    curatorResult = makeCuratorResult(opResult, metadata);
        builder.add(curatorResult);
    }

    return builder.build();
}
 
Example #13
Source File: TestTransactionsNew.java    From curator with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithNamespace() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).namespace("galt").build();
    try
    {
        client.start();
        CuratorOp createOp1 = client.transactionOp().create().forPath("/foo", "one".getBytes());
        CuratorOp createOp2 = client.transactionOp().create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath("/test-", "one".getBytes());
        CuratorOp setDataOp = client.transactionOp().setData().forPath("/foo", "two".getBytes());
        CuratorOp createOp3 = client.transactionOp().create().forPath("/foo/bar");
        CuratorOp deleteOp = client.transactionOp().delete().forPath("/foo/bar");

        Collection<CuratorTransactionResult> results = client.transaction().forOperations(createOp1, createOp2, setDataOp, createOp3, deleteOp);

        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);
    }
}
 
Example #14
Source File: CuratorEventImpl.java    From curator with Apache License 2.0 5 votes vote down vote up
CuratorEventImpl(CuratorFrameworkImpl client, CuratorEventType type, int resultCode, String path, String name, Object context, Stat stat, byte[] data, List<String> children, WatchedEvent watchedEvent, List<ACL> aclList, List<CuratorTransactionResult> opResults)
{
    this.type = type;
    this.resultCode = resultCode;
    this.opResults = (opResults != null) ? ImmutableList.copyOf(opResults) : null;
    this.path = client.unfixForNamespace(path);
    this.name = name;
    this.context = context;
    this.stat = stat;
    this.data = data;
    this.children = children;
    this.watchedEvent = (watchedEvent != null) ? new NamespaceWatchedEvent(client, watchedEvent) : null;
    this.aclList = (aclList != null) ? ImmutableList.copyOf(aclList) : null;
}
 
Example #15
Source File: CuratorMultiTransactionImpl.java    From curator with Apache License 2.0 5 votes vote down vote up
@Override
public List<CuratorTransactionResult> forOperations(List<CuratorOp> operations) throws Exception
{
    operations = Preconditions.checkNotNull(operations, "operations cannot be null");
    Preconditions.checkArgument(!operations.isEmpty(), "operations list cannot be empty");

    CuratorMultiTransactionRecord record = new CuratorMultiTransactionRecord();
    for ( CuratorOp curatorOp : operations )
    {
        Schema schema = client.getSchemaSet().getSchema(curatorOp.getTypeAndPath().getForPath());
        record.add(curatorOp.get(), curatorOp.getTypeAndPath().getType(), curatorOp.getTypeAndPath().getForPath());
        if ( (curatorOp.get().getType() == ZooDefs.OpCode.create) || (curatorOp.get().getType() == ZooDefs.OpCode.createContainer) )
        {
            CreateRequest createRequest = (CreateRequest)curatorOp.get().toRequestRecord();
            CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags(), CreateMode.PERSISTENT);
            schema.validateCreate(createMode, createRequest.getPath(), createRequest.getData(), createRequest.getAcl());
        }
        else if ( (curatorOp.get().getType() == ZooDefs.OpCode.delete) || (curatorOp.get().getType() == ZooDefs.OpCode.deleteContainer) )
        {
            DeleteRequest deleteRequest = (DeleteRequest)curatorOp.get().toRequestRecord();
            schema.validateDelete(deleteRequest.getPath());
        }
        else if ( curatorOp.get().getType() == ZooDefs.OpCode.setData )
        {
            SetDataRequest setDataRequest = (SetDataRequest)curatorOp.get().toRequestRecord();
            schema.validateGeneral(setDataRequest.getPath(), setDataRequest.getData(), null);
        }
    }

    if ( backgrounding.inBackground() )
    {
        client.processBackgroundOperation(new OperationAndData<>(this, record, backgrounding.getCallback(), null, backgrounding.getContext(), null), null);
        return null;
    }
    else
    {
        return forOperationsInForeground(record);
    }
}
 
Example #16
Source File: CuratorTransactionImpl.java    From xian with Apache License 2.0 5 votes vote down vote up
private CuratorTransactionResult makeCuratorResult(OpResult opResult, CuratorMultiTransactionRecord.TypeAndPath metadata)
{
    String                                      resultPath = null;
    Stat resultStat = null;
    switch ( opResult.getType() )
    {
        default:
        {
            // NOP
            break;
        }

        case ZooDefs.OpCode.create:
        {
            OpResult.CreateResult       createResult = (OpResult.CreateResult)opResult;
            resultPath = client.unfixForNamespace(createResult.getPath());
            break;
        }

        case ZooDefs.OpCode.setData:
        {
            OpResult.SetDataResult      setDataResult = (OpResult.SetDataResult)opResult;
            resultStat = setDataResult.getStat();
            break;
        }
    }

    return new CuratorTransactionResult(metadata.type, metadata.forPath, resultPath, resultStat);
}
 
Example #17
Source File: TestTransactions.java    From xian with Apache License 2.0 5 votes vote down vote up
@Test
public void     testWithNamespace() 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().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
    {
        client.close();
    }
}
 
Example #18
Source File: TestTransactions.java    From xian with Apache License 2.0 5 votes vote down vote up
@Test
public void     testBasic() throws Exception
{
    CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();
    try
    {
        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
    {
        client.close();
    }
}
 
Example #19
Source File: MockCurator.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<CuratorTransactionResult> commit() throws Exception {
    fileSystem.replaceRoot(newRoot);
    committed = true;
    delayedListener.commit();
    return null; // TODO
}
 
Example #20
Source File: TestTransactionsOld.java    From curator with Apache License 2.0 4 votes vote down vote up
@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();
    }
}
 
Example #21
Source File: ModeledFrameworkImpl.java    From curator with Apache License 2.0 4 votes vote down vote up
@Override
public AsyncStage<List<CuratorTransactionResult>> inTransaction(List<CuratorOp> operations)
{
    return client.transaction().forOperations(operations);
}
 
Example #22
Source File: CachedModeledFrameworkImpl.java    From curator with Apache License 2.0 4 votes vote down vote up
@Override
public AsyncStage<List<CuratorTransactionResult>> inTransaction(List<CuratorOp> operations)
{
    return client.inTransaction(operations);
}
 
Example #23
Source File: TestTransactions.java    From xian with Apache License 2.0 4 votes vote down vote up
@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();
    }
}
 
Example #24
Source File: DefaultZooKeeperClient.java    From helios with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<CuratorTransactionResult> transaction(final ZooKeeperOperation... operations)
    throws KeeperException {
  return transaction(asList(operations));
}
 
Example #25
Source File: ReportingZooKeeperClient.java    From helios with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<CuratorTransactionResult> transaction(List<ZooKeeperOperation> operations)
    throws KeeperException {
  return reporter.time(tag, "transaction", () -> client.transaction(operations));
}
 
Example #26
Source File: ReportingZooKeeperClient.java    From helios with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<CuratorTransactionResult> transaction(ZooKeeperOperation... operations)
    throws KeeperException {
  return reporter.time(tag, "transaction", () -> client.transaction(operations));
}
 
Example #27
Source File: ZooKeeperClient.java    From helios with Apache License 2.0 4 votes vote down vote up
Collection<CuratorTransactionResult> transaction(List<ZooKeeperOperation> operations)
throws KeeperException;
 
Example #28
Source File: ZooKeeperClient.java    From helios with Apache License 2.0 4 votes vote down vote up
Collection<CuratorTransactionResult> transaction(ZooKeeperOperation... operations)
throws KeeperException;
 
Example #29
Source File: CuratorMultiTransactionImpl.java    From curator with Apache License 2.0 4 votes vote down vote up
@Override
public List<CuratorTransactionResult> forOperations(CuratorOp... operations) throws Exception
{
    List<CuratorOp> ops = (operations != null) ? Arrays.asList(operations) : Lists.<CuratorOp>newArrayList();
    return forOperations(ops);
}
 
Example #30
Source File: CuratorEventImpl.java    From curator with Apache License 2.0 4 votes vote down vote up
@Override
public List<CuratorTransactionResult> getOpResults()
{
    return opResults;
}