Search in sources :

Example 1 with ByteBuf

use of org.apache.pulsar.functions.shaded.io.netty.buffer.ByteBuf 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));
}
Also used : StorageClientSettings(org.apache.bookkeeper.clients.config.StorageClientSettings) StorageClientBuilder(org.apache.bookkeeper.clients.StorageClientBuilder) StorageClient(org.apache.bookkeeper.api.StorageClient) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.anyString(org.mockito.Matchers.anyString) ByteBuf(org.apache.pulsar.functions.shaded.io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

AtomicReference (java.util.concurrent.atomic.AtomicReference)1 StorageClient (org.apache.bookkeeper.api.StorageClient)1 StorageClientBuilder (org.apache.bookkeeper.clients.StorageClientBuilder)1 StorageClientSettings (org.apache.bookkeeper.clients.config.StorageClientSettings)1 ByteBuf (org.apache.pulsar.functions.shaded.io.netty.buffer.ByteBuf)1 Matchers.anyString (org.mockito.Matchers.anyString)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1