Search in sources :

Example 21 with DeleteBuilder

use of org.apache.curator.framework.api.DeleteBuilder in project metron by apache.

the class SensorEnrichmentConfigServiceImplTest method deleteShouldProperlyCatchNonNoNodeExceptionAndThrowRestException.

@Test
public void deleteShouldProperlyCatchNonNoNodeExceptionAndThrowRestException() throws Exception {
    DeleteBuilder builder = mock(DeleteBuilder.class);
    when(curatorFramework.delete()).thenReturn(builder);
    when(builder.forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro")).thenThrow(Exception.class);
    assertThrows(RestException.class, () -> sensorEnrichmentConfigService.delete("bro"));
}
Also used : DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) Test(org.junit.jupiter.api.Test)

Example 22 with DeleteBuilder

use of org.apache.curator.framework.api.DeleteBuilder in project metron by apache.

the class GlobalConfigServiceImplTest method deleteShouldProperlyCatchNonNoNodeExceptionAndThrowRestException.

@Test
public void deleteShouldProperlyCatchNonNoNodeExceptionAndThrowRestException() throws Exception {
    DeleteBuilder builder = mock(DeleteBuilder.class);
    when(curatorFramework.delete()).thenReturn(builder);
    when(builder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot())).thenThrow(Exception.class);
    assertThrows(RestException.class, () -> assertFalse(globalConfigService.delete()));
}
Also used : DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) Test(org.junit.jupiter.api.Test)

Example 23 with DeleteBuilder

use of org.apache.curator.framework.api.DeleteBuilder in project incubator-atlas by apache.

the class SetupStepsTest method shouldDeleteSetupInProgressNodeAfterCompletion.

@Test
public void shouldDeleteSetupInProgressNodeAfterCompletion() throws Exception {
    Set<SetupStep> steps = new LinkedHashSet<>();
    SetupStep setupStep1 = mock(SetupStep.class);
    steps.add(setupStep1);
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
    when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("digest:user:pwd");
    List<ACL> aclList = Arrays.asList(new ACL(ZooDefs.Perms.ALL, new Id("digest", "user:pwd")));
    setupServerIdSelectionMocks();
    DeleteBuilder deleteBuilder = setupSetupInProgressPathMocks(aclList).getRight();
    InterProcessMutex lock = mock(InterProcessMutex.class);
    when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(lock);
    SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
    setupSteps.runSetup();
    verify(deleteBuilder).forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT + SetupSteps.SETUP_IN_PROGRESS_NODE);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ACL(org.apache.zookeeper.data.ACL) SetupStep(org.apache.atlas.setup.SetupStep) Id(org.apache.zookeeper.data.Id) DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder) InterProcessMutex(org.apache.curator.framework.recipes.locks.InterProcessMutex) Test(org.testng.annotations.Test)

Example 24 with DeleteBuilder

use of org.apache.curator.framework.api.DeleteBuilder in project incubator-atlas by apache.

the class SetupStepsTest method setupSetupInProgressPathMocks.

private Pair<CreateBuilder, DeleteBuilder> setupSetupInProgressPathMocks(List<ACL> acls, Stat stat) throws Exception {
    when(curatorFactory.clientInstance()).thenReturn(client);
    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(createBuilder.withACL(acls)).thenReturn(createBuilder);
    when(client.create()).thenReturn(createBuilder);
    DeleteBuilder deleteBuilder = mock(DeleteBuilder.class);
    when(client.delete()).thenReturn(deleteBuilder);
    Pair<CreateBuilder, DeleteBuilder> pair = Pair.of(createBuilder, deleteBuilder);
    ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
    when(client.checkExists()).thenReturn(existsBuilder);
    when(existsBuilder.forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT + SetupSteps.SETUP_IN_PROGRESS_NODE)).thenReturn(stat);
    return pair;
}
Also used : CreateBuilder(org.apache.curator.framework.api.CreateBuilder) ExistsBuilder(org.apache.curator.framework.api.ExistsBuilder) DeleteBuilder(org.apache.curator.framework.api.DeleteBuilder)

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