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