use of org.apache.curator.framework.api.DeleteBuilder in project heron by twitter.
the class CuratorStateManagerTest method testDeleteNode.
/**
* Test deleteNode method
* @throws Exception
*/
@Test
public void testDeleteNode() throws Exception {
CuratorStateManager spyStateManager = spy(new CuratorStateManager());
CuratorFramework mockClient = mock(CuratorFramework.class);
DeleteBuilder mockDeleteBuilder = mock(DeleteBuilder.class);
// Mockito doesn't support mock type-parametrized class, thus suppress the warning
@SuppressWarnings("rawtypes") BackgroundPathable mockBackPathable = mock(BackgroundPathable.class);
doReturn(mockClient).when(spyStateManager).getCuratorClient();
doReturn(true).when(mockClient).blockUntilConnected(anyInt(), any(TimeUnit.class));
doReturn(mockDeleteBuilder).when(mockClient).delete();
doReturn(mockBackPathable).when(mockDeleteBuilder).withVersion(-1);
spyStateManager.initialize(config);
ListenableFuture<Boolean> result = spyStateManager.deleteExecutionState(PATH);
// Verify the node is deleted correctly
verify(mockDeleteBuilder).withVersion(-1);
assertTrue(result.get());
}
use of org.apache.curator.framework.api.DeleteBuilder in project coprhd-controller by CoprHD.
the class CoordinatorClientImpl method deletePath.
@Override
public void deletePath(String path) {
try {
if (_zkConnection.curator().checkExists().forPath(path) == null) {
log.info("Skip path deletion since {} doesn't exist", path);
return;
}
List<String> subPaths = _zkConnection.curator().getChildren().forPath(path);
for (String subPath : subPaths) {
log.info("Subpath {}/{} is going to be deleted", path, subPath);
}
DeleteBuilder deleteOp = _zkConnection.curator().delete();
deleteOp.deletingChildrenIfNeeded();
deleteOp.forPath(path);
} catch (Exception ex) {
log.error("Failed to delete ZK path: {}", path, ex);
throw CoordinatorException.fatals.unableToDeletePath(path, ex);
}
}
use of org.apache.curator.framework.api.DeleteBuilder in project incubator-heron by apache.
the class CuratorStateManager method deleteNode.
@Override
protected ListenableFuture<Boolean> deleteNode(String path, boolean deleteChildrenIfNecessary) {
final SettableFuture<Boolean> result = SettableFuture.create();
try {
DeleteBuilder deleteBuilder = client.delete();
if (deleteChildrenIfNecessary) {
deleteBuilder = (DeleteBuilder) deleteBuilder.deletingChildrenIfNeeded();
}
deleteBuilder.withVersion(-1).forPath(path);
LOG.info("Deleted node for path: " + path);
safeSetFuture(result, true);
} catch (KeeperException e) {
if (KeeperException.Code.NONODE.equals(e.code())) {
safeSetFuture(result, true);
} else {
safeSetException(result, new RuntimeException("Could not deleteNode", e));
}
// Suppress it since forPath() throws Exception
// SUPPRESS CHECKSTYLE IllegalCatch
} catch (Exception e) {
safeSetException(result, new RuntimeException("Could not deleteNode", e));
}
return result;
}
use of org.apache.curator.framework.api.DeleteBuilder in project metron by apache.
the class SensorParserConfigServiceImplTest method deleteShouldReturnTrueWhenClientSuccessfullyCallsDelete.
@Test
public void deleteShouldReturnTrueWhenClientSuccessfullyCallsDelete() throws Exception {
DeleteBuilder builder = mock(DeleteBuilder.class);
when(curatorFramework.delete()).thenReturn(builder);
assertTrue(sensorParserConfigService.delete("bro"));
verify(curatorFramework).delete();
}
use of org.apache.curator.framework.api.DeleteBuilder in project metron by apache.
the class SensorParserConfigServiceImplTest method deleteShouldProperlyCatchNoNodeExceptionAndReturnFalse.
@Test
public void deleteShouldProperlyCatchNoNodeExceptionAndReturnFalse() throws Exception {
DeleteBuilder builder = mock(DeleteBuilder.class);
when(curatorFramework.delete()).thenReturn(builder);
when(builder.forPath(ConfigurationType.PARSER.getZookeeperRoot() + "/bro")).thenThrow(KeeperException.NoNodeException.class);
assertFalse(sensorParserConfigService.delete("bro"));
}
Aggregations