use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class PartitionedProducerConsumerTest method testAsyncPartitionedProducerConsumerQueueSizeOne.
@Test(timeOut = 4000)
public void testAsyncPartitionedProducerConsumerQueueSizeOne() throws Exception {
log.info("-- Starting {} test --", methodName);
final int totalMsg = 100;
final Set<String> produceMsgs = Sets.newHashSet();
final Set<String> consumeMsgs = Sets.newHashSet();
int numPartitions = 4;
DestinationName dn = DestinationName.get("persistent://my-property/use/my-ns/my-partitionedtopic1");
ConsumerConfiguration conf = new ConsumerConfiguration();
conf.setReceiverQueueSize(1);
admin.persistentTopics().createPartitionedTopic(dn.toString(), numPartitions);
ProducerConfiguration producerConf = new ProducerConfiguration();
producerConf.setMessageRoutingMode(MessageRoutingMode.RoundRobinPartition);
Producer producer = pulsarClient.createProducer(dn.toString(), producerConf);
Consumer consumer = pulsarClient.subscribe(dn.toString(), "my-partitioned-subscriber", conf);
// produce messages
for (int i = 0; i < totalMsg; i++) {
String message = "my-message-" + i;
produceMsgs.add(message);
producer.send(message.getBytes());
}
log.info(" start receiving messages :");
// receive messages
CountDownLatch latch = new CountDownLatch(totalMsg);
receiveAsync(consumer, totalMsg, 0, latch, consumeMsgs, Executors.newFixedThreadPool(1));
latch.await();
// verify message produced correctly
assertEquals(produceMsgs.size(), totalMsg);
// verify produced and consumed messages must be exactly same
produceMsgs.removeAll(consumeMsgs);
assertTrue(produceMsgs.isEmpty());
producer.close();
consumer.unsubscribe();
consumer.close();
admin.persistentTopics().deletePartitionedTopic(dn.toString());
log.info("-- Exiting {} test --", methodName);
}
use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class DiscoveryServiceTest method testGetPartitionsMetadata.
@Test
public void testGetPartitionsMetadata() throws Exception {
DestinationName topic1 = DestinationName.get("persistent://test/local/ns/my-topic-1");
PartitionedTopicMetadata m = service.getDiscoveryProvider().getPartitionedTopicMetadata(service, topic1, "role").get();
assertEquals(m.partitions, 0);
// Simulate ZK error
mockZookKeeper.failNow(Code.SESSIONEXPIRED);
DestinationName topic2 = DestinationName.get("persistent://test/local/ns/my-topic-2");
CompletableFuture<PartitionedTopicMetadata> future = service.getDiscoveryProvider().getPartitionedTopicMetadata(service, topic2, "role");
try {
future.get();
fail("Partition metadata lookup should have failed");
} catch (ExecutionException e) {
assertEquals(e.getCause().getClass(), SessionExpiredException.class);
}
}
use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class PersistentTopicsImpl method peekNthMessage.
private CompletableFuture<Message> peekNthMessage(String destination, String subName, int messagePosition) {
DestinationName ds = validateTopic(destination);
String encodedSubName = Codec.encode(subName);
final CompletableFuture<Message> future = new CompletableFuture<Message>();
asyncGetRequest(persistentTopics.path(ds.getNamespace()).path(ds.getEncodedLocalName()).path("subscription").path(encodedSubName).path("position").path(String.valueOf(messagePosition)), new InvocationCallback<Response>() {
@Override
public void completed(Response response) {
try {
Message msg = getMessageFromHttpResponse(response);
future.complete(msg);
} catch (Exception e) {
future.completeExceptionally(getApiException(e));
}
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class CliCommand method validatePersistentTopic.
String validatePersistentTopic(List<String> params) {
String destination = checkArgument(params);
DestinationName ds = DestinationName.get(destination);
if (ds.getDomain() != DestinationDomain.persistent) {
throw new ParameterException("Need to provide a persistent topic name");
}
return ds.toString();
}
use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class PersistentTopicsImpl method getPartitionedStatsAsync.
@Override
public CompletableFuture<PartitionedTopicStats> getPartitionedStatsAsync(String destination, boolean perPartition) {
DestinationName ds = validateTopic(destination);
final CompletableFuture<PartitionedTopicStats> future = new CompletableFuture<>();
asyncGetRequest(persistentTopics.path(ds.getNamespace()).path(ds.getEncodedLocalName()).path("partitioned-stats"), new InvocationCallback<PartitionedTopicStats>() {
@Override
public void completed(PartitionedTopicStats response) {
if (!perPartition) {
response.partitions.clear();
}
future.complete(response);
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
Aggregations