use of org.apache.curator.framework.api.transaction.CuratorTransaction in project druid by druid-io.
the class Announcer method stop.
@LifecycleStop
public void stop() {
synchronized (toAnnounce) {
if (!started) {
return;
}
started = false;
Closer closer = Closer.create();
for (PathChildrenCache cache : listeners.values()) {
closer.register(cache);
}
try {
CloseQuietly.close(closer);
} finally {
pathChildrenCacheExecutor.shutdown();
}
for (Map.Entry<String, ConcurrentMap<String, byte[]>> entry : announcements.entrySet()) {
String basePath = entry.getKey();
for (String announcementPath : entry.getValue().keySet()) {
unannounce(ZKPaths.makePath(basePath, announcementPath));
}
}
if (!parentsIBuilt.isEmpty()) {
CuratorTransaction transaction = curator.inTransaction();
for (String parent : parentsIBuilt) {
try {
transaction = transaction.delete().forPath(parent).and();
} catch (Exception e) {
log.info(e, "Unable to delete parent[%s], boooo.", parent);
}
}
try {
((CuratorTransactionFinal) transaction).commit();
} catch (Exception e) {
log.info(e, "Unable to commit transaction. Please feed the hamsters");
}
}
}
}
use of org.apache.curator.framework.api.transaction.CuratorTransaction 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.CuratorTransaction 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