Search in sources :

Example 1 with TransactionDeleteBuilder

use of org.apache.curator.framework.api.transaction.TransactionDeleteBuilder in project elastic-job by dangdangdotcom.

the class ShardingServiceTest method assertPersistShardingInfoTransactionExecutionCallback.

@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/servers/host0/sharding", "0,1,2".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<String, List<Integer>> shardingItems = new HashMap<>(1);
    shardingItems.put("host0", Arrays.asList(0, 1, 2));
    ShardingService.PersistShardingInfoTransactionExecutionCallback actual = shardingService.new PersistShardingInfoTransactionExecutionCallback(shardingItems);
    actual.execute(curatorTransactionFinal);
    verify(curatorTransactionFinal).create();
    verify(transactionCreateBuilder).forPath("/test_job/servers/host0/sharding", "0,1,2".getBytes());
    verify(curatorTransactionFinal, times(2)).delete();
    verify(transactionDeleteBuilder).forPath("/test_job/leader/sharding/necessary");
    verify(transactionDeleteBuilder).forPath("/test_job/leader/sharding/processing");
    verify(curatorTransactionBridge, times(3)).and();
}
Also used : TransactionCreateBuilder(org.apache.curator.framework.api.transaction.TransactionCreateBuilder) CuratorTransactionBridge(org.apache.curator.framework.api.transaction.CuratorTransactionBridge) HashMap(java.util.HashMap) CuratorTransactionFinal(org.apache.curator.framework.api.transaction.CuratorTransactionFinal) TransactionDeleteBuilder(org.apache.curator.framework.api.transaction.TransactionDeleteBuilder) List(java.util.List) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 List (java.util.List)1 CuratorTransactionBridge (org.apache.curator.framework.api.transaction.CuratorTransactionBridge)1 CuratorTransactionFinal (org.apache.curator.framework.api.transaction.CuratorTransactionFinal)1 TransactionCreateBuilder (org.apache.curator.framework.api.transaction.TransactionCreateBuilder)1 TransactionDeleteBuilder (org.apache.curator.framework.api.transaction.TransactionDeleteBuilder)1 Test (org.junit.Test)1