org.apache.curator.utils.EnsurePath Java Examples
The following examples show how to use
org.apache.curator.utils.EnsurePath.
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: TestEnsurePath.java From xian with Apache License 2.0 | 6 votes |
@Test public void testBasic() throws Exception { ZooKeeper client = mock(ZooKeeper.class, Mockito.RETURNS_MOCKS); CuratorZookeeperClient curator = mock(CuratorZookeeperClient.class); RetryPolicy retryPolicy = new RetryOneTime(1); RetryLoop retryLoop = new RetryLoop(retryPolicy, null); when(curator.getZooKeeper()).thenReturn(client); when(curator.getRetryPolicy()).thenReturn(retryPolicy); when(curator.newRetryLoop()).thenReturn(retryLoop); Stat fakeStat = mock(Stat.class); when(client.exists(Mockito.<String>any(), anyBoolean())).thenReturn(fakeStat); EnsurePath ensurePath = new EnsurePath("/one/two/three"); ensurePath.ensure(curator); verify(client, times(3)).exists(Mockito.<String>any(), anyBoolean()); ensurePath.ensure(curator); verifyNoMoreInteractions(client); ensurePath.ensure(curator); verifyNoMoreInteractions(client); }
Example #2
Source File: TestEnsurePath.java From curator with Apache License 2.0 | 6 votes |
@Test public void testBasic() throws Exception { ZooKeeper client = mock(ZooKeeper.class, Mockito.RETURNS_MOCKS); CuratorZookeeperClient curator = mock(CuratorZookeeperClient.class); RetryPolicy retryPolicy = new RetryOneTime(1); RetryLoop retryLoop = new RetryLoopImpl(retryPolicy, null); when(curator.getZooKeeper()).thenReturn(client); when(curator.getRetryPolicy()).thenReturn(retryPolicy); when(curator.newRetryLoop()).thenReturn(retryLoop); Stat fakeStat = mock(Stat.class); when(client.exists(Mockito.<String>any(), anyBoolean())).thenReturn(fakeStat); EnsurePath ensurePath = new EnsurePath("/one/two/three"); ensurePath.ensure(curator); verify(client, times(3)).exists(Mockito.<String>any(), anyBoolean()); ensurePath.ensure(curator); verifyNoMoreInteractions(client); ensurePath.ensure(curator); verifyNoMoreInteractions(client); }
Example #3
Source File: TestFramework.java From curator with Apache License 2.0 | 6 votes |
@Test public void testEnsurePathWithNamespace() throws Exception { final String namespace = "jz"; CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); CuratorFramework client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).namespace(namespace).build(); client.start(); try { EnsurePath ensurePath = new EnsurePath("/pity/the/fool"); ensurePath.ensure(client.getZookeeperClient()); Assert.assertNull(client.getZookeeperClient().getZooKeeper().exists("/jz/pity/the/fool", false)); ensurePath = client.newNamespaceAwareEnsurePath("/pity/the/fool"); ensurePath.ensure(client.getZookeeperClient()); Assert.assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/jz/pity/the/fool", false)); } finally { CloseableUtils.closeQuietly(client); } }
Example #4
Source File: TestFramework.java From xian with Apache License 2.0 | 6 votes |
@Test public void testEnsurePathWithNamespace() throws Exception { final String namespace = "jz"; CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); CuratorFramework client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).namespace(namespace).build(); client.start(); try { EnsurePath ensurePath = new EnsurePath("/pity/the/fool"); ensurePath.ensure(client.getZookeeperClient()); Assert.assertNull(client.getZookeeperClient().getZooKeeper().exists("/jz/pity/the/fool", false)); ensurePath = client.newNamespaceAwareEnsurePath("/pity/the/fool"); ensurePath.ensure(client.getZookeeperClient()); Assert.assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/jz/pity/the/fool", false)); } finally { CloseableUtils.closeQuietly(client); } }
Example #5
Source File: MasterRespondsWithNoZkTest.java From helios with Apache License 2.0 | 5 votes |
@Override public CuratorFramework newClient(final String connectString, final int sessionTimeoutMs, final int connectionTimeoutMs, final RetryPolicy retryPolicy, final ACLProvider aclProvider, final List<AuthInfo> authorization) { final CuratorFramework curator = mock(CuratorFramework.class); final RetryLoop retryLoop = mock(RetryLoop.class); when(retryLoop.shouldContinue()).thenReturn(false); final CuratorZookeeperClient czkClient = mock(CuratorZookeeperClient.class); when(czkClient.newRetryLoop()).thenReturn(retryLoop); when(curator.getZookeeperClient()).thenReturn(czkClient); @SuppressWarnings("unchecked") final Listenable<ConnectionStateListener> mockListener = (Listenable<ConnectionStateListener>) mock(Listenable.class); when(curator.getConnectionStateListenable()).thenReturn(mockListener); final GetChildrenBuilder builder = mock(GetChildrenBuilder.class); when(curator.getChildren()).thenReturn(builder); try { when(builder.forPath(anyString())).thenThrow( new KeeperException.ConnectionLossException()); } catch (Exception ignored) { // never throws } when(curator.newNamespaceAwareEnsurePath(anyString())).thenReturn(mock(EnsurePath.class)); return curator; }
Example #6
Source File: LeaseManager.java From phoenix-omid with Apache License 2.0 | 5 votes |
private void validateZKPath(String zkPath) throws Exception { EnsurePath path = zkClient.newNamespaceAwareEnsurePath(zkPath); path.ensure(zkClient.getZookeeperClient()); Stat stat = zkClient.checkExists().forPath(zkPath); Preconditions.checkNotNull(stat); LOG.info("Path {} ensured", path.getPath()); }
Example #7
Source File: TestAbstractZooKeeperConfigurationProvider.java From pulsar with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { // start the instance without the admin server! InstanceSpec serverSpec = new InstanceSpec(null, -1, -1, -1, true, -1, -1, -1, Collections.singletonMap("zookeeper.admin.enableServer", "false")); zkServer = new TestingServer(serverSpec, true); client = CuratorFrameworkFactory .newClient("localhost:" + zkServer.getPort(), new ExponentialBackoffRetry(1000, 3)); client.start(); EnsurePath ensurePath = new EnsurePath(AGENT_PATH); ensurePath.ensure(client.getZookeeperClient()); doSetUp(); }
Example #8
Source File: ZkSubscriptionHandler.java From seldon-server with Apache License 2.0 | 5 votes |
public void addSubscription(String location, TreeCacheListener listener) throws Exception { CuratorFramework client = curator.getCurator(); EnsurePath ensureMvTestPath = new EnsurePath(location); ensureMvTestPath.ensure(client.getZookeeperClient()); TreeCache cache = new TreeCache(client, location); cache.getListenable().addListener(listener); cache.start(); caches.put(location, cache); logger.info("Added ZooKeeper subscriber for " + location + " children."); }
Example #9
Source File: ZKAssistedDiscovery.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
public void doAdvertise(Service<byte[]> service, boolean flag) { try { new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient()); ServiceInstance<byte[]> instance = getInstance(service); if (flag) { discovery.registerService(instance); } else { discovery.unregisterService(instance); } } catch (Exception e) { throw Throwables.propagate(e); } }
Example #10
Source File: CuratorManager.java From snowizard-discovery with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void start() throws Exception { // framework was already started in ctor, // ensure that the root path is available new EnsurePath("/").ensure(framework.getZookeeperClient()); }
Example #11
Source File: TestEnsurePath.java From curator with Apache License 2.0 | 4 votes |
@Test public void testSimultaneous() throws Exception { ZooKeeper client = mock(ZooKeeper.class, Mockito.RETURNS_MOCKS); RetryPolicy retryPolicy = new RetryOneTime(1); RetryLoop retryLoop = new RetryLoopImpl(retryPolicy, null); final CuratorZookeeperClient curator = mock(CuratorZookeeperClient.class); when(curator.getZooKeeper()).thenReturn(client); when(curator.getRetryPolicy()).thenReturn(retryPolicy); when(curator.newRetryLoop()).thenReturn(retryLoop); final Stat fakeStat = mock(Stat.class); final CountDownLatch startedLatch = new CountDownLatch(2); final CountDownLatch finishedLatch = new CountDownLatch(2); final Semaphore semaphore = new Semaphore(0); when(client.exists(Mockito.<String>any(), anyBoolean())).thenAnswer ( new Answer<Stat>() { @Override public Stat answer(InvocationOnMock invocation) throws Throwable { semaphore.acquire(); return fakeStat; } } ); final EnsurePath ensurePath = new EnsurePath("/one/two/three"); ExecutorService service = Executors.newCachedThreadPool(); for ( int i = 0; i < 2; ++i ) { service.submit ( new Callable<Void>() { @Override public Void call() throws Exception { startedLatch.countDown(); ensurePath.ensure(curator); finishedLatch.countDown(); return null; } } ); } Assert.assertTrue(startedLatch.await(10, TimeUnit.SECONDS)); semaphore.release(3); Assert.assertTrue(finishedLatch.await(10, TimeUnit.SECONDS)); verify(client, times(3)).exists(Mockito.<String>any(), anyBoolean()); ensurePath.ensure(curator); verifyNoMoreInteractions(client); ensurePath.ensure(curator); verifyNoMoreInteractions(client); }
Example #12
Source File: NamespaceImpl.java From curator with Apache License 2.0 | 4 votes |
EnsurePath newNamespaceAwareEnsurePath(String path) { return new EnsurePath(fixForNamespace(path, false), client.getAclProvider()); }
Example #13
Source File: WatcherRemovalFacade.java From curator with Apache License 2.0 | 4 votes |
@Override public EnsurePath newNamespaceAwareEnsurePath(String path) { return client.newNamespaceAwareEnsurePath(path); }
Example #14
Source File: CuratorFrameworkImpl.java From curator with Apache License 2.0 | 4 votes |
@Override public EnsurePath newNamespaceAwareEnsurePath(String path) { return namespace.newNamespaceAwareEnsurePath(path); }
Example #15
Source File: NamespaceFacade.java From curator with Apache License 2.0 | 4 votes |
@Override public EnsurePath newNamespaceAwareEnsurePath(String path) { return namespace.newNamespaceAwareEnsurePath(path); }
Example #16
Source File: ZKAssistedDiscovery.java From attic-apex-malhar with Apache License 2.0 | 4 votes |
@Override public Collection<Service<byte[]>> discover() { try { new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient()); Collection<ServiceInstance<byte[]>> services = discovery.queryForInstances(serviceName); ArrayList<Service<byte[]>> returnable = new ArrayList<Service<byte[]>>(services.size()); for (final ServiceInstance<byte[]> service : services) { returnable.add(new Service<byte[]>() { @Override public String getHost() { return service.getAddress(); } @Override public int getPort() { return service.getPort(); } @Override public byte[] getPayload() { return service.getPayload(); } @Override public String getId() { return service.getId(); } @Override public String toString() { return "{" + getId() + " => " + getHost() + ':' + getPort() + '}'; } }); } return returnable; } catch (Exception e) { throw Throwables.propagate(e); } }
Example #17
Source File: MockCurator.java From vespa with Apache License 2.0 | 4 votes |
@Deprecated @Override public EnsurePath newNamespaceAwareEnsurePath(String path) { return new EnsurePath(path); }
Example #18
Source File: DataStoreModuleTest.java From emodb with Apache License 2.0 | 4 votes |
private Injector createInjector(final EmoServiceMode serviceMode) { // Mock the minimal CacheRegistry functionality required to instantiate the module final CacheRegistry rootCacheRegistry = mock(CacheRegistry.class); CacheRegistry sorCacheRegistry = mock(CacheRegistry.class); when(rootCacheRegistry.withNamespace(eq("sor"))).thenReturn(sorCacheRegistry); final CuratorFramework curator = mock(CuratorFramework.class); when(curator.getState()).thenReturn(CuratorFrameworkState.STARTED); when(curator.newNamespaceAwareEnsurePath(Mockito.<String>any())).thenReturn(mock(EnsurePath.class)); Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { binder().requireExplicitBindings(); DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration() .setHistoryTtl(Duration.ofDays(2)) .setValidTablePlacements(ImmutableSet.of("app_global:sys")) .setCassandraClusters(ImmutableMap.of("app_global", new CassandraConfiguration() .setCluster("Test Cluster") .setSeeds("127.0.0.1") .setPartitioner("bop") .setKeyspaces(ImmutableMap.of( "app_global", new KeyspaceConfiguration())))); // construct the minimum necessary elements to allow a DataStore module to be created. bind(DataStoreConfiguration.class).toInstance(dataStoreConfiguration); bind(String.class).annotatedWith(SystemTablePlacement.class).toInstance("app_global:sys"); bind(DataStore.class).annotatedWith(SystemDataStore.class).toInstance(mock(DataStore.class)); bind(DataCenterConfiguration.class).toInstance(new DataCenterConfiguration() .setSystemDataCenter("datacenter1") .setCurrentDataCenter("datacenter1")); bind(CqlDriverConfiguration.class).toInstance(new CqlDriverConfiguration()); bind(HostAndPort.class).annotatedWith(SelfHostAndPort.class).toInstance(HostAndPort.fromString("localhost:8080")); bind(Client.class).toInstance(mock(Client.class)); bind(CacheRegistry.class).toInstance(rootCacheRegistry); bind(DataCenters.class).toInstance(mock(DataCenters.class)); bind(HealthCheckRegistry.class).toInstance(mock(HealthCheckRegistry.class)); bind(LeaderServiceTask.class).toInstance(mock(LeaderServiceTask.class)); bind(LifeCycleRegistry.class).toInstance(new SimpleLifeCycleRegistry()); bind(TaskRegistry.class).toInstance(mock(TaskRegistry.class)); bind(CuratorFramework.class).annotatedWith(Global.class).toInstance(curator); bind(CuratorFramework.class).annotatedWith(DataStoreZooKeeper.class).toInstance(curator); bind(CuratorFramework.class).annotatedWith(GlobalFullConsistencyZooKeeper.class).toInstance(curator); bind(ClusterInfo.class).toInstance(new ClusterInfo("Test Cluster", "Test Metric Cluster")); bind(MetricRegistry.class).asEagerSingleton(); bind(JobService.class).toInstance(mock(JobService.class)); bind(JobHandlerRegistry.class).toInstance(mock(JobHandlerRegistry.class)); bind(new TypeLiteral<Supplier<Boolean>>(){}).annotatedWith(CqlForMultiGets.class).toInstance(Suppliers.ofInstance(true)); bind(new TypeLiteral<Supplier<Boolean>>(){}).annotatedWith(CqlForScans.class).toInstance(Suppliers.ofInstance(true)); bind(Clock.class).toInstance(Clock.systemDefaultZone()); bind(String.class).annotatedWith(CompControlApiKey.class).toInstance("CompControlApiKey"); bind(CompactionControlSource.class).annotatedWith(LocalCompactionControl.class).toInstance(mock(CompactionControlSource.class)); bind(ObjectMapper.class).toInstance(mock(ObjectMapper.class)); install(new DataStoreModule(serviceMode)); } }); verify(rootCacheRegistry).withNamespace("sor"); //noinspection unchecked verify(sorCacheRegistry).register(eq("tables"), isA(Cache.class), eq(true)); return injector; }
Example #19
Source File: DatabusModuleTest.java From emodb with Apache License 2.0 | 4 votes |
private Injector createInjector(final EmoServiceMode serviceMode) { // Mock the minimal CacheRegistry functionality required to instantiate the module final CacheRegistry rootCacheRegistry = mock(CacheRegistry.class); CacheRegistry sorCacheRegistry = mock(CacheRegistry.class); when(rootCacheRegistry.withNamespace(eq("bus"))).thenReturn(sorCacheRegistry); final CuratorFramework curator = mock(CuratorFramework.class); when(curator.getState()).thenReturn(CuratorFrameworkState.STARTED); when(curator.newNamespaceAwareEnsurePath(Mockito.<String>any())).thenReturn(mock(EnsurePath.class)); return Guice.createInjector(new AbstractModule() { @Override protected void configure() { binder().requireExplicitBindings(); // construct the minimum necessary elements to allow a Databus module to be created. bind(DatabusConfiguration.class).toInstance(new DatabusConfiguration() .setCassandraConfiguration(new CassandraConfiguration() .setCluster("Test Cluster") .setSeeds("127.0.0.1") .setPartitioner("random") .setKeyspaces(ImmutableMap.of( "random", new KeyspaceConfiguration())))); bind(CacheRegistry.class).toInstance(rootCacheRegistry); bind(DataCenters.class).toInstance(mock(DataCenters.class)); bind(HealthCheckRegistry.class).toInstance(mock(HealthCheckRegistry.class)); bind(LeaderServiceTask.class).toInstance(mock(LeaderServiceTask.class)); bind(LifeCycleRegistry.class).toInstance(new SimpleLifeCycleRegistry()); bind(TaskRegistry.class).toInstance(mock(TaskRegistry.class)); bind(HostAndPort.class).annotatedWith(SelfHostAndPort.class).toInstance(HostAndPort.fromString("localhost:8080")); bind(Client.class).toInstance(mock(Client.class)); bind(DataProvider.class).toInstance(mock(DataProvider.class)); bind(Placements.class).toInstance(mock(Placements.class)); bind(DatabusEventWriterRegistry.class).asEagerSingleton(); bind(CuratorFramework.class).annotatedWith(Global.class).toInstance(curator); bind(CuratorFramework.class).annotatedWith(DatabusZooKeeper.class).toInstance(curator); bind(HostDiscovery.class).annotatedWith(DatabusHostDiscovery.class).toInstance(mock(HostDiscovery.class)); bind(String.class).annotatedWith(ReplicationKey.class).toInstance("password"); bind(String.class).annotatedWith(SystemIdentity.class).toInstance("system"); bind(new TypeLiteral<Collection<ClusterInfo>>(){}).annotatedWith(DatabusClusterInfo.class) .toInstance(ImmutableList.of(new ClusterInfo("Test Cluster", "Test Metric Cluster"))); bind(JobService.class).toInstance(mock(JobService.class)); bind(JobHandlerRegistry.class).toInstance(mock(JobHandlerRegistry.class)); bind(new TypeLiteral<Supplier<Condition>>(){}).annotatedWith(DefaultJoinFilter.class) .toInstance(Suppliers.ofInstance(Conditions.alwaysFalse())); bind(DatabusAuthorizer.class).toInstance(mock(DatabusAuthorizer.class)); MetricRegistry metricRegistry = new MetricRegistry(); bind(MetricRegistry.class).toInstance(metricRegistry); bind(Clock.class).toInstance(mock(Clock.class)); install(new DatabusModule(serviceMode, metricRegistry)); } }); }
Example #20
Source File: BlobStoreModuleTest.java From emodb with Apache License 2.0 | 4 votes |
private Injector createInjector(final EmoServiceMode serviceMode) { // Mock the minimal CacheRegistry functionality required to instantiate the module final CacheRegistry rootCacheRegistry = mock(CacheRegistry.class); CacheRegistry blobCacheRegistry = mock(CacheRegistry.class); when(rootCacheRegistry.withNamespace(eq("blob"))).thenReturn(blobCacheRegistry); final CuratorFramework curator = mock(CuratorFramework.class); when(curator.getState()).thenReturn(CuratorFrameworkState.STARTED); when(curator.newNamespaceAwareEnsurePath(Mockito.<String>any())).thenReturn(mock(EnsurePath.class)); Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { binder().requireExplicitBindings(); // construct the minimum necessary elements to allow a BlobStore module to be created. bind(BlobStoreConfiguration.class).toInstance(new BlobStoreConfiguration() .setValidTablePlacements(ImmutableSet.of("media_global:ugc")) .setCassandraClusters(ImmutableMap.of("media_global", new CassandraConfiguration() .setCluster("Test Cluster") .setSeeds("127.0.0.1") .setPartitioner("bop") .setKeyspaces(ImmutableMap.of( "media_global", new KeyspaceConfiguration()))) ) .setS3Configuration(new S3Configuration() .setS3BucketConfigurations(ImmutableList.of(new S3BucketConfiguration("local-emodb--media-global-ugc", Regions.DEFAULT_REGION.getName(), null, null, false, 1, 1, 1, null)))) ); bind(String.class).annotatedWith(SystemTablePlacement.class).toInstance("ugc_global:sys"); bind(DataCenterConfiguration.class).toInstance(new DataCenterConfiguration() .setSystemDataCenter("datacenter1") .setCurrentDataCenter("datacenter1")); bind(BlobStore.class).annotatedWith(SystemBlobStore.class).toInstance(mock(BlobStore.class)); bind(HostAndPort.class).annotatedWith(SelfHostAndPort.class).toInstance(HostAndPort.fromString("localhost:8080")); bind(Client.class).toInstance(mock(Client.class)); bind(CacheRegistry.class).toInstance(rootCacheRegistry); bind(DataCenters.class).toInstance(mock(DataCenters.class)); bind(TableBackingStore.class).toInstance(mock(TableBackingStore.class)); bind(HealthCheckRegistry.class).toInstance(mock(HealthCheckRegistry.class)); bind(LeaderServiceTask.class).toInstance(mock(LeaderServiceTask.class)); bind(LifeCycleRegistry.class).toInstance(new SimpleLifeCycleRegistry()); bind(TaskRegistry.class).toInstance(mock(TaskRegistry.class)); bind(CuratorFramework.class).annotatedWith(Global.class).toInstance(curator); bind(CuratorFramework.class).annotatedWith(GlobalFullConsistencyZooKeeper.class).toInstance(curator); bind(CuratorFramework.class).annotatedWith(BlobStoreZooKeeper.class).toInstance(curator); MetricRegistry metricRegistry = new MetricRegistry(); bind(MetricRegistry.class).toInstance(metricRegistry); bind(Clock.class).toInstance(Clock.systemDefaultZone()); bind(ObjectMapper.class).toInstance(mock(ObjectMapper.class)); install(new BlobStoreModule(serviceMode, "bv.emodb.blob", metricRegistry)); } }); verify(rootCacheRegistry).withNamespace("blob"); //noinspection unchecked verify(blobCacheRegistry).register(eq("tables"), isA(Cache.class), eq(true)); return injector; }
Example #21
Source File: NamespaceImpl.java From xian with Apache License 2.0 | 4 votes |
EnsurePath newNamespaceAwareEnsurePath(String path) { return new EnsurePath(fixForNamespace(path, false), client.getAclProvider()); }
Example #22
Source File: CuratorFrameworkImpl.java From xian with Apache License 2.0 | 4 votes |
@Override public EnsurePath newNamespaceAwareEnsurePath(String path) { return namespace.newNamespaceAwareEnsurePath(path); }
Example #23
Source File: NamespaceFacade.java From xian with Apache License 2.0 | 4 votes |
@Override public EnsurePath newNamespaceAwareEnsurePath(String path) { return namespace.newNamespaceAwareEnsurePath(path); }
Example #24
Source File: TestEnsurePath.java From xian with Apache License 2.0 | 4 votes |
@Test public void testSimultaneous() throws Exception { ZooKeeper client = mock(ZooKeeper.class, Mockito.RETURNS_MOCKS); RetryPolicy retryPolicy = new RetryOneTime(1); RetryLoop retryLoop = new RetryLoop(retryPolicy, null); final CuratorZookeeperClient curator = mock(CuratorZookeeperClient.class); when(curator.getZooKeeper()).thenReturn(client); when(curator.getRetryPolicy()).thenReturn(retryPolicy); when(curator.newRetryLoop()).thenReturn(retryLoop); final Stat fakeStat = mock(Stat.class); final CountDownLatch startedLatch = new CountDownLatch(2); final CountDownLatch finishedLatch = new CountDownLatch(2); final Semaphore semaphore = new Semaphore(0); when(client.exists(Mockito.<String>any(), anyBoolean())).thenAnswer ( new Answer<Stat>() { @Override public Stat answer(InvocationOnMock invocation) throws Throwable { semaphore.acquire(); return fakeStat; } } ); final EnsurePath ensurePath = new EnsurePath("/one/two/three"); ExecutorService service = Executors.newCachedThreadPool(); for ( int i = 0; i < 2; ++i ) { service.submit ( new Callable<Void>() { @Override public Void call() throws Exception { startedLatch.countDown(); ensurePath.ensure(curator); finishedLatch.countDown(); return null; } } ); } Assert.assertTrue(startedLatch.await(10, TimeUnit.SECONDS)); semaphore.release(3); Assert.assertTrue(finishedLatch.await(10, TimeUnit.SECONDS)); verify(client, times(3)).exists(Mockito.<String>any(), anyBoolean()); ensurePath.ensure(curator); verifyNoMoreInteractions(client); ensurePath.ensure(curator); verifyNoMoreInteractions(client); }
Example #25
Source File: CuratorFramework.java From curator with Apache License 2.0 | 2 votes |
/** * Allocates an ensure path instance that is namespace aware * * @param path path to ensure * @return new EnsurePath instance * @deprecated Since 2.9.0 - prefer {@link CreateBuilder#creatingParentContainersIfNeeded()}, {@link ExistsBuilder#creatingParentContainersIfNeeded()} * or {@link CuratorFramework#createContainers(String)} */ @Deprecated public EnsurePath newNamespaceAwareEnsurePath(String path);
Example #26
Source File: CuratorFramework.java From xian with Apache License 2.0 | 2 votes |
/** * Allocates an ensure path instance that is namespace aware * * @param path path to ensure * @return new EnsurePath instance * @deprecated Since 2.9.0 - prefer {@link CreateBuilder#creatingParentContainersIfNeeded()}, {@link ExistsBuilder#creatingParentContainersIfNeeded()} * or {@link CuratorFramework#createContainers(String)} */ @Deprecated public EnsurePath newNamespaceAwareEnsurePath(String path);