Search in sources :

Example 1 with DelayedDeliveryPolicies

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;
    });
}
Also used : InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) TopicPolicies(org.apache.pulsar.common.policies.data.TopicPolicies) DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies)

Example 2 with 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)));
}
Also used : DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) Test(org.testng.annotations.Test)

Example 3 with DelayedDeliveryPolicies

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;
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) CompletableFuture(java.util.concurrent.CompletableFuture) DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) WebTarget(javax.ws.rs.client.WebTarget) AutoTopicCreationOverride(org.apache.pulsar.common.policies.data.AutoTopicCreationOverride) AutoSubscriptionCreationOverride(org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride) AutoTopicCreationOverride(org.apache.pulsar.common.policies.data.AutoTopicCreationOverride) AutoSubscriptionCreationOverride(org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride)

Example 4 with DelayedDeliveryPolicies

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());
}
Also used : DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 5 with DelayedDeliveryPolicies

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)));
}
Also used : DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

DelayedDeliveryPolicies (org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies)10 Test (org.testng.annotations.Test)6 CompletableFuture (java.util.concurrent.CompletableFuture)3 WebTarget (javax.ws.rs.client.WebTarget)3 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)3 TopicName (org.apache.pulsar.common.naming.TopicName)2 HashSet (java.util.HashSet)1 Cleanup (lombok.Cleanup)1 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)1 AutoSubscriptionCreationOverride (org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride)1 AutoTopicCreationOverride (org.apache.pulsar.common.policies.data.AutoTopicCreationOverride)1 InactiveTopicPolicies (org.apache.pulsar.common.policies.data.InactiveTopicPolicies)1 TopicPolicies (org.apache.pulsar.common.policies.data.TopicPolicies)1