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

The following examples show how to use org.apache.curator.framework.api.transaction.TransactionCreateBuilder. 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: JobNodeStorageTest.java    From shardingsphere-elasticjob-lite with Apache License 2.0 6 votes vote down vote up
@Test
public void assertExecuteInTransactionSuccess() throws Exception {
    CuratorFramework client = mock(CuratorFramework.class);
    CuratorTransaction curatorTransaction = mock(CuratorTransaction.class);
    TransactionCheckBuilder transactionCheckBuilder = mock(TransactionCheckBuilder.class);
    CuratorTransactionBridge curatorTransactionBridge = mock(CuratorTransactionBridge.class);
    CuratorTransactionFinal curatorTransactionFinal = mock(CuratorTransactionFinal.class);
    when(regCenter.getRawClient()).thenReturn(client);
    when(client.inTransaction()).thenReturn(curatorTransaction);
    when(curatorTransaction.check()).thenReturn(transactionCheckBuilder);
    when(transactionCheckBuilder.forPath("/")).thenReturn(curatorTransactionBridge);
    when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal);
    TransactionCreateBuilder transactionCreateBuilder = mock(TransactionCreateBuilder.class);
    when(curatorTransactionFinal.create()).thenReturn(transactionCreateBuilder);
    when(transactionCreateBuilder.forPath("/test_transaction")).thenReturn(curatorTransactionBridge);
    when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal);
    jobNodeStorage.executeInTransaction(curatorTransactionFinalForCallback -> curatorTransactionFinalForCallback.create().forPath("/test_transaction").and());
    verify(regCenter).getRawClient();
    verify(client).inTransaction();
    verify(curatorTransaction).check();
    verify(transactionCheckBuilder).forPath("/");
    verify(curatorTransactionBridge, times(2)).and();
    verify(curatorTransactionFinal).create();
    verify(transactionCreateBuilder).forPath("/test_transaction");
    verify(curatorTransactionFinal).commit();
}
 
Example #2
Source File: CuratorTransactionImpl.java    From xian with Apache License 2.0 5 votes vote down vote up
@Override
public TransactionCreateBuilder create()
{
    Preconditions.checkState(!isCommitted, "transaction already committed");

    return new CreateBuilderImpl(client).asTransactionCreateBuilder(this, transaction);
}
 
Example #3
Source File: ShardingServiceTest.java    From shardingsphere-elasticjob-lite with Apache License 2.0 5 votes vote down vote up
@Test
public void assertPersistShardingInfoTransactionExecutionCallback() throws Exception {
    CuratorTransactionFinal curatorTransactionFinal = mock(CuratorTransactionFinal.class);
    TransactionCreateBuilder transactionCreateBuilder = mock(TransactionCreateBuilder.class);
    TransactionDeleteBuilder transactionDeleteBuilder = mock(TransactionDeleteBuilder.class);
    CuratorTransactionBridge curatorTransactionBridge = mock(CuratorTransactionBridge.class);
    when(curatorTransactionFinal.create()).thenReturn(transactionCreateBuilder);
    when(transactionCreateBuilder.forPath("/test_job/sharding/0/instance", "host0@-@0".getBytes())).thenReturn(curatorTransactionBridge);
    when(transactionCreateBuilder.forPath("/test_job/sharding/1/instance", "host0@-@0".getBytes())).thenReturn(curatorTransactionBridge);
    when(transactionCreateBuilder.forPath("/test_job/sharding/2/instance", "host0@-@0".getBytes())).thenReturn(curatorTransactionBridge);
    when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal);
    when(curatorTransactionFinal.delete()).thenReturn(transactionDeleteBuilder);
    when(transactionDeleteBuilder.forPath("/test_job/leader/sharding/necessary")).thenReturn(curatorTransactionBridge);
    when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal);
    when(curatorTransactionFinal.delete()).thenReturn(transactionDeleteBuilder);
    when(transactionDeleteBuilder.forPath("/test_job/leader/sharding/processing")).thenReturn(curatorTransactionBridge);
    when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal);
    Map<JobInstance, List<Integer>> shardingResult = new HashMap<>();
    shardingResult.put(new JobInstance("host0@-@0"), Arrays.asList(0, 1, 2));
    ShardingService.PersistShardingInfoTransactionExecutionCallback actual = shardingService.new PersistShardingInfoTransactionExecutionCallback(shardingResult);
    actual.execute(curatorTransactionFinal);
    verify(curatorTransactionFinal, times(3)).create();
    verify(curatorTransactionFinal, times(2)).delete();
    verify(transactionDeleteBuilder).forPath("/test_job/leader/sharding/necessary");
    verify(transactionDeleteBuilder).forPath("/test_job/leader/sharding/processing");
    verify(curatorTransactionBridge, times(5)).and();
}
 
Example #4
Source File: MockCurator.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public TransactionCreateBuilder create() {
    ensureNotCommitted();
    return new MockTransactionCreateBuilder();
}
 
Example #5
Source File: TransactionOpImpl.java    From curator with Apache License 2.0 4 votes vote down vote up
@Override
public TransactionCreateBuilder<CuratorOp> create()
{
    ExtractingCuratorOp op = new ExtractingCuratorOp();
    return new CreateBuilderImpl(client).<CuratorOp>asTransactionCreateBuilder(op, op.getRecord());
}