use of org.apache.curator.framework.api.ExistsBuilder in project heron by twitter.
the class CuratorStateManagerTest method testExistNode.
/**
* 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());
}
use of org.apache.curator.framework.api.ExistsBuilder in project atlas by apache.
the class ActiveInstanceStateTest method testDataIsUpdatedWithAtlasServerAddress.
@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")));
}
use of org.apache.curator.framework.api.ExistsBuilder in project 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;
}
use of org.apache.curator.framework.api.ExistsBuilder in project incubator-heron by apache.
the class CuratorStateManagerTest method testExistNode.
/**
* 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());
}
use of org.apache.curator.framework.api.ExistsBuilder in project heron by twitter.
the class CuratorStateManagerTest method testExistNode.
/**
* 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());
}
Aggregations