Search in sources :

Example 1 with DispatchRateImpl

use of org.apache.pulsar.common.policies.data.impl.DispatchRateImpl in project pulsar by apache.

the class AbstractTopic method updateNamespaceDispatchRate.

private void updateNamespaceDispatchRate(Policies namespacePolicies, String cluster) {
    DispatchRateImpl dispatchRate = namespacePolicies.topicDispatchRate.get(cluster);
    if (dispatchRate == null) {
        dispatchRate = namespacePolicies.clusterDispatchRate.get(cluster);
    }
    topicPolicies.getDispatchRate().updateNamespaceValue(normalize(dispatchRate));
}
Also used : DispatchRateImpl(org.apache.pulsar.common.policies.data.impl.DispatchRateImpl)

Example 2 with DispatchRateImpl

use of org.apache.pulsar.common.policies.data.impl.DispatchRateImpl in project pulsar by apache.

the class MessageDispatchThrottlingTest method testDispatchRateCompatibility2.

@SuppressWarnings("deprecation")
@Test
public void testDispatchRateCompatibility2() throws Exception {
    final String namespace = "my-property/dispatch-rate-compatibility";
    final String topicName = "persistent://" + namespace + "/t1";
    final String cluster = "test";
    admin.namespaces().createNamespace(namespace, Sets.newHashSet(cluster));
    Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName).create();
    PersistentTopic topic = (PersistentTopic) pulsar.getBrokerService().getOrCreateTopic(topicName).get();
    DispatchRateLimiter dispatchRateLimiter = new DispatchRateLimiter(topic, DispatchRateLimiter.Type.TOPIC);
    Policies policies = new Policies();
    DispatchRateImpl clusterDispatchRate = DispatchRateImpl.builder().dispatchThrottlingRateInMsg(100).dispatchThrottlingRateInByte(512).ratePeriodInSecond(1).build();
    DispatchRateImpl topicDispatchRate = DispatchRateImpl.builder().dispatchThrottlingRateInMsg(200).dispatchThrottlingRateInByte(1024).ratePeriodInSecond(1).build();
    // (1) If both clusterDispatchRate and topicDispatchRate are empty, dispatch throttling is disabled
    dispatchRateLimiter.onPoliciesUpdate(policies);
    Assert.assertEquals(dispatchRateLimiter.getDispatchRateOnMsg(), -1);
    Assert.assertEquals(dispatchRateLimiter.getDispatchRateOnByte(), -1);
    // (2) If topicDispatchRate is empty, clusterDispatchRate is effective
    policies.clusterDispatchRate.put(cluster, clusterDispatchRate);
    dispatchRateLimiter.onPoliciesUpdate(policies);
    Assert.assertEquals(dispatchRateLimiter.getDispatchRateOnMsg(), 100);
    Assert.assertEquals(dispatchRateLimiter.getDispatchRateOnByte(), 512);
    // (3) If topicDispatchRate is not empty, topicDispatchRate is effective
    policies.topicDispatchRate.put(cluster, topicDispatchRate);
    dispatchRateLimiter.onPoliciesUpdate(policies);
    Assert.assertEquals(dispatchRateLimiter.getDispatchRateOnMsg(), 200);
    Assert.assertEquals(dispatchRateLimiter.getDispatchRateOnByte(), 1024);
    producer.close();
    topic.close().get();
}
Also used : Policies(org.apache.pulsar.common.policies.data.Policies) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) DispatchRateLimiter(org.apache.pulsar.broker.service.persistent.DispatchRateLimiter) DispatchRateImpl(org.apache.pulsar.common.policies.data.impl.DispatchRateImpl) Test(org.testng.annotations.Test)

Example 3 with DispatchRateImpl

use of org.apache.pulsar.common.policies.data.impl.DispatchRateImpl in project pulsar by apache.

the class MessageDispatchThrottlingTest method testDispatchRateCompatibility1.

@SuppressWarnings("deprecation")
@Test
public void testDispatchRateCompatibility1() throws Exception {
    final String cluster = "test";
    Optional<Policies> policies = Optional.of(new Policies());
    DispatchRateImpl clusterDispatchRate = DispatchRateImpl.builder().dispatchThrottlingRateInMsg(10).dispatchThrottlingRateInByte(512).ratePeriodInSecond(1).build();
    DispatchRateImpl topicDispatchRate = DispatchRateImpl.builder().dispatchThrottlingRateInMsg(200).dispatchThrottlingRateInByte(1024).ratePeriodInSecond(1).build();
    // (1) If both clusterDispatchRate and topicDispatchRate are empty, dispatch throttling is disabled
    DispatchRateImpl dispatchRate = DispatchRateLimiter.getPoliciesDispatchRate(cluster, policies, DispatchRateLimiter.Type.TOPIC);
    Assert.assertNull(dispatchRate);
    // (2) If topicDispatchRate is empty, clusterDispatchRate is effective
    policies.get().clusterDispatchRate.put(cluster, clusterDispatchRate);
    dispatchRate = DispatchRateLimiter.getPoliciesDispatchRate(cluster, policies, DispatchRateLimiter.Type.TOPIC);
    Assert.assertEquals(dispatchRate, clusterDispatchRate);
    // (3) If topicDispatchRate is not empty, topicDispatchRate is effective
    policies.get().topicDispatchRate.put(cluster, topicDispatchRate);
    dispatchRate = DispatchRateLimiter.getPoliciesDispatchRate(cluster, policies, DispatchRateLimiter.Type.TOPIC);
    Assert.assertEquals(dispatchRate, topicDispatchRate);
}
Also used : Policies(org.apache.pulsar.common.policies.data.Policies) DispatchRateImpl(org.apache.pulsar.common.policies.data.impl.DispatchRateImpl) Test(org.testng.annotations.Test)

Aggregations

DispatchRateImpl (org.apache.pulsar.common.policies.data.impl.DispatchRateImpl)3 Policies (org.apache.pulsar.common.policies.data.Policies)2 Test (org.testng.annotations.Test)2 DispatchRateLimiter (org.apache.pulsar.broker.service.persistent.DispatchRateLimiter)1 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)1