Search in sources :

Example 1 with PulsarClientTool

use of org.apache.pulsar.client.cli.PulsarClientTool in project incubator-pulsar by apache.

the class PulsarClientToolTest method testInitialzation.

@Test(timeOut = 10000)
public void testInitialzation() throws MalformedURLException, InterruptedException, ExecutionException, PulsarAdminException {
    Properties properties = new Properties();
    properties.setProperty("serviceUrl", brokerUrl.toString());
    properties.setProperty("useTls", "false");
    admin.properties().createProperty("property", new PropertyAdmin());
    String topicName = "persistent://property/ns/topic-scale-ns-0/topic";
    int numberOfMessages = 10;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    CompletableFuture<Void> future = new CompletableFuture<Void>();
    executor.execute(() -> {
        PulsarClientTool pulsarClientToolConsumer;
        try {
            pulsarClientToolConsumer = new PulsarClientTool(properties);
            String[] args = { "consume", "-t", "Exclusive", "-s", "sub-name", "-n", Integer.toString(numberOfMessages), "--hex", "-r", "30", topicName };
            Assert.assertEquals(pulsarClientToolConsumer.run(args), 0);
            future.complete(null);
        } catch (Throwable t) {
            future.completeExceptionally(t);
        }
    });
    // Make sure subscription has been created
    while (true) {
        try {
            List<String> subscriptions = admin.persistentTopics().getSubscriptions(topicName);
            if (subscriptions.size() == 1) {
                break;
            }
        } catch (Exception e) {
        }
        Thread.sleep(200);
    }
    PulsarClientTool pulsarClientToolProducer = new PulsarClientTool(properties);
    String[] args = { "produce", "--messages", "Have a nice day", "-n", Integer.toString(numberOfMessages), "-r", "20", topicName };
    Assert.assertEquals(pulsarClientToolProducer.run(args), 0);
    future.get();
    executor.shutdown();
}
Also used : Properties(java.util.Properties) MalformedURLException(java.net.MalformedURLException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ExecutionException(java.util.concurrent.ExecutionException) CompletableFuture(java.util.concurrent.CompletableFuture) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) ExecutorService(java.util.concurrent.ExecutorService) PulsarClientTool(org.apache.pulsar.client.cli.PulsarClientTool) Test(org.testng.annotations.Test)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 Properties (java.util.Properties)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)1 PulsarClientTool (org.apache.pulsar.client.cli.PulsarClientTool)1 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)1 Test (org.testng.annotations.Test)1