use of org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies in project pulsar by apache.
the class PersistentTopicsBase method internalGetDelayedDeliveryPolicies.
protected CompletableFuture<DelayedDeliveryPolicies> internalGetDelayedDeliveryPolicies(boolean applied, boolean isGlobal) {
return getTopicPoliciesAsyncWithRetry(topicName, isGlobal).thenApply(op -> {
TopicPolicies policies = op.orElseGet(TopicPolicies::new);
DelayedDeliveryPolicies delayedDeliveryPolicies = null;
if (policies.isDelayedDeliveryEnabledSet() && policies.isDelayedDeliveryTickTimeMillisSet()) {
delayedDeliveryPolicies = DelayedDeliveryPolicies.builder().tickTime(policies.getDelayedDeliveryTickTimeMillis()).active(policies.getDelayedDeliveryEnabled()).build();
}
if (delayedDeliveryPolicies == null && applied) {
delayedDeliveryPolicies = getNamespacePolicies(namespaceName).delayed_delivery_policies;
if (delayedDeliveryPolicies == null) {
delayedDeliveryPolicies = DelayedDeliveryPolicies.builder().tickTime(pulsar().getConfiguration().getDelayedDeliveryTickTimeMillis()).active(pulsar().getConfiguration().isDelayedDeliveryEnabled()).build();
}
}
return delayedDeliveryPolicies;
});
}
use of org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies in project pulsar by apache.
the class ReplicatorTopicPoliciesTest method testReplicateDelayedDelivery.
@Test
public void testReplicateDelayedDelivery() throws Exception {
final String namespace = "pulsar/partitionedNs-" + UUID.randomUUID();
final String topic = "persistent://" + namespace + "/topic" + UUID.randomUUID();
init(namespace, topic);
DelayedDeliveryPolicies policies = DelayedDeliveryPolicies.builder().active(true).tickTime(10000L).build();
// local
admin1.topicPolicies().setDelayedDeliveryPolicy(topic, policies);
Awaitility.await().untilAsserted(() -> assertNull(admin2.topicPolicies().getDelayedDeliveryPolicy(topic)));
Awaitility.await().untilAsserted(() -> assertNull(admin3.topicPolicies().getDelayedDeliveryPolicy(topic)));
// global
admin1.topicPolicies(true).setDelayedDeliveryPolicy(topic, policies);
Awaitility.await().ignoreExceptions().untilAsserted(() -> assertEquals(admin2.topicPolicies(true).getDelayedDeliveryPolicy(topic), policies));
Awaitility.await().ignoreExceptions().untilAsserted(() -> assertEquals(admin3.topicPolicies(true).getDelayedDeliveryPolicy(topic), policies));
// remove delayed delivery
admin1.topicPolicies(true).removeDelayedDeliveryPolicy(topic);
Awaitility.await().untilAsserted(() -> assertNull(admin2.topicPolicies(true).getDelayedDeliveryPolicy(topic)));
Awaitility.await().untilAsserted(() -> assertNull(admin3.topicPolicies(true).getDelayedDeliveryPolicy(topic)));
}
use of org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies in project pulsar by apache.
the class NamespacesImpl method getDelayedDeliveryAsync.
@Override
public CompletableFuture<DelayedDeliveryPolicies> getDelayedDeliveryAsync(String namespace) {
NamespaceName ns = NamespaceName.get(namespace);
WebTarget path = namespacePath(ns, "delayedDelivery");
final CompletableFuture<DelayedDeliveryPolicies> future = new CompletableFuture<>();
asyncGetRequest(path, new InvocationCallback<DelayedDeliveryPolicies>() {
@Override
public void completed(DelayedDeliveryPolicies delayedDeliveryPolicies) {
future.complete(delayedDeliveryPolicies);
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
use of org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies in project pulsar by apache.
the class AdminApiDelayedDelivery method testDisableDelayedDelivery.
@Test
public void testDisableDelayedDelivery() throws Exception {
admin.namespaces().createNamespace("delayed-delivery-messages/default-ns");
String namespace = "delayed-delivery-messages/default-ns";
assertNull(admin.namespaces().getDelayedDelivery(namespace));
DelayedDeliveryPolicies delayedDeliveryPolicies = DelayedDeliveryPolicies.builder().tickTime(2000).active(false).build();
admin.namespaces().setDelayedDeliveryMessages(namespace, delayedDeliveryPolicies);
// zk update takes time
Awaitility.await().until(() -> admin.namespaces().getDelayedDelivery(namespace) != null);
assertFalse(admin.namespaces().getDelayedDelivery(namespace).isActive());
assertEquals(2000, admin.namespaces().getDelayedDelivery(namespace).getTickTime());
}
use of org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies in project pulsar by apache.
the class AdminApiDelayedDelivery method testNamespaceDelayedDeliveryPolicyApi.
@Test(timeOut = 30000)
public void testNamespaceDelayedDeliveryPolicyApi() throws Exception {
final String namespace = "delayed-delivery-messages/my-ns";
admin.namespaces().createNamespace(namespace);
assertNull(admin.namespaces().getDelayedDelivery(namespace));
DelayedDeliveryPolicies delayedDeliveryPolicies = DelayedDeliveryPolicies.builder().tickTime(3).active(true).build();
admin.namespaces().setDelayedDeliveryMessages(namespace, delayedDeliveryPolicies);
Awaitility.await().untilAsserted(() -> assertEquals(admin.namespaces().getDelayedDelivery(namespace), delayedDeliveryPolicies));
admin.namespaces().removeDelayedDeliveryMessages(namespace);
Awaitility.await().untilAsserted(() -> assertNull(admin.namespaces().getDelayedDelivery(namespace)));
}
Aggregations