use of org.apache.pulsar.common.policies.data.PersistentTopicStats in project incubator-pulsar by apache.
the class BacklogQuotaManagerTest method testAheadProducerOnHold.
@Test
public void testAheadProducerOnHold() throws Exception {
assertEquals(admin.namespaces().getBacklogQuotaMap("prop/usc/quotahold"), Maps.newTreeMap());
admin.namespaces().setBacklogQuota("prop/usc/quotahold", new BacklogQuota(10 * 1024, BacklogQuota.RetentionPolicy.producer_request_hold));
final PulsarClient client = PulsarClient.builder().serviceUrl(adminUrl.toString()).statsInterval(0, TimeUnit.SECONDS).build();
final String topic1 = "persistent://prop/usc/quotahold/hold";
final String subName1 = "c1hold";
final int numMsgs = 10;
Consumer<byte[]> consumer = client.newConsumer().topic(topic1).subscriptionName(subName1).subscribe();
byte[] content = new byte[1024];
Producer<byte[]> producer = client.newProducer().topic(topic1).sendTimeout(2, TimeUnit.SECONDS).create();
for (int i = 0; i <= numMsgs; i++) {
try {
producer.send(content);
LOG.info("sent [{}]", i);
} catch (PulsarClientException.TimeoutException cte) {
// producer close may cause a timeout on send
LOG.info("timeout on [{}]", i);
}
}
for (int i = 0; i < numMsgs; i++) {
consumer.receive();
LOG.info("received [{}]", i);
}
Thread.sleep((TIME_TO_CHECK_BACKLOG_QUOTA + 1) * 1000);
rolloverStats();
PersistentTopicStats stats = admin.persistentTopics().getStats(topic1);
Assert.assertEquals(stats.publishers.size(), 0, "Number of producers on topic " + topic1 + " are [" + stats.publishers.size() + "]");
client.close();
}
use of org.apache.pulsar.common.policies.data.PersistentTopicStats in project incubator-pulsar by apache.
the class BacklogQuotaManagerTest method testConsumerBacklogEvictionWithAck.
@Test
public void testConsumerBacklogEvictionWithAck() throws Exception {
assertEquals(admin.namespaces().getBacklogQuotaMap("prop/usc/ns-quota"), Maps.newTreeMap());
admin.namespaces().setBacklogQuota("prop/usc/ns-quota", new BacklogQuota(10 * 1024, BacklogQuota.RetentionPolicy.consumer_backlog_eviction));
PulsarClient client = PulsarClient.builder().serviceUrl(adminUrl.toString()).build();
final String topic1 = "persistent://prop/usc/ns-quota/topic11";
final String subName1 = "c11";
final String subName2 = "c21";
final int numMsgs = 20;
Consumer<byte[]> consumer1 = client.newConsumer().topic(topic1).subscriptionName(subName1).subscribe();
Consumer<byte[]> consumer2 = client.newConsumer().topic(topic1).subscriptionName(subName2).subscribe();
org.apache.pulsar.client.api.Producer<byte[]> producer = client.newProducer().topic(topic1).create();
byte[] content = new byte[1024];
for (int i = 0; i < numMsgs; i++) {
producer.send(content);
// only one consumer acknowledges the message
consumer1.acknowledge(consumer1.receive());
consumer2.receive();
}
Thread.sleep((TIME_TO_CHECK_BACKLOG_QUOTA + 1) * 1000);
rolloverStats();
PersistentTopicStats stats = admin.persistentTopics().getStats(topic1);
Assert.assertTrue(stats.storageSize <= 10 * 1024, "Storage size is [" + stats.storageSize + "]");
client.close();
}
Aggregations