Search in sources :

Example 1 with CreateBuilder

use of org.apache.bookkeeper.client.api.CreateBuilder in project bookkeeper by apache.

the class SimpleTestCommandTest method testCommand.

public void testCommand(String... args) throws Exception {
    WriteHandle wh = mock(WriteHandle.class);
    AtomicLong counter = new AtomicLong(0L);
    when(wh.append(any(byte[].class))).thenReturn(counter.get());
    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(createBuilder.execute()).thenReturn(FutureUtils.value(wh));
    when(createBuilder.withEnsembleSize(anyInt())).thenReturn(createBuilder);
    when(createBuilder.withWriteQuorumSize(anyInt())).thenReturn(createBuilder);
    when(createBuilder.withAckQuorumSize(anyInt())).thenReturn(createBuilder);
    when(createBuilder.withDigestType(any(DigestType.class))).thenReturn(createBuilder);
    when(createBuilder.withPassword(any(byte[].class))).thenReturn(createBuilder);
    when(mockBk.newCreateLedgerOp()).thenReturn(createBuilder);
    CommandRunner runner = createCommandRunner(new SimpleTestCommand());
    assertTrue(runner.runArgs(args));
    // verify create builder
    verify(createBuilder, times(1)).withEnsembleSize(eq(5));
    verify(createBuilder, times(1)).withWriteQuorumSize(eq(3));
    verify(createBuilder, times(1)).withAckQuorumSize(eq(3));
    verify(createBuilder, times(1)).withDigestType(eq(DigestType.CRC32C));
    verify(createBuilder, times(1)).withPassword(eq(new byte[0]));
    verify(createBuilder, times(1)).execute();
    // verify appends
    verify(wh, times(10)).append(eq(new byte[100]));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) WriteHandle(org.apache.bookkeeper.client.api.WriteHandle) CreateBuilder(org.apache.bookkeeper.client.api.CreateBuilder) DigestType(org.apache.bookkeeper.client.api.DigestType)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)1 CreateBuilder (org.apache.bookkeeper.client.api.CreateBuilder)1 DigestType (org.apache.bookkeeper.client.api.DigestType)1 WriteHandle (org.apache.bookkeeper.client.api.WriteHandle)1