org.apache.curator.framework.api.DeleteBuilder Java Examples
The following examples show how to use
org.apache.curator.framework.api.DeleteBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZookeeperClient.java From flow-platform-x with Apache License 2.0 | 6 votes |
public void delete(String path, boolean isDeleteChildren) { try { if (!exist(path)) { return; } DeleteBuilder builder = client.delete(); if (isDeleteChildren) { builder.guaranteed().deletingChildrenIfNeeded().forPath(path); return; } builder.guaranteed().forPath(path); } catch (Throwable e) { throw new ZookeeperException("Fail to delete node of path: {0}", e.getMessage()); } }
Example #2
Source File: SetupStepsTest.java From atlas with Apache License 2.0 | 6 votes |
@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); }
Example #3
Source File: ZookeeperClient.java From flow-platform-x with Apache License 2.0 | 6 votes |
public void delete(String path, boolean isDeleteChildren) { try { if (!exist(path)) { return; } DeleteBuilder builder = client.delete(); if (isDeleteChildren) { builder.guaranteed().deletingChildrenIfNeeded().forPath(path); return; } builder.guaranteed().forPath(path); } catch (Throwable e) { throw new ZookeeperException("Fail to delete node of path: {0}", e.getMessage()); } }
Example #4
Source File: SetupStepsTest.java From incubator-atlas with Apache License 2.0 | 6 votes |
@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); }
Example #5
Source File: SensorEnrichmentConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@Test public void deleteShouldReturnTrueWhenClientSuccessfullyCallsDelete() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); doNothing().when(builder).forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro"); assertTrue(sensorEnrichmentConfigService.delete("bro")); verify(curatorFramework).delete(); }
Example #6
Source File: SensorEnrichmentConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@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")); }
Example #7
Source File: SensorEnrichmentConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@Test public void deleteShouldProperlyCatchNoNodeExceptionAndReturnFalse() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); when(builder.forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro")).thenThrow(KeeperException.NoNodeException.class); assertFalse(sensorEnrichmentConfigService.delete("bro")); }
Example #8
Source File: SensorParserConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@Test public void deleteShouldReturnTrueWhenClientSuccessfullyCallsDelete() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); assertTrue(sensorParserConfigService.delete("bro")); verify(curatorFramework).delete(); }
Example #9
Source File: SensorParserConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@Test public void deleteShouldProperlyCatchNonNoNodeExceptionAndThrowRestException() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); when(builder.forPath(ConfigurationType.PARSER.getZookeeperRoot() + "/bro")).thenThrow(Exception.class); assertThrows(RestException.class, () -> sensorParserConfigService.delete("bro")); }
Example #10
Source File: SensorParserConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@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")); }
Example #11
Source File: GlobalConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@Test public void deleteShouldReturnTrueWhenClientSuccessfullyCallsDelete() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); assertTrue(globalConfigService.delete()); verify(curatorFramework).delete(); }
Example #12
Source File: GlobalConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@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())); }
Example #13
Source File: GlobalConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@Test public void deleteShouldProperlyCatchNoNodeExceptionAndReturnFalse() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); when(builder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot())).thenThrow(KeeperException.NoNodeException.class); assertFalse(globalConfigService.delete()); }
Example #14
Source File: SensorIndexingConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@Test public void deleteShouldReturnTrueWhenClientSuccessfullyCallsDelete() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); assertTrue(sensorIndexingConfigService.delete("bro")); verify(curatorFramework).delete(); }
Example #15
Source File: SensorIndexingConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@Test public void deleteShouldProperlyCatchNonNoNodeExceptionAndThrowRestException() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); when(builder.forPath(ConfigurationType.INDEXING.getZookeeperRoot() + "/bro")).thenThrow(Exception.class); assertThrows(RestException.class, () -> sensorIndexingConfigService.delete("bro")); }
Example #16
Source File: SensorIndexingConfigServiceImplTest.java From metron with Apache License 2.0 | 5 votes |
@Test public void deleteShouldProperlyCatchNoNodeExceptionAndReturnFalse() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); when(builder.forPath(ConfigurationType.INDEXING.getZookeeperRoot() + "/bro")).thenThrow(KeeperException.NoNodeException.class); assertFalse(sensorIndexingConfigService.delete("bro")); }
Example #17
Source File: SetupStepsTest.java From incubator-atlas with Apache License 2.0 | 5 votes |
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; }
Example #18
Source File: CuratorStateManagerTest.java From incubator-heron with Apache License 2.0 | 5 votes |
/** * 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()); }
Example #19
Source File: ZookeeperBackendService.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
@Override public void remove(String uuid, Handler<AsyncResult<Record>> resultHandler) { Objects.requireNonNull(uuid, "No registration id in the record"); Context context = Vertx.currentContext(); ensureConnected(x -> { if (x.failed()) { resultHandler.handle(Future.failedFuture(x.cause())); } else { getRecordById(context, uuid, record -> { if (record == null) { resultHandler.handle(Future.failedFuture("Unknown registration " + uuid)); } else { try { DeleteBuilder delete = client.delete(); if (guaranteed) { delete.guaranteed(); } delete .deletingChildrenIfNeeded() .inBackground((curatorFramework, curatorEvent) -> callback(context, record, resultHandler, curatorEvent)) .withUnhandledErrorListener((s, throwable) -> resultHandler.handle(Future.failedFuture(throwable))) .forPath(getPath(uuid)); } catch (Exception e) { resultHandler.handle(Future.failedFuture(e)); } } }); } }); }
Example #20
Source File: CuratorHelperTest.java From storm-dynamic-spout with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Tests that if we attempt to delete a node that doesnt actually exist * just silently returns. * * To simulate a race condition we do this using mocks. */ @Test public void testDeleteNodeIfNoChildren_withNodeThatDoesntExist() throws Exception { final String basePath = "/testDeleteNodeIfNoChildren_withNodeThatDoesntExist"; final CuratorFramework mockCurator = mock(CuratorFramework.class); // Exists builder should return true saying our basePath exists. final ExistsBuilder mockExistsBuilder = mock(ExistsBuilder.class); when(mockExistsBuilder.forPath(eq(basePath))).thenReturn(new Stat()); when(mockCurator.checkExists()).thenReturn(mockExistsBuilder); // When we look for children, make sure it returns an empty list. final GetChildrenBuilder mockGetChildrenBuilder = mock(GetChildrenBuilder.class); when(mockGetChildrenBuilder.forPath(eq(basePath))).thenReturn(new ArrayList<>()); when(mockCurator.getChildren()).thenReturn(mockGetChildrenBuilder); // When we go to delete the actual node, we toss a no-node exception. // This effectively simulates a race condition between checking if the node exists (our mock above says yes) // and it being removed before we call delete on it. final DeleteBuilder mockDeleteBuilder = mock(DeleteBuilder.class); when(mockDeleteBuilder.forPath(eq(basePath))).thenThrow(new KeeperException.NoNodeException()); when(mockCurator.delete()).thenReturn(mockDeleteBuilder); // Now create our helper final CuratorHelper curatorHelper = new CuratorHelper(mockCurator, new HashMap<>()); // Call our method curatorHelper.deleteNodeIfNoChildren(basePath); }
Example #21
Source File: SetupStepsTest.java From atlas with Apache License 2.0 | 5 votes |
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; }
Example #22
Source File: ZKUtil.java From PoseidonX with Apache License 2.0 | 5 votes |
/** * 删除节点 * @param curator * @param path * @param recursive * @param backgroundCallback * @throws Exception */ public static void zkDelete(CuratorFramework curator, String path, boolean recursive, BackgroundCallback backgroundCallback) throws Exception { DeleteBuilder delete = curator.delete(); if(recursive) { delete.deletingChildrenIfNeeded(); } if(backgroundCallback != null) { delete.inBackground(backgroundCallback); } delete.forPath(path); }
Example #23
Source File: SetupStepsTest.java From incubator-atlas with Apache License 2.0 | 4 votes |
private Pair<CreateBuilder, DeleteBuilder> setupSetupInProgressPathMocks(List<ACL> acls) throws Exception { return setupSetupInProgressPathMocks(acls, null); }
Example #24
Source File: MockCurator.java From vespa with Apache License 2.0 | 4 votes |
@Override public DeleteBuilder delete() { return new MockDeleteBuilder(); }
Example #25
Source File: SetupStepsTest.java From atlas with Apache License 2.0 | 4 votes |
private Pair<CreateBuilder, DeleteBuilder> setupSetupInProgressPathMocks(List<ACL> acls) throws Exception { return setupSetupInProgressPathMocks(acls, null); }