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]));
}
Aggregations