@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("/testJob/servers/host0/sharding", "0,1,2".getBytes())).thenReturn(curatorTransactionBridge); when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal); when(curatorTransactionFinal.delete()).thenReturn(transactionDeleteBuilder); when(transactionDeleteBuilder.forPath("/testJob/leader/sharding/necessary")).thenReturn(curatorTransactionBridge); when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal); when(curatorTransactionFinal.delete()).thenReturn(transactionDeleteBuilder); when(transactionDeleteBuilder.forPath("/testJob/leader/sharding/processing")).thenReturn(curatorTransactionBridge); when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal); Map<String, List<Integer>> shardingItems = new HashMap<String, List<Integer>>(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("/testJob/servers/host0/sharding", "0,1,2".getBytes()); verify(curatorTransactionFinal, times(2)).delete(); verify(transactionDeleteBuilder).forPath("/testJob/leader/sharding/necessary"); verify(transactionDeleteBuilder).forPath("/testJob/leader/sharding/processing"); verify(curatorTransactionBridge, times(3)).and(); }
@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("/testJob/servers/host0/sharding", "0,1,2".getBytes())).thenReturn(curatorTransactionBridge); when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal); when(curatorTransactionFinal.delete()).thenReturn(transactionDeleteBuilder); when(transactionDeleteBuilder.forPath("/testJob/leader/sharding/necessary")).thenReturn(curatorTransactionBridge); when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal); when(curatorTransactionFinal.delete()).thenReturn(transactionDeleteBuilder); when(transactionDeleteBuilder.forPath("/testJob/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("/testJob/servers/host0/sharding", "0,1,2".getBytes()); verify(curatorTransactionFinal, times(2)).delete(); verify(transactionDeleteBuilder).forPath("/testJob/leader/sharding/necessary"); verify(transactionDeleteBuilder).forPath("/testJob/leader/sharding/processing"); verify(curatorTransactionBridge, times(3)).and(); }
@Override public CuratorTransactionBridge forPath(String path, byte[] data) throws Exception { this.path = path; this.data = data; return returnMe; }
@Override public CuratorTransactionBridge forPath(String path) throws Exception { this.path = path; this.data = null; return returnMe; }
@Override public Pathable<CuratorTransactionBridge> withVersion(int version) { throw new UnsupportedOperationException(); }
@Override public ACLPathAndBytesable<CuratorTransactionBridge> withMode(CreateMode mode) { throw new UnsupportedOperationException(); }
@Override public PathAndBytesable<CuratorTransactionBridge> withACL(List<ACL> aclList) { throw new UnsupportedOperationException(); }
@Override public ACLPathAndBytesable<CuratorTransactionBridge> compressed() { throw new UnsupportedOperationException(); }
@Override public PathAndBytesable<CuratorTransactionBridge> withVersion(int version) { throw new UnsupportedOperationException(); }
@Override public PathAndBytesable<CuratorTransactionBridge> compressed() { throw new UnsupportedOperationException(); }
@Override public PathAndBytesable<CuratorTransactionBridge> withACL(List<ACL> list) { throw new UnsupportedOperationException("Not implemented in MockCurator"); }
@Override public ACLPathAndBytesable<CuratorTransactionBridge> compressed() { throw new UnsupportedOperationException("Not implemented in MockCurator"); }
@Override public ACLPathAndBytesable<CuratorTransactionBridge> withMode(CreateMode createMode) { this.createMode = createMode; return this; }
@Override public CuratorTransactionBridge forPath(String s, byte[] bytes) throws Exception { createNode(s, bytes, false, createMode, newRoot, delayedListener); return new MockCuratorTransactionBridge(); }
@Override public CuratorTransactionBridge forPath(String s) throws Exception { createNode(s, new byte[0], false, createMode, newRoot, delayedListener); return new MockCuratorTransactionBridge(); }
@Override public Pathable<CuratorTransactionBridge> withVersion(int i) { throw new UnsupportedOperationException("Not implemented in MockCurator"); }
@Override public CuratorTransactionBridge forPath(String path) throws Exception { deleteNode(path, false, newRoot, delayedListener); return new MockCuratorTransactionBridge(); }
@Override public PathAndBytesable<CuratorTransactionBridge> compressed() { throw new UnsupportedOperationException("Not implemented in MockCurator"); }
@Override public PathAndBytesable<CuratorTransactionBridge> withVersion(int i) { throw new UnsupportedOperationException("Not implemented in MockCurator"); }
@Override public CuratorTransactionBridge forPath(String s, byte[] bytes) throws Exception { MockCurator.this.setData(s, bytes, newRoot, delayedListener); return new MockCuratorTransactionBridge(); }
@Override public CuratorTransactionBridge forPath(String s) throws Exception { MockCurator.this.setData(s, new byte[0], newRoot, delayedListener); return new MockCuratorTransactionBridge(); }