use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class ReplicatorTest method testReplication.
@Test(enabled = true)
public void testReplication() throws Exception {
log.info("--- Starting ReplicatorTest::testReplication ---");
// This test is to verify that the config change on global namespace is successfully applied in broker during
// runtime.
// Run a set of producer tasks to create the destinations
SortedSet<String> testDests = new TreeSet<String>();
List<Future<Void>> results = Lists.newArrayList();
for (int i = 0; i < 3; i++) {
final DestinationName dest = DestinationName.get(String.format("persistent://pulsar/global/ns/repltopic-%d", i));
testDests.add(dest.toString());
results.add(executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
MessageProducer producer1 = new MessageProducer(url1, dest);
log.info("--- Starting producer --- " + url1);
MessageProducer producer2 = new MessageProducer(url2, dest);
log.info("--- Starting producer --- " + url2);
MessageProducer producer3 = new MessageProducer(url3, dest);
log.info("--- Starting producer --- " + url3);
MessageConsumer consumer1 = new MessageConsumer(url1, dest);
log.info("--- Starting Consumer --- " + url1);
MessageConsumer consumer2 = new MessageConsumer(url2, dest);
log.info("--- Starting Consumer --- " + url2);
MessageConsumer consumer3 = new MessageConsumer(url3, dest);
log.info("--- Starting Consumer --- " + url3);
// Produce from cluster1 and consume from the rest
producer1.produce(2);
consumer1.receive(2);
consumer2.receive(2);
consumer3.receive(2);
// Produce from cluster2 and consume from the rest
producer2.produce(2);
consumer1.receive(2);
consumer2.receive(2);
consumer3.receive(2);
// Produce from cluster3 and consume from the rest
producer3.produce(2);
consumer1.receive(2);
consumer2.receive(2);
consumer3.receive(2);
// Produce from cluster1&2 and consume from cluster3
producer1.produce(1);
producer2.produce(1);
consumer1.receive(1);
consumer2.receive(1);
consumer3.receive(1);
consumer1.receive(1);
consumer2.receive(1);
consumer3.receive(1);
producer1.close();
producer2.close();
producer3.close();
consumer1.close();
consumer2.close();
consumer3.close();
return null;
}
}));
}
for (Future<Void> result : results) {
try {
result.get();
} catch (Exception e) {
log.error("exception in getting future result ", e);
fail(String.format("replication test failed with %s exception", e.getMessage()));
}
}
}
use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class ReplicatorTest method testDeleteReplicatorFailure.
/**
* It verifies that: if it fails while removing replicator-cluster-cursor: it should not restart the replicator and
* it should have cleaned up from the list
*
* @throws Exception
*/
@Test
public void testDeleteReplicatorFailure() throws Exception {
log.info("--- Starting ReplicatorTest::testDeleteReplicatorFailure ---");
final String topicName = "persistent://pulsar/global/ns/repltopicbatch";
final DestinationName dest = DestinationName.get(topicName);
MessageProducer producer1 = new MessageProducer(url1, dest);
PersistentTopic topic = (PersistentTopic) pulsar1.getBrokerService().getTopicReference(topicName);
final String replicatorClusterName = topic.getReplicators().keys().get(0);
ManagedLedgerImpl ledger = (ManagedLedgerImpl) topic.getManagedLedger();
CountDownLatch latch = new CountDownLatch(1);
// delete cursor already : so next time if topic.removeReplicator will get exception but then it should
// remove-replicator from the list even with failure
ledger.asyncDeleteCursor("pulsar.repl." + replicatorClusterName, new DeleteCursorCallback() {
@Override
public void deleteCursorComplete(Object ctx) {
latch.countDown();
}
@Override
public void deleteCursorFailed(ManagedLedgerException exception, Object ctx) {
latch.countDown();
}
}, null);
latch.await();
Method removeReplicator = PersistentTopic.class.getDeclaredMethod("removeReplicator", String.class);
removeReplicator.setAccessible(true);
// invoke removeReplicator : it fails as cursor is not present: but still it should remove the replicator from
// list without restarting it
CompletableFuture<Void> result = (CompletableFuture<Void>) removeReplicator.invoke(topic, replicatorClusterName);
result.thenApply((v) -> {
assertNull(topic.getPersistentReplicator(replicatorClusterName));
return null;
});
}
use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class PartitionedProducerConsumerTest method testSillyUser.
@Test
public void testSillyUser() throws Exception {
int numPartitions = 4;
DestinationName dn = DestinationName.get("persistent://my-property/use/my-ns/my-partitionedtopic5");
admin.persistentTopics().createPartitionedTopic(dn.toString(), numPartitions);
ProducerConfiguration producerConf = new ProducerConfiguration();
Producer producer = null;
Consumer consumer = null;
try {
producerConf.setMessageRouter(null);
Assert.fail("should fail");
} catch (NullPointerException e) {
// ok
}
try {
producerConf.setMessageRoutingMode(null);
Assert.fail("should fail");
} catch (NullPointerException e) {
// ok
}
try {
producer = pulsarClient.createProducer(dn.toString(), null);
Assert.fail("should fail");
} catch (PulsarClientException e) {
Assert.assertTrue(e instanceof PulsarClientException.InvalidConfigurationException);
}
ConsumerConfiguration consumerConf = new ConsumerConfiguration();
try {
consumer = pulsarClient.subscribe(dn.toString(), "my-subscriber-name", null);
Assert.fail("Should fail");
} catch (PulsarClientException e) {
Assert.assertTrue(e instanceof PulsarClientException.InvalidConfigurationException);
}
try {
producer = pulsarClient.createProducer(dn.toString());
consumer = pulsarClient.subscribe(dn.toString(), "my-sub");
producer.send("message1".getBytes());
producer.send("message2".getBytes());
Message msg1 = consumer.receive();
Message msg2 = consumer.receive();
consumer.acknowledgeCumulative(msg2);
Assert.fail("should fail since ack cumulative is not supported for partitioned topic");
} catch (PulsarClientException e) {
Assert.assertTrue(e instanceof PulsarClientException.NotSupportedException);
} finally {
producer.close();
consumer.unsubscribe();
consumer.close();
}
admin.persistentTopics().deletePartitionedTopic(dn.toString());
}
use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class PartitionedProducerConsumerTest method testInvalidSequence.
@Test
public void testInvalidSequence() throws Exception {
log.info("-- Starting {} test --", methodName);
int numPartitions = 4;
DestinationName dn = DestinationName.get("persistent://my-property/use/my-ns/my-partitionedtopic4");
admin.persistentTopics().createPartitionedTopic(dn.toString(), numPartitions);
ConsumerConfiguration consumerConf = new ConsumerConfiguration();
consumerConf.setSubscriptionType(SubscriptionType.Exclusive);
Consumer consumer = pulsarClient.subscribe(dn.toString(), "my-subscriber-name", consumerConf);
try {
Message msg = MessageBuilder.create().setContent("InvalidMessage".getBytes()).build();
consumer.acknowledge(msg);
} catch (PulsarClientException.InvalidMessageException e) {
// ok
}
consumer.close();
try {
consumer.receive();
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
try {
consumer.unsubscribe();
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
Producer producer = pulsarClient.createProducer(dn.toString());
producer.close();
try {
producer.send("message".getBytes());
Assert.fail("Should fail");
} catch (PulsarClientException.AlreadyClosedException e) {
// ok
}
admin.persistentTopics().deletePartitionedTopic(dn.toString());
}
use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class PartitionedProducerConsumerTest method testAsyncPartitionedProducerConsumer.
@Test(timeOut = 4000)
public void testAsyncPartitionedProducerConsumer() 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.setSubscriptionType(SubscriptionType.Shared);
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);
}
Aggregations