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));
}
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();
}
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);
}
Aggregations