Search in sources :

Example 26 with PersistentTopicStats

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();
}
Also used : PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) PulsarClient(org.apache.pulsar.client.api.PulsarClient) BacklogQuota(org.apache.pulsar.common.policies.data.BacklogQuota) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) Test(org.testng.annotations.Test)

Example 27 with PersistentTopicStats

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();
}
Also used : PulsarClient(org.apache.pulsar.client.api.PulsarClient) BacklogQuota(org.apache.pulsar.common.policies.data.BacklogQuota) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) Test(org.testng.annotations.Test)

Aggregations

PersistentTopicStats (org.apache.pulsar.common.policies.data.PersistentTopicStats)27 Test (org.testng.annotations.Test)22 PulsarClient (org.apache.pulsar.client.api.PulsarClient)12 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)6 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)6 BacklogQuota (org.apache.pulsar.common.policies.data.BacklogQuota)6 SubscriptionStats (org.apache.pulsar.common.policies.data.SubscriptionStats)6 URL (java.net.URL)5 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)5 PartitionedTopicStats (org.apache.pulsar.common.policies.data.PartitionedTopicStats)4 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)3 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)3 ClientConfiguration (org.apache.pulsar.client.api.ClientConfiguration)3 TopologyContext (org.apache.storm.task.TopologyContext)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 WebTarget (javax.ws.rs.client.WebTarget)2 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)2