Search in sources :

Example 1 with ACLBackgroundPathAndBytesable

use of org.apache.curator.framework.api.ACLBackgroundPathAndBytesable in project heron by twitter.

the class CuratorStateManagerTest method testCreateNode.

/**
   * test createNode method
   * @throws Exception
   */
@Test
public void testCreateNode() throws Exception {
    CuratorStateManager spyStateManager = spy(new CuratorStateManager());
    CuratorFramework mockClient = mock(CuratorFramework.class);
    CreateBuilder mockCreateBuilder = mock(CreateBuilder.class);
    // Mockito doesn't support mock type-parametrized class, thus suppress the warning
    @SuppressWarnings("rawtypes") ACLBackgroundPathAndBytesable mockPath = spy(ACLBackgroundPathAndBytesable.class);
    final byte[] data = new byte[10];
    doReturn(mockClient).when(spyStateManager).getCuratorClient();
    doReturn(true).when(mockClient).blockUntilConnected(anyInt(), any(TimeUnit.class));
    doReturn(mockCreateBuilder).when(mockClient).create();
    doReturn(mockPath).when(mockCreateBuilder).withMode(any(CreateMode.class));
    spyStateManager.initialize(config);
    // Verify the node is created successfully
    ListenableFuture<Boolean> result = spyStateManager.createNode(PATH, data, false);
    verify(mockCreateBuilder).withMode(any(CreateMode.class));
    verify(mockPath).forPath(PATH, data);
    assertTrue(result.get());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CreateMode(org.apache.zookeeper.CreateMode) CreateBuilder(org.apache.curator.framework.api.CreateBuilder) ACLBackgroundPathAndBytesable(org.apache.curator.framework.api.ACLBackgroundPathAndBytesable) TimeUnit(java.util.concurrent.TimeUnit) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Test(org.junit.Test)

Example 2 with ACLBackgroundPathAndBytesable

use of org.apache.curator.framework.api.ACLBackgroundPathAndBytesable in project incubator-heron by apache.

the class CuratorStateManagerTest method testCreateNode.

/**
 * test createNode method
 * @throws Exception
 */
@Test
public void testCreateNode() throws Exception {
    CuratorStateManager spyStateManager = spy(new CuratorStateManager());
    CuratorFramework mockClient = mock(CuratorFramework.class);
    CreateBuilder mockCreateBuilder = mock(CreateBuilder.class);
    // Mockito doesn't support mock type-parametrized class, thus suppress the warning
    @SuppressWarnings("rawtypes") ACLBackgroundPathAndBytesable mockPath = spy(ACLBackgroundPathAndBytesable.class);
    final byte[] data = new byte[10];
    doReturn(mockClient).when(spyStateManager).getCuratorClient();
    doReturn(true).when(mockClient).blockUntilConnected(anyInt(), any(TimeUnit.class));
    doReturn(mockCreateBuilder).when(mockClient).create();
    doReturn(mockPath).when(mockCreateBuilder).withMode(any(CreateMode.class));
    spyStateManager.initialize(config);
    // Verify the node is created successfully
    ListenableFuture<Boolean> result = spyStateManager.createNode(PATH, data, false);
    verify(mockCreateBuilder).withMode(any(CreateMode.class));
    verify(mockPath).forPath(PATH, data);
    assertTrue(result.get());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CreateMode(org.apache.zookeeper.CreateMode) CreateBuilder(org.apache.curator.framework.api.CreateBuilder) ACLBackgroundPathAndBytesable(org.apache.curator.framework.api.ACLBackgroundPathAndBytesable) TimeUnit(java.util.concurrent.TimeUnit) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Test(org.junit.Test)

Example 3 with ACLBackgroundPathAndBytesable

use of org.apache.curator.framework.api.ACLBackgroundPathAndBytesable in project heron by twitter.

the class CuratorStateManagerTest method testCreateNode.

/**
 * test createNode method
 * @throws Exception
 */
@Test
public void testCreateNode() throws Exception {
    CuratorStateManager spyStateManager = spy(new CuratorStateManager());
    CuratorFramework mockClient = mock(CuratorFramework.class);
    CreateBuilder mockCreateBuilder = mock(CreateBuilder.class);
    // Mockito doesn't support mock type-parametrized class, thus suppress the warning
    @SuppressWarnings("rawtypes") ACLBackgroundPathAndBytesable mockPath = spy(ACLBackgroundPathAndBytesable.class);
    final byte[] data = new byte[10];
    doReturn(mockClient).when(spyStateManager).getCuratorClient();
    doReturn(true).when(mockClient).blockUntilConnected(anyInt(), any(TimeUnit.class));
    doReturn(mockCreateBuilder).when(mockClient).create();
    doReturn(mockPath).when(mockCreateBuilder).withMode(any(CreateMode.class));
    spyStateManager.initialize(config);
    // Verify the node is created successfully
    ListenableFuture<Boolean> result = spyStateManager.createNode(PATH, data, false);
    verify(mockCreateBuilder).withMode(any(CreateMode.class));
    verify(mockPath).forPath(PATH, data);
    assertTrue(result.get());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CreateMode(org.apache.zookeeper.CreateMode) CreateBuilder(org.apache.curator.framework.api.CreateBuilder) ACLBackgroundPathAndBytesable(org.apache.curator.framework.api.ACLBackgroundPathAndBytesable) TimeUnit(java.util.concurrent.TimeUnit) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Test(org.junit.Test)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 ACLBackgroundPathAndBytesable (org.apache.curator.framework.api.ACLBackgroundPathAndBytesable)3 CreateBuilder (org.apache.curator.framework.api.CreateBuilder)3 CreateMode (org.apache.zookeeper.CreateMode)3 Test (org.junit.Test)3 Matchers.anyBoolean (org.mockito.Matchers.anyBoolean)3