本文整理汇总了Java中org.apache.curator.framework.api.ExistsBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ExistsBuilder类的具体用法?Java ExistsBuilder怎么用?Java ExistsBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExistsBuilder类属于org.apache.curator.framework.api包,在下文中一共展示了ExistsBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDataIsUpdatedWithAtlasServerAddress
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
@Test
public void testDataIsUpdatedWithAtlasServerAddress() throws Exception {
when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn(HOST_PORT);
when(configuration.getString(
HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
when(curatorFactory.clientInstance()).thenReturn(curatorFramework);
ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
when(curatorFramework.checkExists()).thenReturn(existsBuilder);
when(existsBuilder.forPath(getPath())).thenReturn(new Stat());
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder);
ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
activeInstanceState.update("id1");
verify(setDataBuilder).forPath(
getPath(),
SERVER_ADDRESS.getBytes(Charset.forName("UTF-8")));
}
示例2: testCanReadFromZookeeper
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
@Test
public void testCanReadFromZookeeper() throws Exception {
CuratorFramework curatorFramework = mock(CuratorFramework.class);
ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
GetDataBuilder getDataBuilder = mock(GetDataBuilder.class);
GetChildrenBuilder getChildrenBuilder = mock(GetChildrenBuilder.class);
when(getDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot())).thenReturn(mockGlobalData());
when(curatorFramework.checkExists()).thenReturn(existsBuilder);
when(curatorFramework.getData()).thenReturn(getDataBuilder);
when(curatorFramework.getChildren()).thenReturn(getChildrenBuilder);
when(getChildrenBuilder.forPath(anyString())).thenReturn(Collections.<String> emptyList());
Configuration configuration = new Configuration(Paths.get("foo"));
configuration.curatorFramework = curatorFramework;
configuration.update();
checkResult(configuration);
}
示例3: testStart
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testStart() throws Exception {
CuratorFramework framework = mockFramework();
ExistsBuilder ceBuilder = mock(ExistsBuilder.class);
CreateBuilder createBuilder = mock(CreateBuilder.class);
when(framework.checkExists()).thenReturn(ceBuilder);
when(ceBuilder.forPath("/services/myservice/nodes")).thenReturn(mock(Stat.class));
when(framework.create()).thenReturn(createBuilder);
when(framework.getState()).thenReturn(CuratorFrameworkState.STARTED);
ACLBackgroundPathAndBytesable<String> os = mock(ACLBackgroundPathAndBytesable.class);
when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(os);
DiscoService service = new DiscoService(framework, "myservice");
byte[] payload = "foo bar baz bingo".getBytes();
service.start("foo", 4321, true, payload);
verify(os).forPath(eq("/services/myservice/nodes/foo:4321"), eq(payload));
}
示例4: testDeletesEphemeralNode
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testDeletesEphemeralNode() throws Exception {
CuratorFramework framework = mockFramework();
ExistsBuilder ceBuilder = mock(ExistsBuilder.class);
CreateBuilder createBuilder = mock(CreateBuilder.class);
when(framework.checkExists()).thenReturn(ceBuilder);
when(ceBuilder.forPath("/services/myservice/nodes")).thenReturn(mock(Stat.class));
when(ceBuilder.forPath("/services/myservice/nodes/foo:4321")).thenReturn(mock(Stat.class));
when(framework.create()).thenReturn(createBuilder);
when(framework.getState()).thenReturn(CuratorFrameworkState.STARTED);
DeleteBuilder deleteBuilder = mock(DeleteBuilder.class);
when(framework.delete()).thenReturn(deleteBuilder);
ACLBackgroundPathAndBytesable<String> os = mock(ACLBackgroundPathAndBytesable.class);
when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(os);
DiscoService service = new DiscoService(framework, "myservice");
byte[] payload = "foo bar baz bingo".getBytes();
service.start("foo", 4321, true, payload);
verify(deleteBuilder).forPath("/services/myservice/nodes/foo:4321");
verify(os).forPath(eq("/services/myservice/nodes/foo:4321"), eq(payload));
}
示例5: testDeleteNodeIfNoChildren_withNodeThatDoesntExist
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
/**
* 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);
// Call our method
curatorHelper.deleteNodeIfNoChildren(basePath);
}
示例6: setupClient
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
protected void setupClient() {
client = mock(CuratorFramework.class);
existsBuilder = mock(ExistsBuilder.class);
pathCreator = mock(ZookeeperConnector.IPathCreator.class);
stackCache = mock(IStacksCache.class);
nodeCacheFactory = mock(INodeCacheFactory.class);
pathChildrenCacheFactory = mock(IPathChildrenCacheFactory.class);
when(client.checkExists()).thenReturn(existsBuilder);
when(client.getState()).thenReturn(CuratorFrameworkState.STARTED);
}
示例7: createNonExisting
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
public void createNonExisting() throws Exception {
CuratorFramework client = mock(CuratorFramework.class);
ExistsBuilder builder = mock(ExistsBuilder.class);
CreateBuilder createBuilder = mock(CreateBuilder.class);
//ProtectACLCreateModeStatPathAndBytesable<String> protector = mock(ProtectACLCreateModeStatPathAndBytesable.class);
when(builder.forPath(anyString())).thenReturn(null);
when(client.checkExists()).thenReturn(builder);
when(client.create()).thenReturn(createBuilder);
//when(createBuilder.creatingParentContainersIfNeeded()).thenReturn((ProtectACLCreateModeStatPathAndBytesable<String>)protector);
new DistributedLockServiceCuratorImpl(client, "/", 0);
//verify(protector).forPath(anyString(), anyObject());
}
示例8: createNonExisting2
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
public void createNonExisting2() throws Exception {
CuratorFramework client = mock(CuratorFramework.class);
ExistsBuilder builder = mock(ExistsBuilder.class);
CreateBuilder createBuilder = mock(CreateBuilder.class);
//ProtectACLCreateModeStatPathAndBytesable<String> protector = mock(ProtectACLCreateModeStatPathAndBytesable.class);
when(builder.forPath(anyString())).thenReturn(new Stat());
when(client.checkExists()).thenReturn(builder);
when(client.create()).thenReturn(createBuilder);
//when(createBuilder.creatingParentContainersIfNeeded()).thenReturn(protector);
new DistributedLockServiceCuratorImpl(client, "/", 0);
//verify(protector, times(0)).forPath(anyString(), anyObject());
}
示例9: createNonExisting
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
@Test
public void createNonExisting() throws Exception {
CuratorFramework client = mock(CuratorFramework.class);
ExistsBuilder builder = mock(ExistsBuilder.class);
CreateBuilder createBuilder = mock(CreateBuilder.class);
ProtectACLCreateModeStatPathAndBytesable<String> protector = mock(ProtectACLCreateModeStatPathAndBytesable.class);
when(builder.forPath(anyString())).thenReturn(null);
when(client.checkExists()).thenReturn(builder);
when(client.create()).thenReturn(createBuilder);
when(createBuilder.creatingParentContainersIfNeeded()).thenReturn((ProtectACLCreateModeStatPathAndBytesable<String>)protector);
new DistributedLockServiceCuratorImpl(client, "/", 0);
verify(protector).forPath(anyString(), anyObject());
}
示例10: createNonExisting2
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
@Test
public void createNonExisting2() throws Exception {
CuratorFramework client = mock(CuratorFramework.class);
ExistsBuilder builder = mock(ExistsBuilder.class);
CreateBuilder createBuilder = mock(CreateBuilder.class);
ProtectACLCreateModeStatPathAndBytesable<String> protector = mock(ProtectACLCreateModeStatPathAndBytesable.class);
when(builder.forPath(anyString())).thenReturn(new Stat());
when(client.checkExists()).thenReturn(builder);
when(client.create()).thenReturn(createBuilder);
when(createBuilder.creatingParentContainersIfNeeded()).thenReturn(protector);
new DistributedLockServiceCuratorImpl(client, "/", 0);
verify(protector, times(0)).forPath(anyString(), anyObject());
}
示例11: setupSetupInProgressPathMocks
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
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;
}
示例12: testSharedPathIsCreatedIfNotExists
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
@Test
public void testSharedPathIsCreatedIfNotExists() throws Exception {
when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn(HOST_PORT);
when(configuration.getString(
HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
when(curatorFactory.clientInstance()).thenReturn(curatorFramework);
ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
when(curatorFramework.checkExists()).thenReturn(existsBuilder);
when(existsBuilder.forPath(getPath())).thenReturn(null);
CreateBuilder createBuilder = mock(CreateBuilder.class);
when(curatorFramework.create()).thenReturn(createBuilder);
when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
when(createBuilder.withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE)).thenReturn(createBuilder);
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder);
ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
activeInstanceState.update("id1");
verify(createBuilder).forPath(getPath());
}
示例13: testSharedPathIsCreatedWithRightACLIfNotExists
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
@Test
public void testSharedPathIsCreatedWithRightACLIfNotExists() throws Exception {
when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn(HOST_PORT);
when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("sasl:[email protected]");
when(configuration.getString(
HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
when(curatorFactory.clientInstance()).thenReturn(curatorFramework);
ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
when(curatorFramework.checkExists()).thenReturn(existsBuilder);
when(existsBuilder.forPath(getPath())).thenReturn(null);
CreateBuilder createBuilder = mock(CreateBuilder.class);
when(curatorFramework.create()).thenReturn(createBuilder);
when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
ACL expectedAcl = new ACL(ZooDefs.Perms.ALL, new Id("sasl", "[email protected]"));
when(createBuilder.
withACL(Arrays.asList(new ACL[]{expectedAcl}))).thenReturn(createBuilder);
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder);
ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
activeInstanceState.update("id1");
verify(createBuilder).forPath(getPath());
}
示例14: before
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
@Before
public void before() {
existsBuilder = mock(ExistsBuilder.class);
final CuratorFramework curatorFramework = mock(CuratorFramework.class);
when(curatorFramework.checkExists()).thenReturn(existsBuilder);
final ZooKeeperHolder zkHolder = mock(ZooKeeperHolder.class);
when(zkHolder.get()).thenReturn(curatorFramework);
featureToggleService = new FeatureToggleServiceZk(zkHolder);
}
示例15: testExistNode
import org.apache.curator.framework.api.ExistsBuilder; //导入依赖的package包/类
/**
* Test nodeExists method
* @throws Exception
*/
@Test
public void testExistNode() throws Exception {
CuratorStateManager spyStateManager = spy(new CuratorStateManager());
CuratorFramework mockClient = mock(CuratorFramework.class);
ExistsBuilder mockExistsBuilder = mock(ExistsBuilder.class);
final String correctPath = "/correct/path";
final String wrongPath = "/wrong/path";
doReturn(mockClient)
.when(spyStateManager).getCuratorClient();
doReturn(true)
.when(mockClient).blockUntilConnected(anyInt(), any(TimeUnit.class));
doReturn(mockExistsBuilder)
.when(mockClient).checkExists();
doReturn(new Stat())
.when(mockExistsBuilder).forPath(correctPath);
doReturn(null)
.when(mockExistsBuilder).forPath(wrongPath);
spyStateManager.initialize(config);
// Verify the result is true when path is correct
ListenableFuture<Boolean> result1 = spyStateManager.nodeExists(correctPath);
verify(mockExistsBuilder).forPath(correctPath);
assertTrue(result1.get());
// Verify the result is false when path is wrong
ListenableFuture<Boolean> result2 = spyStateManager.nodeExists(wrongPath);
verify(mockExistsBuilder).forPath(wrongPath);
assertFalse(result2.get());
}