use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class ReplicatorTest method testResumptionAfterBacklogRelaxed.
/**
* Issue #199
*
* It verifies that: if the remote cluster reaches backlog quota limit, replicator temporarily stops and once the
* backlog drains it should resume replication.
*
* @throws Exception
*/
@Test(timeOut = 60000, enabled = true, priority = -1)
public void testResumptionAfterBacklogRelaxed() throws Exception {
List<RetentionPolicy> policies = Lists.newArrayList();
policies.add(RetentionPolicy.producer_exception);
policies.add(RetentionPolicy.producer_request_hold);
for (RetentionPolicy policy : policies) {
// Use 1Mb quota by default
admin1.namespaces().setBacklogQuota("pulsar/global/ns1", new BacklogQuota(1 * 1024 * 1024, policy));
Thread.sleep(200);
TopicName dest = TopicName.get(String.format("persistent://pulsar/global/ns1/%s-%d", policy, System.currentTimeMillis()));
// Producer on r1
MessageProducer producer1 = new MessageProducer(url1, dest);
// Consumer on r2
MessageConsumer consumer2 = new MessageConsumer(url2, dest);
// Replicator for r1 -> r2
PersistentTopic topic = (PersistentTopic) pulsar1.getBrokerService().getTopicReference(dest.toString());
Replicator replicator = topic.getPersistentReplicator("r2");
// Produce 1 message in r1. This message will be replicated immediately into r2 and it will become part of
// local backlog
producer1.produce(1);
Thread.sleep(500);
// Restrict backlog quota limit to 1 byte to stop replication
admin1.namespaces().setBacklogQuota("pulsar/global/ns1", new BacklogQuota(1, policy));
Thread.sleep((TIME_TO_CHECK_BACKLOG_QUOTA + 1) * 1000);
assertEquals(replicator.getStats().replicationBacklog, 0);
// Next message will not be replicated, because r2 has reached the quota
producer1.produce(1);
Thread.sleep(500);
assertEquals(replicator.getStats().replicationBacklog, 1);
// Consumer will now drain 1 message and the replication backlog will be cleared
consumer2.receive(1);
// Wait until the 2nd message got delivered to consumer
consumer2.receive(1);
int retry = 10;
for (int i = 0; i < retry && replicator.getStats().replicationBacklog > 0; i++) {
if (i != retry - 1) {
Thread.sleep(100);
}
}
assertEquals(replicator.getStats().replicationBacklog, 0);
producer1.close();
consumer2.close();
}
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class ReplicatorTest method testReplicatorClearBacklog.
@Test(timeOut = 30000)
public void testReplicatorClearBacklog() throws Exception {
// This test is to verify that reset cursor fails on global topic
SortedSet<String> testDests = new TreeSet<String>();
final TopicName dest = TopicName.get("persistent://pulsar/global/ns/clearBacklogTopic");
testDests.add(dest.toString());
MessageProducer producer1 = new MessageProducer(url1, dest);
MessageConsumer consumer1 = new MessageConsumer(url3, dest);
// Produce from cluster1 and consume from the rest
producer1.produce(2);
producer1.close();
PersistentTopic topic = (PersistentTopic) pulsar1.getBrokerService().getTopicReference(dest.toString());
PersistentReplicator replicator = (PersistentReplicator) spy(topic.getReplicators().get(topic.getReplicators().keys().get(0)));
replicator.readEntriesFailed(new ManagedLedgerException.InvalidCursorPositionException("failed"), null);
replicator.clearBacklog().get();
Thread.sleep(100);
// for code-coverage
replicator.updateRates();
// for code-coverage
replicator.expireMessages(1);
ReplicatorStats status = replicator.getStats();
assertTrue(status.replicationBacklog == 0);
consumer1.close();
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class ReplicatorTest method testReplication.
@Test(enabled = true, timeOut = 30000)
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 topics
SortedSet<String> testDests = new TreeSet<String>();
List<Future<Void>> results = Lists.newArrayList();
for (int i = 0; i < 3; i++) {
final TopicName dest = TopicName.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 org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class PersistentTopicE2ETest method testUnloadNamespace.
@Test(enabled = false)
public void testUnloadNamespace() throws Exception {
String topic = "persistent://prop/use/ns-abc/topic-9";
TopicName topicName = TopicName.get(topic);
pulsarClient.newProducer().topic(topic).create();
pulsarClient.close();
assertTrue(pulsar.getBrokerService().getTopicReference(topic) != null);
assertTrue(((ManagedLedgerFactoryImpl) pulsar.getManagedLedgerFactory()).getManagedLedgers().containsKey(topicName.getPersistenceNamingEncoding()));
admin.namespaces().unload("prop/use/ns-abc");
int i = 0;
for (i = 0; i < 30; i++) {
if (pulsar.getBrokerService().getTopicReference(topic) == null) {
break;
}
Thread.sleep(1000);
}
if (i == 30) {
fail("The topic reference should be null");
}
// ML should have been closed as well
assertFalse(((ManagedLedgerFactoryImpl) pulsar.getManagedLedgerFactory()).getManagedLedgers().containsKey(topicName.getPersistenceNamingEncoding()));
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class SimpleProducerConsumerTest method testFailReceiveAsyncOnConsumerClose.
@Test(timeOut = 5000)
public void testFailReceiveAsyncOnConsumerClose() throws Exception {
log.info("-- Starting {} test --", methodName);
// (1) simple consumers
Consumer<byte[]> consumer = pulsarClient.newConsumer().topic("persistent://my-property/use/my-ns/failAsyncReceive").subscriptionName("my-subscriber-name").subscribe();
consumer.close();
// receive messages
try {
consumer.receiveAsync().get(1, TimeUnit.SECONDS);
fail("it should have failed because consumer is already closed");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof PulsarClientException.AlreadyClosedException);
}
// (2) Partitioned-consumer
int numPartitions = 4;
TopicName topicName = TopicName.get("persistent://my-property/use/my-ns/failAsyncReceive");
admin.persistentTopics().createPartitionedTopic(topicName.toString(), numPartitions);
Consumer<byte[]> partitionedConsumer = pulsarClient.newConsumer().topic(topicName.toString()).subscriptionName("my-partitioned-subscriber").subscribe();
partitionedConsumer.close();
// receive messages
try {
partitionedConsumer.receiveAsync().get(1, TimeUnit.SECONDS);
fail("it should have failed because consumer is already closed");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof PulsarClientException.AlreadyClosedException);
}
log.info("-- Exiting {} test --", methodName);
}
Aggregations