use of org.apache.curator.framework.api.BackgroundPathable in project heron by twitter.
the class CuratorStateManagerTest method testDeleteNode.
/**
* 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());
}
use of org.apache.curator.framework.api.BackgroundPathable in project heron by twitter.
the class CuratorStateManagerTest method testGetNodeData.
/**
* Test getNodeData method
* @throws Exception
*/
@Test
public void testGetNodeData() throws Exception {
CuratorStateManager spyStateManager = spy(new CuratorStateManager());
final CuratorFramework mockClient = mock(CuratorFramework.class);
GetDataBuilder mockGetBuilder = mock(GetDataBuilder.class);
// Mockito doesn't support mock type-parametrized class, thus suppress the warning
@SuppressWarnings("rawtypes") BackgroundPathable mockBackPathable = mock(BackgroundPathable.class);
final CuratorEvent mockEvent = mock(CuratorEvent.class);
Message.Builder mockBuilder = mock(Message.Builder.class);
Message mockMessage = mock(Message.class);
final byte[] data = "wy_1989".getBytes();
doReturn(mockMessage).when(mockBuilder).build();
doReturn(data).when(mockEvent).getData();
doReturn(PATH).when(mockEvent).getPath();
doReturn(mockClient).when(spyStateManager).getCuratorClient();
doReturn(true).when(mockClient).blockUntilConnected(anyInt(), any(TimeUnit.class));
doReturn(mockGetBuilder).when(mockClient).getData();
doReturn(mockBackPathable).when(mockGetBuilder).usingWatcher(any(Watcher.class));
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] objests = invocationOnMock.getArguments();
// the first object is the BackgroundCallback
((BackgroundCallback) objests[0]).processResult(mockClient, mockEvent);
return null;
}
}).when(mockBackPathable).inBackground(any(BackgroundCallback.class));
spyStateManager.initialize(config);
// Verify the data on node is fetched correctly
ListenableFuture<Message> result = spyStateManager.getNodeData(null, PATH, mockBuilder);
assertTrue(result.get().equals(mockMessage));
}
Aggregations