use of org.apache.bookkeeper.api.StorageClient in project incubator-pulsar by apache.
the class CmdFunctionsTest method testStateGetter.
@Test
public void testStateGetter() throws Exception {
String tenant = TEST_NAME + "_tenant";
String namespace = TEST_NAME + "_namespace";
String fnName = TEST_NAME + "_function";
mockStatic(StorageClientBuilder.class);
StorageClientBuilder builder = mock(StorageClientBuilder.class);
when(builder.withSettings(any(StorageClientSettings.class))).thenReturn(builder);
when(builder.withNamespace(eq(tenant + "_" + namespace))).thenReturn(builder);
StorageClient client = mock(StorageClient.class);
when(builder.build()).thenReturn(client);
PowerMockito.when(StorageClientBuilder.class, "newBuilder").thenReturn(builder);
Table<ByteBuf, ByteBuf> table = mock(Table.class);
when(client.openTable(eq(fnName))).thenReturn(FutureUtils.value(table));
AtomicReference<ByteBuf> keyHolder = new AtomicReference<>();
doAnswer(invocationOnMock -> {
ByteBuf buf = invocationOnMock.getArgumentAt(0, ByteBuf.class);
keyHolder.set(buf);
return FutureUtils.value(null);
}).when(table).getKv(any(ByteBuf.class));
cmd.run(new String[] { "querystate", "--tenant", tenant, "--namespace", namespace, "--name", fnName, "--key", "test-key", "--storage-service-url", "127.0.0.1:4181" });
assertEquals("test-key", new String(ByteBufUtil.getBytes(keyHolder.get()), UTF_8));
}
Aggregations