Search in sources :

Example 1 with DeleteBuilder

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());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TimeUnit(java.util.concurrent.TimeUnit) BackgroundPathable(org.apache.curator.framework.api.BackgroundPathable) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) Test(org.junit.Test)

Example 2 with DeleteBuilder

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);
    }
}
Also used : PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 3 with DeleteBuilder

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;
}
Also used : DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with DeleteBuilder

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();
}
Also used : DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with DeleteBuilder

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"));
}
Also used : DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.jupiter.api.Test)

Aggregations

DeleteBuilder (org.apache.curator.framework.api.DeleteBuilder)24 Test (org.junit.jupiter.api.Test)12 KeeperException (org.apache.zookeeper.KeeperException)9 ExecutionException (java.util.concurrent.ExecutionException)3 TimeUnit (java.util.concurrent.TimeUnit)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 BackgroundPathable (org.apache.curator.framework.api.BackgroundPathable)3 Test (org.junit.Test)3 Matchers.anyBoolean (org.mockito.Matchers.anyBoolean)3 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 SetupStep (org.apache.atlas.setup.SetupStep)2 CreateBuilder (org.apache.curator.framework.api.CreateBuilder)2 ExistsBuilder (org.apache.curator.framework.api.ExistsBuilder)2 InterProcessMutex (org.apache.curator.framework.recipes.locks.InterProcessMutex)2 ACL (org.apache.zookeeper.data.ACL)2 Id (org.apache.zookeeper.data.Id)2 Test (org.testng.annotations.Test)2 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)1 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)1