Search in sources :

Example 1 with SubscribeRate

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

the class NamespacesTest method testSubscribeRate.

@Test
public void testSubscribeRate() throws Exception {
    SubscribeRate subscribeRate = new SubscribeRate(1, 5);
    String namespace = "my-tenants/my-namespace";
    admin.tenants().createTenant("my-tenants", new TenantInfoImpl(Sets.newHashSet(), Sets.newHashSet(testLocalCluster)));
    admin.namespaces().createNamespace(namespace, Sets.newHashSet(testLocalCluster));
    admin.namespaces().setSubscribeRate(namespace, subscribeRate);
    assertEquals(subscribeRate, admin.namespaces().getSubscribeRate(namespace));
    String topicName = "persistent://" + namespace + "/" + "subscribe-rate";
    admin.topics().createPartitionedTopic(topicName, 2);
    pulsar.getConfiguration().setAuthorizationEnabled(false);
    Consumer<?> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionType(SubscriptionType.Shared).subscriptionName("subscribe-rate").subscribe();
    assertTrue(consumer.isConnected());
    // Subscribe Rate Limiter is enabled, will limited by broker
    pulsarClient.updateServiceUrl(lookupUrl.toString());
    Awaitility.await().untilAsserted(() -> assertFalse(consumer.isConnected()));
    // Out of limit period
    pulsarClient.updateServiceUrl(lookupUrl.toString());
    Awaitility.await().pollDelay(Duration.ofSeconds(6)).untilAsserted(() -> assertTrue(consumer.isConnected()));
    // Disable Subscribe Rate Limiter
    subscribeRate = new SubscribeRate(0, 10);
    admin.namespaces().setSubscribeRate(namespace, subscribeRate);
    pulsarClient.updateServiceUrl(lookupUrl.toString());
    Awaitility.await().untilAsserted(() -> assertTrue(consumer.isConnected()));
    pulsar.getConfiguration().setAuthorizationEnabled(true);
    admin.topics().deletePartitionedTopic(topicName, true);
    admin.namespaces().deleteNamespace(namespace);
    admin.tenants().deleteTenant("my-tenants");
}
Also used : SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 2 with SubscribeRate

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

the class TopicPoliciesDisableTest method testSubscribeRateDisabled.

@Test
public void testSubscribeRateDisabled() throws Exception {
    SubscribeRate subscribeRate = new SubscribeRate(10, 30);
    log.info("Subscribe Rate: {} will set to the topic: {}", subscribeRate, testTopic);
    try {
        admin.topics().setSubscribeRate(testTopic, subscribeRate);
        Assert.fail();
    } catch (PulsarAdminException e) {
        Assert.assertEquals(e.getStatusCode(), 405);
    }
    try {
        admin.topics().getSubscribeRate(testTopic);
        Assert.fail();
    } catch (PulsarAdminException e) {
        Assert.assertEquals(e.getStatusCode(), 405);
    }
}
Also used : SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 3 with SubscribeRate

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

the class PulsarAdminToolTest method topics.

@Test
public void topics() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    Topics mockTopics = mock(Topics.class);
    when(admin.topics()).thenReturn(mockTopics);
    Schemas mockSchemas = mock(Schemas.class);
    when(admin.schemas()).thenReturn(mockSchemas);
    Lookup mockLookup = mock(Lookup.class);
    when(admin.lookups()).thenReturn(mockLookup);
    CmdTopics cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("truncate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).truncate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("delete persistent://myprop/clust/ns1/ds1 -f -d"));
    verify(mockTopics).delete("persistent://myprop/clust/ns1/ds1", true, true);
    cmdTopics.run(split("unload persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).unload("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("permissions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPermissions("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("grant-permission persistent://myprop/clust/ns1/ds1 --role admin --actions produce,consume"));
    verify(mockTopics).grantPermission("persistent://myprop/clust/ns1/ds1", "admin", Sets.newHashSet(AuthAction.produce, AuthAction.consume));
    cmdTopics.run(split("revoke-permission persistent://myprop/clust/ns1/ds1 --role admin"));
    verify(mockTopics).revokePermissions("persistent://myprop/clust/ns1/ds1", "admin");
    cmdTopics.run(split("list myprop/clust/ns1"));
    verify(mockTopics).getList("myprop/clust/ns1", null, null);
    cmdTopics.run(split("lookup persistent://myprop/clust/ns1/ds1"));
    verify(mockLookup).lookupTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("partitioned-lookup persistent://myprop/clust/ns1/ds1"));
    verify(mockLookup).lookupPartitionedTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("partitioned-lookup persistent://myprop/clust/ns1/ds1 --sort-by-broker"));
    verify(mockLookup).lookupPartitionedTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("bundle-range persistent://myprop/clust/ns1/ds1"));
    verify(mockLookup).getBundleRange("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("subscriptions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getSubscriptions("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("unsubscribe persistent://myprop/clust/ns1/ds1 -s sub1"));
    verify(mockTopics).deleteSubscription("persistent://myprop/clust/ns1/ds1", "sub1", false);
    cmdTopics.run(split("stats persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getStats("persistent://myprop/clust/ns1/ds1", false, false, false);
    cmdTopics.run(split("stats-internal persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getInternalStats("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("get-backlog-quotas persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getBacklogQuotaMap("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-backlog-quota persistent://myprop/clust/ns1/ds1 -l 10 -p producer_request_hold"));
    verify(mockTopics).setBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.builder().limitSize(10).retentionPolicy(RetentionPolicy.producer_request_hold).build(), BacklogQuota.BacklogQuotaType.destination_storage);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("set-backlog-quota persistent://myprop/clust/ns1/ds1 -lt 1000 -p producer_request_hold -t message_age"));
    verify(mockTopics).setBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.builder().limitSize(-1).limitTime(1000).retentionPolicy(RetentionPolicy.producer_request_hold).build(), BacklogQuota.BacklogQuotaType.message_age);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("remove-backlog-quota persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.BacklogQuotaType.destination_storage);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("remove-backlog-quota persistent://myprop/clust/ns1/ds1 -t message_age"));
    verify(mockTopics).removeBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.BacklogQuotaType.message_age);
    cmdTopics.run(split("info-internal persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getInternalInfo("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("partitioned-stats persistent://myprop/clust/ns1/ds1 --per-partition"));
    verify(mockTopics).getPartitionedStats("persistent://myprop/clust/ns1/ds1", true, false, false);
    cmdTopics.run(split("partitioned-stats-internal persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPartitionedInternalStats("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("clear-backlog persistent://myprop/clust/ns1/ds1 -s sub1"));
    verify(mockTopics).skipAllMessages("persistent://myprop/clust/ns1/ds1", "sub1");
    cmdTopics.run(split("skip persistent://myprop/clust/ns1/ds1 -s sub1 -n 100"));
    verify(mockTopics).skipMessages("persistent://myprop/clust/ns1/ds1", "sub1", 100);
    cmdTopics.run(split("expire-messages persistent://myprop/clust/ns1/ds1 -s sub1 -t 100"));
    verify(mockTopics).expireMessages("persistent://myprop/clust/ns1/ds1", "sub1", 100);
    cmdTopics.run(split("get-subscribe-rate persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getSubscribeRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-subscribe-rate persistent://myprop/clust/ns1/ds1 -sr 2 -st 60"));
    verify(mockTopics).setSubscribeRate("persistent://myprop/clust/ns1/ds1", new SubscribeRate(2, 60));
    cmdTopics.run(split("remove-subscribe-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeSubscribeRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-replicated-subscription-status persistent://myprop/clust/ns1/ds1 -s sub1 -e"));
    verify(mockTopics).setReplicatedSubscriptionStatus("persistent://myprop/clust/ns1/ds1", "sub1", true);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("expire-messages persistent://myprop/clust/ns1/ds1 -s sub1 -p 1:1 -e"));
    verify(mockTopics).expireMessages(eq("persistent://myprop/clust/ns1/ds1"), eq("sub1"), eq(new MessageIdImpl(1, 1, -1)), eq(true));
    cmdTopics.run(split("expire-messages-all-subscriptions persistent://myprop/clust/ns1/ds1 -t 100"));
    verify(mockTopics).expireMessagesForAllSubscriptions("persistent://myprop/clust/ns1/ds1", 100);
    cmdTopics.run(split("create-subscription persistent://myprop/clust/ns1/ds1 -s sub1 --messageId earliest"));
    verify(mockTopics).createSubscription("persistent://myprop/clust/ns1/ds1", "sub1", MessageId.earliest);
    cmdTopics.run(split("create-partitioned-topic persistent://myprop/clust/ns1/ds1 --partitions 32"));
    verify(mockTopics).createPartitionedTopic("persistent://myprop/clust/ns1/ds1", 32, null);
    cmdTopics.run(split("create-missed-partitions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).createMissedPartitions("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("create persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).createNonPartitionedTopic("persistent://myprop/clust/ns1/ds1", new HashMap<>());
    cmdTopics.run(split("list-partitioned-topics myprop/clust/ns1"));
    verify(mockTopics).getPartitionedTopicList("myprop/clust/ns1");
    cmdTopics.run(split("update-partitioned-topic persistent://myprop/clust/ns1/ds1 -p 6"));
    verify(mockTopics).updatePartitionedTopic("persistent://myprop/clust/ns1/ds1", 6, false, false);
    cmdTopics.run(split("get-partitioned-topic-metadata persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPartitionedTopicMetadata("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("delete-partitioned-topic persistent://myprop/clust/ns1/ds1 -d -f"));
    verify(mockTopics).deletePartitionedTopic("persistent://myprop/clust/ns1/ds1", true, true);
    cmdTopics.run(split("peek-messages persistent://myprop/clust/ns1/ds1 -s sub1 -n 3"));
    verify(mockTopics).peekMessages("persistent://myprop/clust/ns1/ds1", "sub1", 3);
    MessageImpl message = mock(MessageImpl.class);
    when(message.getData()).thenReturn(new byte[] {});
    when(message.getMessageId()).thenReturn(new MessageIdImpl(1L, 1L, 1));
    when(mockTopics.examineMessage("persistent://myprop/clust/ns1/ds1", "latest", 1)).thenReturn(message);
    cmdTopics.run(split("examine-messages persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).examineMessage("persistent://myprop/clust/ns1/ds1", "latest", 1);
    cmdTopics.run(split("enable-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).enableDeduplication("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("disable-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).enableDeduplication("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-deduplication persistent://myprop/clust/ns1/ds1 --disable"));
    verify(mockTopics).setDeduplicationStatus("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2"));
    verify(mockTopics).setSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-subscription-types-enabled persistent://myprop/clust/ns1/ds1 -t Shared,Failover"));
    verify(mockTopics).setSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1", Sets.newHashSet(SubscriptionType.Shared, SubscriptionType.Failover));
    cmdTopics.run(split("get-subscription-types-enabled persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-subscription-types-enabled persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -md 10 -bd 11 -dt 12"));
    verify(mockTopics).setReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(10).dispatchThrottlingRateInByte(11).ratePeriodInSecond(12).build());
    cmdTopics.run(split("remove-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication-enabled persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics, times(2)).getDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-offload-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getOffloadPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-offload-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeOffloadPolicies("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-delayed-delivery persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-delayed-delivery persistent://myprop/clust/ns1/ds1 -t 10s --enable"));
    verify(mockTopics).setDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", DelayedDeliveryPolicies.builder().tickTime(10000).active(true).build());
    cmdTopics.run(split("remove-delayed-delivery persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-offload-policies persistent://myprop/clust/ns1/ds1 -d s3 -r region -b bucket -e endpoint -m 8 -rb 9 -t 10 -orp tiered-storage-first"));
    OffloadPoliciesImpl offloadPolicies = OffloadPoliciesImpl.create("s3", "region", "bucket", "endpoint", null, null, null, null, 8, 9, 10L, null, OffloadedReadPriority.TIERED_STORAGE_FIRST);
    verify(mockTopics).setOffloadPolicies("persistent://myprop/clust/ns1/ds1", offloadPolicies);
    cmdTopics.run(split("get-max-unacked-messages-on-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("get-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics, times(2)).getMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-unacked-messages-on-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics, times(2)).removeMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-unacked-messages-on-consumer persistent://myprop/clust/ns1/ds1 -m 999"));
    verify(mockTopics).setMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", 999);
    cmdTopics.run(split("set-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1 -m 999"));
    verify(mockTopics, times(2)).setMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", 999);
    cmdTopics.run(split("get-max-unacked-messages-on-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("get-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics, times(2)).getMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-unacked-messages-on-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics, times(2)).removeMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-publish-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-publish-rate persistent://myprop/clust/ns1/ds1 -m 100 -b 10240"));
    verify(mockTopics).setPublishRate("persistent://myprop/clust/ns1/ds1", new PublishRate(100, 10240L));
    cmdTopics.run(split("remove-publish-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removePublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-unacked-messages-on-subscription persistent://myprop/clust/ns1/ds1 -m 99"));
    verify(mockTopics).setMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("set-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1 -m 99"));
    verify(mockTopics, times(2)).setMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-compaction-threshold persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getCompactionThreshold("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-compaction-threshold persistent://myprop/clust/ns1/ds1 -t 10k"));
    verify(mockTopics).setCompactionThreshold("persistent://myprop/clust/ns1/ds1", 10 * 1024);
    cmdTopics.run(split("remove-compaction-threshold persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeCompactionThreshold("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-message-size persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-max-message-size persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1 -c 5"));
    verify(mockTopics).setMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1", 5);
    cmdTopics.run(split("remove-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-message-size persistent://myprop/clust/ns1/ds1 -m 99"));
    verify(mockTopics).setMaxMessageSize("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-message-by-id persistent://myprop/clust/ns1/ds1 -l 10 -e 2"));
    verify(mockTopics).getMessageById("persistent://myprop/clust/ns1/ds1", 10, 2);
    cmdTopics.run(split("get-dispatch-rate persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getDispatchRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("remove-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2"));
    verify(mockTopics).setDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-max-producers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxProducers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-producers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxProducers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-producers persistent://myprop/clust/ns1/ds1 -p 99"));
    verify(mockTopics).setMaxProducers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-max-consumers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxConsumers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-consumers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxConsumers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers persistent://myprop/clust/ns1/ds1 -c 99"));
    verify(mockTopics).setMaxConsumers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1 -i 99"));
    verify(mockTopics).setDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-inactive-topic-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-inactive-topic-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-inactive-topic-policies persistent://myprop/clust/ns1/ds1" + " -e -t 1s -m delete_when_no_subscriptions"));
    verify(mockTopics).setInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", new InactiveTopicPolicies(InactiveTopicDeleteMode.delete_when_no_subscriptions, 1, true));
    cmdTopics.run(split("get-max-subscriptions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-subscriptions persistent://myprop/clust/ns1/ds1 -m 100"));
    verify(mockTopics).setMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1", 100);
    cmdTopics.run(split("remove-max-subscriptions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-persistence persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPersistence("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-persistence persistent://myprop/clust/ns1/ds1 -e 2 -w 1 -a 1 -r 100.0"));
    verify(mockTopics).setPersistence("persistent://myprop/clust/ns1/ds1", new PersistencePolicies(2, 1, 1, 100.0d));
    cmdTopics.run(split("remove-persistence persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removePersistence("persistent://myprop/clust/ns1/ds1");
    // range of +/- 1 second of the expected timestamp
    class TimestampMatcher implements ArgumentMatcher<Long> {

        @Override
        public boolean matches(Long timestamp) {
            long expectedTimestamp = System.currentTimeMillis() - (1 * 60 * 1000);
            if (timestamp < (expectedTimestamp + 1000) && timestamp > (expectedTimestamp - 1000)) {
                return true;
            }
            return false;
        }
    }
    cmdTopics.run(split("reset-cursor persistent://myprop/clust/ns1/ds1 -s sub1 -t 1m"));
    verify(mockTopics).resetCursor(eq("persistent://myprop/clust/ns1/ds1"), eq("sub1"), longThat(new TimestampMatcher()));
    when(mockTopics.terminateTopicAsync("persistent://myprop/clust/ns1/ds1")).thenReturn(CompletableFuture.completedFuture(new MessageIdImpl(1L, 1L, 1)));
    cmdTopics.run(split("terminate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).terminateTopicAsync("persistent://myprop/clust/ns1/ds1");
    Map<Integer, MessageId> results = new HashMap<>();
    results.put(0, new MessageIdImpl(1, 1, 0));
    when(mockTopics.terminatePartitionedTopic("persistent://myprop/clust/ns1/ds1")).thenReturn(results);
    cmdTopics.run(split("partitioned-terminate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).terminatePartitionedTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("compact persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).triggerCompaction("persistent://myprop/clust/ns1/ds1");
    when(mockTopics.compactionStatus("persistent://myprop/clust/ns1/ds1")).thenReturn(new LongRunningProcessStatus());
    cmdTopics.run(split("compaction-status persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).compactionStatus("persistent://myprop/clust/ns1/ds1");
    PersistentTopicInternalStats stats = new PersistentTopicInternalStats();
    stats.ledgers = new ArrayList<>();
    stats.ledgers.add(newLedger(0, 10, 1000));
    stats.ledgers.add(newLedger(1, 10, 2000));
    stats.ledgers.add(newLedger(2, 10, 3000));
    when(mockTopics.getInternalStats("persistent://myprop/clust/ns1/ds1", false)).thenReturn(stats);
    cmdTopics.run(split("offload persistent://myprop/clust/ns1/ds1 -s 1k"));
    verify(mockTopics).triggerOffload("persistent://myprop/clust/ns1/ds1", new MessageIdImpl(2, 0, -1));
    when(mockTopics.offloadStatus("persistent://myprop/clust/ns1/ds1")).thenReturn(new OffloadProcessStatusImpl());
    cmdTopics.run(split("offload-status persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).offloadStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("last-message-id persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getLastMessageId(eq("persistent://myprop/clust/ns1/ds1"));
    cmdTopics.run(split("get-message-ttl persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMessageTTL("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-message-ttl persistent://myprop/clust/ns1/ds1 -t 10"));
    verify(mockTopics).setMessageTTL("persistent://myprop/clust/ns1/ds1", 10);
    cmdTopics.run(split("remove-message-ttl persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMessageTTL("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-replicated-subscription-status persistent://myprop/clust/ns1/ds1 -s sub1 -d"));
    verify(mockTopics).setReplicatedSubscriptionStatus("persistent://myprop/clust/ns1/ds1", "sub1", false);
    cmdTopics.run(split("get-replicated-subscription-status persistent://myprop/clust/ns1/ds1 -s sub1"));
    verify(mockTopics).getReplicatedSubscriptionStatus("persistent://myprop/clust/ns1/ds1", "sub1");
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("get-max-unacked-messages-on-subscription persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("reset-cursor persistent://myprop/clust/ns1/ds2 -s sub1 -m 1:1 -e"));
    verify(mockTopics).resetCursor(eq("persistent://myprop/clust/ns1/ds2"), eq("sub1"), eq(new MessageIdImpl(1, 1, -1)), eq(true));
    cmdTopics.run(split("get-maxProducers persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getMaxProducers("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-maxProducers persistent://myprop/clust/ns1/ds1 -p 3"));
    verify(mockTopics).setMaxProducers("persistent://myprop/clust/ns1/ds1", 3);
    cmdTopics.run(split("remove-maxProducers persistent://myprop/clust/ns1/ds2"));
    verify(mockTopics).removeMaxProducers("persistent://myprop/clust/ns1/ds2");
    cmdTopics.run(split("get-message-ttl persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getMessageTTL("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-offload-policies persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getOffloadPolicies("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-max-unacked-messages-on-consumer persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-inactive-topic-policies persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-delayed-delivery persistent://myprop/clust/ns1/ds1 --applied"));
    verify(mockTopics).getDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-max-consumers persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getMaxConsumers("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-replication-clusters persistent://myprop/clust/ns1/ds1 --applied"));
    verify(mockTopics).getReplicationClusters("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-replication-clusters persistent://myprop/clust/ns1/ds1 -c test"));
    verify(mockTopics).setReplicationClusters("persistent://myprop/clust/ns1/ds1", Lists.newArrayList("test"));
    cmdTopics.run(split("remove-replication-clusters persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeReplicationClusters("persistent://myprop/clust/ns1/ds1");
}
Also used : PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) HashMap(java.util.HashMap) OffloadProcessStatusImpl(org.apache.pulsar.client.admin.internal.OffloadProcessStatusImpl) ArgumentMatcher(org.mockito.ArgumentMatcher) PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats) Lookup(org.apache.pulsar.client.admin.Lookup) NonPersistentTopics(org.apache.pulsar.client.admin.NonPersistentTopics) Topics(org.apache.pulsar.client.admin.Topics) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) LongRunningProcessStatus(org.apache.pulsar.client.admin.LongRunningProcessStatus) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) Schemas(org.apache.pulsar.client.admin.Schemas) OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) MessageImpl(org.apache.pulsar.client.impl.MessageImpl) MessageId(org.apache.pulsar.client.api.MessageId) Test(org.testng.annotations.Test)

Example 4 with SubscribeRate

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

the class ReplicatorTopicPoliciesTest method testReplicateSubscribeRatePolicies.

@Test
public void testReplicateSubscribeRatePolicies() throws Exception {
    final String namespace = "pulsar/partitionedNs-" + UUID.randomUUID();
    final String topic = "persistent://" + namespace + "/topic" + UUID.randomUUID();
    init(namespace, topic);
    // set global topic policy
    SubscribeRate subscribeRate = new SubscribeRate(100, 10000);
    // local
    admin1.topicPolicies().setSubscribeRate(topic, subscribeRate);
    untilRemoteClustersAsserted(admin -> assertNull(admin.topicPolicies().getSubscribeRate(topic)));
    // global
    admin1.topicPolicies(true).setSubscribeRate(topic, subscribeRate);
    // get global topic policy
    untilRemoteClustersAsserted(admin -> assertEquals(admin.topicPolicies(true).getSubscribeRate(topic), subscribeRate));
    // remove global topic policy
    admin1.topicPolicies(true).removeSubscribeRate(topic);
    untilRemoteClustersAsserted(admin -> assertNull(admin.topicPolicies(true).getSubscribeRate(topic)));
}
Also used : SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) Test(org.testng.annotations.Test)

Example 5 with SubscribeRate

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

the class TopicPoliciesImpl method getSubscribeRateAsync.

@Override
public CompletableFuture<SubscribeRate> getSubscribeRateAsync(String topic, boolean applied) {
    TopicName topicName = validateTopic(topic);
    WebTarget path = topicPath(topicName, "subscribeRate");
    path = path.queryParam("applied", applied);
    final CompletableFuture<SubscribeRate> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<SubscribeRate>() {

        @Override
        public void completed(SubscribeRate subscribeRate) {
            future.complete(subscribeRate);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) WebTarget(javax.ws.rs.client.WebTarget) TopicName(org.apache.pulsar.common.naming.TopicName)

Aggregations

SubscribeRate (org.apache.pulsar.common.policies.data.SubscribeRate)13 Test (org.testng.annotations.Test)10 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)6 CompletableFuture (java.util.concurrent.CompletableFuture)3 WebTarget (javax.ws.rs.client.WebTarget)3 Lookup (org.apache.pulsar.client.admin.Lookup)3 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)3 InactiveTopicPolicies (org.apache.pulsar.common.policies.data.InactiveTopicPolicies)3 PersistencePolicies (org.apache.pulsar.common.policies.data.PersistencePolicies)3 PublishRate (org.apache.pulsar.common.policies.data.PublishRate)3 Schemas (org.apache.pulsar.client.admin.Schemas)2 PulsarClient (org.apache.pulsar.client.api.PulsarClient)2 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)2 TopicName (org.apache.pulsar.common.naming.TopicName)2 RetentionPolicies (org.apache.pulsar.common.policies.data.RetentionPolicies)2 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)1 SubscribeRateLimiter (org.apache.pulsar.broker.service.persistent.SubscribeRateLimiter)1