use of org.apache.curator.framework.api.transaction.CuratorTransactionBridge in project elastic-job by dangdangdotcom.
the class JobNodeStorageTest method assertExecuteInTransactionFailure.
@Test(expected = RuntimeException.class)
public void assertExecuteInTransactionFailure() 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()).thenThrow(new RuntimeException());
jobNodeStorage.executeInTransaction(new TransactionExecutionCallback() {
@Override
public void execute(final CuratorTransactionFinal curatorTransactionFinal) throws Exception {
curatorTransactionFinal.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, times(0)).commit();
}
use of org.apache.curator.framework.api.transaction.CuratorTransactionBridge 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();
}
use of org.apache.curator.framework.api.transaction.CuratorTransactionBridge in project elastic-job by dangdangdotcom.
the class JobNodeStorageTest method assertExecuteInTransactionSuccess.
@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(new TransactionExecutionCallback() {
@Override
public void execute(final CuratorTransactionFinal curatorTransactionFinal) throws Exception {
curatorTransactionFinal.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();
}
Aggregations