Search in sources :

Example 11 with Schemas

use of org.apache.pulsar.client.admin.Schemas in project incubator-pulsar by apache.

the class TestPulsarConnector method setup.

@BeforeMethod
public void setup() throws Exception {
    this.pulsarConnectorConfig = spy(PulsarConnectorConfig.class);
    this.pulsarConnectorConfig.setMaxEntryReadBatchSize(1);
    this.pulsarConnectorConfig.setMaxSplitEntryQueueSize(10);
    this.pulsarConnectorConfig.setMaxSplitMessageQueueSize(100);
    Tenants tenants = mock(Tenants.class);
    doReturn(new LinkedList<>(topicNames.stream().map(TopicName::getTenant).collect(Collectors.toSet()))).when(tenants).getTenants();
    Namespaces namespaces = mock(Namespaces.class);
    when(namespaces.getNamespaces(anyString())).thenAnswer(new Answer<List<String>>() {

        @Override
        public List<String> answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            String tenant = (String) args[0];
            List<String> ns = getNamespace(tenant);
            if (ns.isEmpty()) {
                ClientErrorException cee = new ClientErrorException(Response.status(404).build());
                throw new PulsarAdminException(cee, cee.getMessage(), cee.getResponse().getStatus());
            }
            return ns;
        }
    });
    Topics topics = mock(Topics.class);
    when(topics.getList(anyString(), any())).thenAnswer(new Answer<List<String>>() {

        @Override
        public List<String> answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String ns = (String) args[0];
            List<String> topics = getTopics(ns);
            if (topics.isEmpty()) {
                ClientErrorException cee = new ClientErrorException(Response.status(404).build());
                throw new PulsarAdminException(cee, cee.getMessage(), cee.getResponse().getStatus());
            }
            return topics;
        }
    });
    when(topics.getPartitionedTopicList(anyString())).thenAnswer(new Answer<List<String>>() {

        @Override
        public List<String> answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String ns = (String) args[0];
            List<String> topics = getPartitionedTopics(ns);
            if (topics.isEmpty()) {
                ClientErrorException cee = new ClientErrorException(Response.status(404).build());
                throw new PulsarAdminException(cee, cee.getMessage(), cee.getResponse().getStatus());
            }
            return topics;
        }
    });
    when(topics.getPartitionedTopicMetadata(anyString())).thenAnswer(new Answer<PartitionedTopicMetadata>() {

        @Override
        public PartitionedTopicMetadata answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String topic = (String) args[0];
            int partitions = partitionedTopicsToPartitions.get(topic) == null ? 0 : partitionedTopicsToPartitions.get(topic);
            return new PartitionedTopicMetadata(partitions);
        }
    });
    schemas = mock(Schemas.class);
    when(schemas.getSchemaInfo(anyString())).thenAnswer(new Answer<SchemaInfo>() {

        @Override
        public SchemaInfo answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String topic = (String) args[0];
            if (topicsToSchemas.get(topic) != null) {
                return topicsToSchemas.get(topic);
            } else {
                ClientErrorException cee = new ClientErrorException(Response.status(404).build());
                throw new PulsarAdminException(cee, cee.getMessage(), cee.getResponse().getStatus());
            }
        }
    });
    pulsarAdmin = mock(PulsarAdmin.class);
    doReturn(tenants).when(pulsarAdmin).tenants();
    doReturn(namespaces).when(pulsarAdmin).namespaces();
    doReturn(topics).when(pulsarAdmin).topics();
    doReturn(schemas).when(pulsarAdmin).schemas();
    doReturn(pulsarAdmin).when(this.pulsarConnectorConfig).getPulsarAdmin();
    this.pulsarAuth = mock(PulsarAuth.class);
    this.pulsarMetadata = new PulsarMetadata(pulsarConnectorId, this.pulsarConnectorConfig, dispatchingRowDecoderFactory, this.pulsarAuth);
    this.pulsarSplitManager = Mockito.spy(new PulsarSplitManager(pulsarConnectorId, this.pulsarConnectorConfig));
    ManagedLedgerFactory managedLedgerFactory = mock(ManagedLedgerFactory.class);
    when(managedLedgerFactory.openReadOnlyCursor(any(), any(), any())).then(new Answer<ReadOnlyCursor>() {

        private Map<String, Integer> positions = new HashMap<>();

        private int count = 0;

        @Override
        public ReadOnlyCursor answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String topic = (String) args[0];
            PositionImpl positionImpl = (PositionImpl) args[1];
            int position = positionImpl.getEntryId() == -1 ? 0 : (int) positionImpl.getEntryId();
            positions.put(topic, position);
            String schemaName = TopicName.get(TopicName.get(topic.replaceAll("/persistent", "")).getPartitionedTopicName()).getSchemaName();
            long entries = topicsToNumEntries.get(schemaName);
            ReadOnlyCursorImpl readOnlyCursor = mock(ReadOnlyCursorImpl.class);
            doReturn(entries).when(readOnlyCursor).getNumberOfEntries();
            doAnswer(new Answer<Void>() {

                @Override
                public Void answer(InvocationOnMock invocation) throws Throwable {
                    Object[] args = invocation.getArguments();
                    Integer skipEntries = (Integer) args[0];
                    positions.put(topic, positions.get(topic) + skipEntries);
                    return null;
                }
            }).when(readOnlyCursor).skipEntries(anyInt());
            when(readOnlyCursor.getReadPosition()).thenAnswer(new Answer<PositionImpl>() {

                @Override
                public PositionImpl answer(InvocationOnMock invocationOnMock) throws Throwable {
                    return PositionImpl.get(0, positions.get(topic));
                }
            });
            doAnswer(new Answer() {

                @Override
                public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                    Object[] args = invocationOnMock.getArguments();
                    Integer readEntries = (Integer) args[0];
                    AsyncCallbacks.ReadEntriesCallback callback = (AsyncCallbacks.ReadEntriesCallback) args[2];
                    Object ctx = args[3];
                    new Thread(new Runnable() {

                        @Override
                        public void run() {
                            List<Entry> entries = new LinkedList<>();
                            for (int i = 0; i < readEntries; i++) {
                                TestPulsarConnector.Bar bar = new TestPulsarConnector.Bar();
                                bar.field1 = fooFunctions.get("bar.field1").apply(count) == null ? null : (int) fooFunctions.get("bar.field1").apply(count);
                                bar.field2 = fooFunctions.get("bar.field2").apply(count) == null ? null : (String) fooFunctions.get("bar.field2").apply(count);
                                bar.field3 = (float) fooFunctions.get("bar.field3").apply(count);
                                Foo foo = new Foo();
                                foo.field1 = (int) fooFunctions.get("field1").apply(count);
                                foo.field2 = (String) fooFunctions.get("field2").apply(count);
                                foo.field3 = (float) fooFunctions.get("field3").apply(count);
                                foo.field4 = (double) fooFunctions.get("field4").apply(count);
                                foo.field5 = (boolean) fooFunctions.get("field5").apply(count);
                                foo.field6 = (long) fooFunctions.get("field6").apply(count);
                                foo.timestamp = (long) fooFunctions.get("timestamp").apply(count);
                                foo.time = (int) fooFunctions.get("time").apply(count);
                                foo.date = (int) fooFunctions.get("date").apply(count);
                                foo.decimal = (BigDecimal) fooFunctions.get("decimal").apply(count);
                                foo.bar = bar;
                                foo.field7 = (Foo.TestEnum) fooFunctions.get("field7").apply(count);
                                MessageMetadata messageMetadata = new MessageMetadata().setProducerName("test-producer").setSequenceId(positions.get(topic)).setPublishTime(System.currentTimeMillis());
                                Schema schema = topicsToSchemas.get(schemaName).getType() == SchemaType.AVRO ? AvroSchema.of(Foo.class) : JSONSchema.of(Foo.class);
                                ByteBuf payload = io.netty.buffer.Unpooled.copiedBuffer(schema.encode(foo));
                                ByteBuf byteBuf = serializeMetadataAndPayload(Commands.ChecksumType.Crc32c, messageMetadata, payload);
                                completedBytes += byteBuf.readableBytes();
                                entries.add(EntryImpl.create(0, positions.get(topic), byteBuf));
                                positions.put(topic, positions.get(topic) + 1);
                                count++;
                            }
                            callback.readEntriesComplete(entries, ctx);
                        }
                    }).start();
                    return null;
                }
            }).when(readOnlyCursor).asyncReadEntries(anyInt(), anyLong(), any(), any(), any());
            when(readOnlyCursor.hasMoreEntries()).thenAnswer(new Answer<Boolean>() {

                @Override
                public Boolean answer(InvocationOnMock invocationOnMock) throws Throwable {
                    return positions.get(topic) < entries;
                }
            });
            when(readOnlyCursor.findNewestMatching(any(), any())).then(new Answer<Position>() {

                @Override
                public Position answer(InvocationOnMock invocationOnMock) throws Throwable {
                    Object[] args = invocationOnMock.getArguments();
                    com.google.common.base.Predicate<Entry> predicate = (com.google.common.base.Predicate<Entry>) args[1];
                    String schemaName = TopicName.get(TopicName.get(topic.replaceAll("/persistent", "")).getPartitionedTopicName()).getSchemaName();
                    List<Entry> entries = getTopicEntries(schemaName);
                    Integer target = null;
                    for (int i = entries.size() - 1; i >= 0; i--) {
                        Entry entry = entries.get(i);
                        if (predicate.apply(entry)) {
                            target = i;
                            break;
                        }
                    }
                    return target == null ? null : new PositionImpl(0, target);
                }
            });
            when(readOnlyCursor.getNumberOfEntries(any())).then(new Answer<Long>() {

                @Override
                public Long answer(InvocationOnMock invocationOnMock) throws Throwable {
                    Object[] args = invocationOnMock.getArguments();
                    com.google.common.collect.Range<PositionImpl> range = (com.google.common.collect.Range<PositionImpl>) args[0];
                    return (range.upperEndpoint().getEntryId() + 1) - range.lowerEndpoint().getEntryId();
                }
            });
            when(readOnlyCursor.getCurrentLedgerInfo()).thenReturn(MLDataFormats.ManagedLedgerInfo.LedgerInfo.newBuilder().setLedgerId(0).build());
            return readOnlyCursor;
        }
    });
    PulsarConnectorCache.instance = mock(PulsarConnectorCache.class);
    when(PulsarConnectorCache.instance.getManagedLedgerFactory()).thenReturn(managedLedgerFactory);
    for (Map.Entry<TopicName, PulsarSplit> split : splits.entrySet()) {
        PulsarRecordCursor pulsarRecordCursor = spy(new PulsarRecordCursor(topicsToColumnHandles.get(split.getKey()), split.getValue(), pulsarConnectorConfig, managedLedgerFactory, new ManagedLedgerConfig(), new PulsarConnectorMetricsTracker(new NullStatsProvider()), dispatchingRowDecoderFactory));
        this.pulsarRecordCursors.put(split.getKey(), pulsarRecordCursor);
    }
}
Also used : Namespaces(org.apache.pulsar.client.admin.Namespaces) HashMap(java.util.HashMap) JSONSchema(org.apache.pulsar.client.impl.schema.JSONSchema) AvroSchema(org.apache.pulsar.client.impl.schema.AvroSchema) Schema(org.apache.pulsar.client.api.Schema) Mockito.anyString(org.mockito.Mockito.anyString) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) SchemaInfo(org.apache.pulsar.common.schema.SchemaInfo) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Schemas(org.apache.pulsar.client.admin.Schemas) LinkedList(java.util.LinkedList) TopicName(org.apache.pulsar.common.naming.TopicName) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Map(java.util.Map) HashMap(java.util.HashMap) ReadOnlyCursorImpl(org.apache.bookkeeper.mledger.impl.ReadOnlyCursorImpl) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) Tenants(org.apache.pulsar.client.admin.Tenants) ByteBuf(io.netty.buffer.ByteBuf) Entry(org.apache.bookkeeper.mledger.Entry) MessageMetadata(org.apache.pulsar.common.api.proto.MessageMetadata) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) Topics(org.apache.pulsar.client.admin.Topics) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ClientErrorException(javax.ws.rs.ClientErrorException) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 12 with Schemas

use of org.apache.pulsar.client.admin.Schemas in project incubator-pulsar by apache.

the class PulsarAdminToolTest method schemas.

@Test
void schemas() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    Schemas schemas = Mockito.mock(Schemas.class);
    doReturn(schemas).when(admin).schemas();
    CmdSchemas cmdSchemas = new CmdSchemas(() -> admin);
    cmdSchemas.run(split("get -v 1 persistent://tn1/ns1/tp1"));
    verify(schemas).getSchemaInfo("persistent://tn1/ns1/tp1", 1);
    cmdSchemas = new CmdSchemas(() -> admin);
    cmdSchemas.run(split("get -a persistent://tn1/ns1/tp1"));
    verify(schemas).getAllSchemas("persistent://tn1/ns1/tp1");
    cmdSchemas = new CmdSchemas(() -> admin);
    cmdSchemas.run(split("get persistent://tn1/ns1/tp1"));
    verify(schemas).getSchemaInfoWithVersion("persistent://tn1/ns1/tp1");
    cmdSchemas = new CmdSchemas(() -> admin);
    cmdSchemas.run(split("delete persistent://tn1/ns1/tp1"));
    verify(schemas).deleteSchema("persistent://tn1/ns1/tp1", false);
    cmdSchemas = new CmdSchemas(() -> admin);
    cmdSchemas.run(split("delete persistent://tn1/ns1/tp1 -f"));
    verify(schemas).deleteSchema("persistent://tn1/ns1/tp1", true);
    cmdSchemas = new CmdSchemas(() -> admin);
    String schemaFile = PulsarAdminToolTest.class.getClassLoader().getResource("test_schema_create.json").getFile();
    cmdSchemas.run(split("upload -f " + schemaFile + " persistent://tn1/ns1/tp1"));
    PostSchemaPayload input = new ObjectMapper().readValue(new File(schemaFile), PostSchemaPayload.class);
    verify(schemas).createSchema("persistent://tn1/ns1/tp1", input);
    cmdSchemas = new CmdSchemas(() -> admin);
    String jarFile = PulsarAdminToolTest.class.getClassLoader().getResource("dummyexamples.jar").getFile();
    String className = SchemaDemo.class.getName();
    cmdSchemas.run(split("extract -j " + jarFile + " -c " + className + " -t json persistent://tn1/ns1/tp1"));
    File file = new File(jarFile);
    ClassLoader cl = new URLClassLoader(new URL[] { file.toURI().toURL() });
    Class cls = cl.loadClass(className);
    SchemaDefinition<Object> schemaDefinition = SchemaDefinition.builder().withPojo(cls).withAlwaysAllowNull(true).build();
    PostSchemaPayload postSchemaPayload = new PostSchemaPayload();
    postSchemaPayload.setType("JSON");
    postSchemaPayload.setSchema(SchemaExtractor.getJsonSchemaInfo(schemaDefinition));
    postSchemaPayload.setProperties(schemaDefinition.getProperties());
    verify(schemas).createSchema("persistent://tn1/ns1/tp1", postSchemaPayload);
}
Also used : PostSchemaPayload(org.apache.pulsar.common.protocol.schema.PostSchemaPayload) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) Schemas(org.apache.pulsar.client.admin.Schemas) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 13 with Schemas

use of org.apache.pulsar.client.admin.Schemas in project incubator-pulsar by apache.

the class PulsarAdminToolTest method topicPolicies.

@Test
public void topicPolicies() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    TopicPolicies mockTopicsPolicies = mock(TopicPolicies.class);
    TopicPolicies mockGlobalTopicsPolicies = mock(TopicPolicies.class);
    when(admin.topicPolicies()).thenReturn(mockTopicsPolicies);
    when(admin.topicPolicies(false)).thenReturn(mockTopicsPolicies);
    when(admin.topicPolicies(true)).thenReturn(mockGlobalTopicsPolicies);
    Schemas mockSchemas = mock(Schemas.class);
    when(admin.schemas()).thenReturn(mockSchemas);
    Lookup mockLookup = mock(Lookup.class);
    when(admin.lookups()).thenReturn(mockLookup);
    CmdTopicPolicies cmdTopics = new CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("set-subscription-types-enabled persistent://myprop/clust/ns1/ds1 -t Shared,Failover"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).getSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-subscription-types-enabled persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-offload-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getOffloadPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-offload-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeOffloadPolicies("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"));
    verify(mockTopicsPolicies).setOffloadPolicies("persistent://myprop/clust/ns1/ds1", OffloadPoliciesImpl.create("s3", "region", "bucket", "endpoint", null, null, null, null, 8, 9, 10L, null, OffloadedReadPriority.TIERED_STORAGE_FIRST));
    cmdTopics.run(split("get-retention persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getRetention("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 10m -s 20M"));
    verify(mockTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1", new RetentionPolicies(10, 20));
    cmdTopics.run(split("remove-retention persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeRetention("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-inactive-topic-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-inactive-topic-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).setInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", new InactiveTopicPolicies(InactiveTopicDeleteMode.delete_when_no_subscriptions, 1, true));
    cmdTopics.run(split("get-compaction-threshold persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getCompactionThreshold("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-compaction-threshold persistent://myprop/clust/ns1/ds1 -t 10k"));
    verify(mockTopicsPolicies).setCompactionThreshold("persistent://myprop/clust/ns1/ds1", 10 * 1024);
    cmdTopics.run(split("remove-compaction-threshold persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeCompactionThreshold("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-producers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMaxProducers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-producers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMaxProducers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-producers persistent://myprop/clust/ns1/ds1 -p 99"));
    verify(mockTopicsPolicies).setMaxProducers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-dispatch-rate persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopicsPolicies).getDispatchRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("remove-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2"));
    verify(mockTopicsPolicies).setDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("set-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2"));
    verify(mockTopicsPolicies).setReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).getSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics = new CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("set-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -s sub -md -1 -bd -1 -dt 3"));
    verify(mockTopicsPolicies).setSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", "sub", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(3).build());
    cmdTopics.run(split("get-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -s sub"));
    verify(mockTopicsPolicies).getSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", "sub", false);
    cmdTopics.run(split("remove-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -s sub"));
    verify(mockTopicsPolicies).removeSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", "sub");
    cmdTopics.run(split("get-persistence persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).setPersistence("persistent://myprop/clust/ns1/ds1", new PersistencePolicies(2, 1, 1, 100.0d));
    cmdTopics.run(split("remove-persistence persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removePersistence("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-publish-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getPublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-publish-rate persistent://myprop/clust/ns1/ds1 -m 10 -b 100"));
    verify(mockTopicsPolicies).setPublishRate("persistent://myprop/clust/ns1/ds1", new PublishRate(10, 100));
    cmdTopics.run(split("remove-publish-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removePublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-subscribe-rate persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopicsPolicies).getSubscribeRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-subscribe-rate persistent://myprop/clust/ns1/ds1 -sr 10 -st 100"));
    verify(mockTopicsPolicies).setSubscribeRate("persistent://myprop/clust/ns1/ds1", new SubscribeRate(10, 100));
    cmdTopics.run(split("remove-subscribe-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeSubscribeRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-message-size persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-message-size persistent://myprop/clust/ns1/ds1 -m 1000"));
    verify(mockTopicsPolicies).setMaxMessageSize("persistent://myprop/clust/ns1/ds1", 1000);
    cmdTopics.run(split("remove-max-message-size persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-consumers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMaxConsumers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-consumers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMaxConsumers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers persistent://myprop/clust/ns1/ds1 -c 99"));
    verify(mockTopicsPolicies).setMaxConsumers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("remove-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies, times(1)).removeMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies, times(1)).getMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1 -m 999"));
    verify(mockTopicsPolicies, times(1)).setMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", 999);
    cmdTopics.run(split("get-message-ttl persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMessageTTL("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-message-ttl persistent://myprop/clust/ns1/ds1 -t 10"));
    verify(mockTopicsPolicies).setMessageTTL("persistent://myprop/clust/ns1/ds1", 10);
    cmdTopics.run(split("remove-message-ttl persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMessageTTL("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1 -c 5"));
    verify(mockTopicsPolicies).setMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1", 5);
    cmdTopics.run(split("remove-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies, times(1)).getMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies, times(1)).removeMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1 -m 99"));
    verify(mockTopicsPolicies, times(1)).setMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-delayed-delivery persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-delayed-delivery persistent://myprop/clust/ns1/ds1 -t 10s --enable"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).removeDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-deduplication persistent://myprop/clust/ns1/ds1 --disable"));
    verify(mockTopicsPolicies).setDeduplicationStatus("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1 -s 1024"));
    verify(mockTopicsPolicies).setMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1", 1024);
    cmdTopics.run(split("remove-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1 -i 100"));
    verify(mockTopicsPolicies).setDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1", 100);
    cmdTopics.run(split("remove-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    // Reset the cmd, and check global option
    cmdTopics = new CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("get-retention persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getRetention("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 10m -s 20M -g"));
    verify(mockGlobalTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1", new RetentionPolicies(10, 20));
    cmdTopics.run(split("remove-retention persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeRetention("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-backlog-quota persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).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 CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("set-message-ttl persistent://myprop/clust/ns1/ds1 -t 10h"));
    verify(mockTopicsPolicies).setMessageTTL("persistent://myprop/clust/ns1/ds1", 10 * 60 * 60);
    cmdTopics.run(split("set-backlog-quota persistent://myprop/clust/ns1/ds1 -lt 1w -p consumer_backlog_eviction"));
    verify(mockTopicsPolicies).setBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.builder().limitSize(-1).limitTime(60 * 60 * 24 * 7).retentionPolicy(RetentionPolicy.consumer_backlog_eviction).build(), BacklogQuota.BacklogQuotaType.destination_storage);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("set-backlog-quota persistent://myprop/clust/ns1/ds1 -lt 1000 -p producer_request_hold -t message_age"));
    verify(mockTopicsPolicies).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 CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("remove-backlog-quota persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.BacklogQuotaType.destination_storage);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("remove-backlog-quota persistent://myprop/clust/ns1/ds1 -t message_age"));
    verify(mockTopicsPolicies).removeBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.BacklogQuotaType.message_age);
    cmdTopics.run(split("get-max-producers persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMaxProducers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-producers persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMaxProducers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-producers persistent://myprop/clust/ns1/ds1 -p 99 -g"));
    verify(mockGlobalTopicsPolicies).setMaxProducers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("remove-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).removeMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).getMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1 -m 999 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).setMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", 999);
    cmdTopics.run(split("get-message-ttl persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMessageTTL("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-message-ttl persistent://myprop/clust/ns1/ds1 -t 10 -g"));
    verify(mockGlobalTopicsPolicies).setMessageTTL("persistent://myprop/clust/ns1/ds1", 10);
    cmdTopics.run(split("remove-message-ttl persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMessageTTL("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-persistence persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).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 -g"));
    verify(mockGlobalTopicsPolicies).setPersistence("persistent://myprop/clust/ns1/ds1", new PersistencePolicies(2, 1, 1, 100.0d));
    cmdTopics.run(split("remove-persistence persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removePersistence("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).getMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).removeMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1 -m 99 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).setMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-inactive-topic-policies persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-inactive-topic-policies persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).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 -g"));
    verify(mockGlobalTopicsPolicies).setInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", new InactiveTopicPolicies(InactiveTopicDeleteMode.delete_when_no_subscriptions, 1, true));
    cmdTopics.run(split("get-dispatch-rate persistent://myprop/clust/ns1/ds1 -ap -g"));
    verify(mockGlobalTopicsPolicies).getDispatchRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("remove-dispatch-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2 -g"));
    verify(mockGlobalTopicsPolicies).setDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-publish-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getPublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-publish-rate persistent://myprop/clust/ns1/ds1 -m 10 -b 100 -g"));
    verify(mockGlobalTopicsPolicies).setPublishRate("persistent://myprop/clust/ns1/ds1", new PublishRate(10, 100));
    cmdTopics.run(split("remove-publish-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removePublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-subscribe-rate persistent://myprop/clust/ns1/ds1 -ap -g"));
    verify(mockGlobalTopicsPolicies).getSubscribeRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-subscribe-rate persistent://myprop/clust/ns1/ds1 -sr 10 -st 100 -g"));
    verify(mockGlobalTopicsPolicies).setSubscribeRate("persistent://myprop/clust/ns1/ds1", new SubscribeRate(10, 100));
    cmdTopics.run(split("remove-subscribe-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeSubscribeRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-delayed-delivery persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-delayed-delivery persistent://myprop/clust/ns1/ds1 -t 10s --enable -g"));
    verify(mockGlobalTopicsPolicies).setDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", DelayedDeliveryPolicies.builder().tickTime(10000).active(true).build());
    cmdTopics.run(split("remove-delayed-delivery persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-message-size persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-message-size persistent://myprop/clust/ns1/ds1 -m 1000 -g"));
    verify(mockGlobalTopicsPolicies).setMaxMessageSize("persistent://myprop/clust/ns1/ds1", 1000);
    cmdTopics.run(split("remove-max-message-size persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-deduplication persistent://myprop/clust/ns1/ds1 --disable -g"));
    verify(mockGlobalTopicsPolicies).setDeduplicationStatus("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-deduplication persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1 -i 100 -g"));
    verify(mockGlobalTopicsPolicies).setDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1", 100);
    cmdTopics.run(split("remove-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1 -c 5 -g"));
    verify(mockGlobalTopicsPolicies).setMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1", 5);
    cmdTopics.run(split("remove-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-subscription-types-enabled persistent://myprop/clust/ns1/ds1 -t Shared,Failover -g"));
    verify(mockGlobalTopicsPolicies).setSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1", Sets.newHashSet(SubscriptionType.Shared, SubscriptionType.Failover));
    cmdTopics.run(split("get-subscription-types-enabled persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-subscription-types-enabled persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-consumers persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMaxConsumers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-consumers persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMaxConsumers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers persistent://myprop/clust/ns1/ds1 -c 99 -g"));
    verify(mockGlobalTopicsPolicies).setMaxConsumers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-compaction-threshold persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getCompactionThreshold("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-compaction-threshold persistent://myprop/clust/ns1/ds1 -t 10k -g"));
    verify(mockGlobalTopicsPolicies).setCompactionThreshold("persistent://myprop/clust/ns1/ds1", 10 * 1024);
    cmdTopics.run(split("remove-compaction-threshold persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeCompactionThreshold("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2 -g"));
    verify(mockGlobalTopicsPolicies).setReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2 -g"));
    verify(mockGlobalTopicsPolicies).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 -g"));
    verify(mockGlobalTopicsPolicies).getSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics = new CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("set-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -s sub -md -1 -bd -1 -dt 2 -g"));
    verify(mockGlobalTopicsPolicies).setSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", "sub", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -s sub -g"));
    verify(mockGlobalTopicsPolicies).getSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", "sub", false);
    cmdTopics.run(split("remove-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -s sub -g"));
    verify(mockGlobalTopicsPolicies).removeSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", "sub");
    cmdTopics.run(split("get-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1 -s 1024 -g"));
    verify(mockGlobalTopicsPolicies).setMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1", 1024);
    cmdTopics.run(split("remove-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-offload-policies persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getOffloadPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-offload-policies persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeOffloadPolicies("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 -g"));
    verify(mockGlobalTopicsPolicies).setOffloadPolicies("persistent://myprop/clust/ns1/ds1", OffloadPoliciesImpl.create("s3", "region", "bucket", "endpoint", null, null, null, null, 8, 9, 10L, null, OffloadedReadPriority.TIERED_STORAGE_FIRST));
}
Also used : RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) TopicPolicies(org.apache.pulsar.client.admin.TopicPolicies) PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) Lookup(org.apache.pulsar.client.admin.Lookup) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) Schemas(org.apache.pulsar.client.admin.Schemas) Test(org.testng.annotations.Test)

Example 14 with Schemas

use of org.apache.pulsar.client.admin.Schemas in project pulsar by yahoo.

the class TestCmdTopics method setup.

@BeforeMethod
public void setup() throws Exception {
    pulsarAdmin = Mockito.mock(PulsarAdmin.class);
    Topics mockTopics = mock(Topics.class);
    when(pulsarAdmin.topics()).thenReturn(mockTopics);
    Schemas mockSchemas = mock(Schemas.class);
    when(pulsarAdmin.schemas()).thenReturn(mockSchemas);
    mockLookup = mock(Lookup.class);
    when(pulsarAdmin.lookups()).thenReturn(mockLookup);
    cmdTopics = spy(new CmdTopics(() -> pulsarAdmin));
    partitionedLookup = spy(cmdTopics.getPartitionedLookup());
}
Also used : Topics(org.apache.pulsar.client.admin.Topics) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Lookup(org.apache.pulsar.client.admin.Lookup) Schemas(org.apache.pulsar.client.admin.Schemas) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 15 with Schemas

use of org.apache.pulsar.client.admin.Schemas in project pulsar by yahoo.

the class PulsarAdminToolTest method topicPolicies.

@Test
public void topicPolicies() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    TopicPolicies mockTopicsPolicies = mock(TopicPolicies.class);
    TopicPolicies mockGlobalTopicsPolicies = mock(TopicPolicies.class);
    when(admin.topicPolicies()).thenReturn(mockTopicsPolicies);
    when(admin.topicPolicies(false)).thenReturn(mockTopicsPolicies);
    when(admin.topicPolicies(true)).thenReturn(mockGlobalTopicsPolicies);
    Schemas mockSchemas = mock(Schemas.class);
    when(admin.schemas()).thenReturn(mockSchemas);
    Lookup mockLookup = mock(Lookup.class);
    when(admin.lookups()).thenReturn(mockLookup);
    CmdTopicPolicies cmdTopics = new CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("set-subscription-types-enabled persistent://myprop/clust/ns1/ds1 -t Shared,Failover"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).getSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-subscription-types-enabled persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-offload-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getOffloadPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-offload-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeOffloadPolicies("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"));
    verify(mockTopicsPolicies).setOffloadPolicies("persistent://myprop/clust/ns1/ds1", OffloadPoliciesImpl.create("s3", "region", "bucket", "endpoint", null, null, null, null, 8, 9, 10L, null, OffloadedReadPriority.TIERED_STORAGE_FIRST));
    cmdTopics.run(split("get-retention persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getRetention("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 10m -s 20M"));
    verify(mockTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1", new RetentionPolicies(10, 20));
    cmdTopics.run(split("remove-retention persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeRetention("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-inactive-topic-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-inactive-topic-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).setInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", new InactiveTopicPolicies(InactiveTopicDeleteMode.delete_when_no_subscriptions, 1, true));
    cmdTopics.run(split("get-compaction-threshold persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getCompactionThreshold("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-compaction-threshold persistent://myprop/clust/ns1/ds1 -t 10k"));
    verify(mockTopicsPolicies).setCompactionThreshold("persistent://myprop/clust/ns1/ds1", 10 * 1024);
    cmdTopics.run(split("remove-compaction-threshold persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeCompactionThreshold("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-producers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMaxProducers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-producers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMaxProducers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-producers persistent://myprop/clust/ns1/ds1 -p 99"));
    verify(mockTopicsPolicies).setMaxProducers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-dispatch-rate persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopicsPolicies).getDispatchRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("remove-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2"));
    verify(mockTopicsPolicies).setDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("set-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2"));
    verify(mockTopicsPolicies).setReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).getSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-persistence persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).setPersistence("persistent://myprop/clust/ns1/ds1", new PersistencePolicies(2, 1, 1, 100.0d));
    cmdTopics.run(split("remove-persistence persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removePersistence("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-publish-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getPublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-publish-rate persistent://myprop/clust/ns1/ds1 -m 10 -b 100"));
    verify(mockTopicsPolicies).setPublishRate("persistent://myprop/clust/ns1/ds1", new PublishRate(10, 100));
    cmdTopics.run(split("remove-publish-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removePublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-subscribe-rate persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopicsPolicies).getSubscribeRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-subscribe-rate persistent://myprop/clust/ns1/ds1 -sr 10 -st 100"));
    verify(mockTopicsPolicies).setSubscribeRate("persistent://myprop/clust/ns1/ds1", new SubscribeRate(10, 100));
    cmdTopics.run(split("remove-subscribe-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeSubscribeRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-message-size persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-message-size persistent://myprop/clust/ns1/ds1 -m 1000"));
    verify(mockTopicsPolicies).setMaxMessageSize("persistent://myprop/clust/ns1/ds1", 1000);
    cmdTopics.run(split("remove-max-message-size persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-consumers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMaxConsumers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-consumers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMaxConsumers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers persistent://myprop/clust/ns1/ds1 -c 99"));
    verify(mockTopicsPolicies).setMaxConsumers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("remove-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies, times(1)).removeMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies, times(1)).getMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1 -m 999"));
    verify(mockTopicsPolicies, times(1)).setMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", 999);
    cmdTopics.run(split("get-message-ttl persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMessageTTL("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-message-ttl persistent://myprop/clust/ns1/ds1 -t 10"));
    verify(mockTopicsPolicies).setMessageTTL("persistent://myprop/clust/ns1/ds1", 10);
    cmdTopics.run(split("remove-message-ttl persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMessageTTL("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1 -c 5"));
    verify(mockTopicsPolicies).setMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1", 5);
    cmdTopics.run(split("remove-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies, times(1)).getMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies, times(1)).removeMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1 -m 99"));
    verify(mockTopicsPolicies, times(1)).setMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-delayed-delivery persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-delayed-delivery persistent://myprop/clust/ns1/ds1 -t 10s --enable"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).removeDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-deduplication persistent://myprop/clust/ns1/ds1 --disable"));
    verify(mockTopicsPolicies).setDeduplicationStatus("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1 -s 1024"));
    verify(mockTopicsPolicies).setMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1", 1024);
    cmdTopics.run(split("remove-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).getDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1 -i 100"));
    verify(mockTopicsPolicies).setDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1", 100);
    cmdTopics.run(split("remove-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    // Reset the cmd, and check global option
    cmdTopics = new CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("get-retention persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getRetention("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-retention persistent://myprop/clust/ns1/ds1 -t 10m -s 20M -g"));
    verify(mockGlobalTopicsPolicies).setRetention("persistent://myprop/clust/ns1/ds1", new RetentionPolicies(10, 20));
    cmdTopics.run(split("remove-retention persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeRetention("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-backlog-quota persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopicsPolicies).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(mockTopicsPolicies).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 CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("set-message-ttl persistent://myprop/clust/ns1/ds1 -t 10h"));
    verify(mockTopicsPolicies).setMessageTTL("persistent://myprop/clust/ns1/ds1", 10 * 60 * 60);
    cmdTopics.run(split("set-backlog-quota persistent://myprop/clust/ns1/ds1 -lt 1w -p consumer_backlog_eviction"));
    verify(mockTopicsPolicies).setBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.builder().limitSize(-1).limitTime(60 * 60 * 24 * 7).retentionPolicy(RetentionPolicy.consumer_backlog_eviction).build(), BacklogQuota.BacklogQuotaType.destination_storage);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("set-backlog-quota persistent://myprop/clust/ns1/ds1 -lt 1000 -p producer_request_hold -t message_age"));
    verify(mockTopicsPolicies).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 CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("remove-backlog-quota persistent://myprop/clust/ns1/ds1"));
    verify(mockTopicsPolicies).removeBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.BacklogQuotaType.destination_storage);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopicPolicies(() -> admin);
    cmdTopics.run(split("remove-backlog-quota persistent://myprop/clust/ns1/ds1 -t message_age"));
    verify(mockTopicsPolicies).removeBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.BacklogQuotaType.message_age);
    cmdTopics.run(split("get-max-producers persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMaxProducers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-producers persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMaxProducers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-producers persistent://myprop/clust/ns1/ds1 -p 99 -g"));
    verify(mockGlobalTopicsPolicies).setMaxProducers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("remove-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).removeMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).getMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1 -m 999 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).setMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", 999);
    cmdTopics.run(split("get-message-ttl persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMessageTTL("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-message-ttl persistent://myprop/clust/ns1/ds1 -t 10 -g"));
    verify(mockGlobalTopicsPolicies).setMessageTTL("persistent://myprop/clust/ns1/ds1", 10);
    cmdTopics.run(split("remove-message-ttl persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMessageTTL("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-persistence persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).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 -g"));
    verify(mockGlobalTopicsPolicies).setPersistence("persistent://myprop/clust/ns1/ds1", new PersistencePolicies(2, 1, 1, 100.0d));
    cmdTopics.run(split("remove-persistence persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removePersistence("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).getMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).removeMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1 -m 99 -g"));
    verify(mockGlobalTopicsPolicies, times(1)).setMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-inactive-topic-policies persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-inactive-topic-policies persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).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 -g"));
    verify(mockGlobalTopicsPolicies).setInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", new InactiveTopicPolicies(InactiveTopicDeleteMode.delete_when_no_subscriptions, 1, true));
    cmdTopics.run(split("get-dispatch-rate persistent://myprop/clust/ns1/ds1 -ap -g"));
    verify(mockGlobalTopicsPolicies).getDispatchRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("remove-dispatch-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2 -g"));
    verify(mockGlobalTopicsPolicies).setDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-publish-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getPublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-publish-rate persistent://myprop/clust/ns1/ds1 -m 10 -b 100 -g"));
    verify(mockGlobalTopicsPolicies).setPublishRate("persistent://myprop/clust/ns1/ds1", new PublishRate(10, 100));
    cmdTopics.run(split("remove-publish-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removePublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-subscribe-rate persistent://myprop/clust/ns1/ds1 -ap -g"));
    verify(mockGlobalTopicsPolicies).getSubscribeRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-subscribe-rate persistent://myprop/clust/ns1/ds1 -sr 10 -st 100 -g"));
    verify(mockGlobalTopicsPolicies).setSubscribeRate("persistent://myprop/clust/ns1/ds1", new SubscribeRate(10, 100));
    cmdTopics.run(split("remove-subscribe-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeSubscribeRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-delayed-delivery persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-delayed-delivery persistent://myprop/clust/ns1/ds1 -t 10s --enable -g"));
    verify(mockGlobalTopicsPolicies).setDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", DelayedDeliveryPolicies.builder().tickTime(10000).active(true).build());
    cmdTopics.run(split("remove-delayed-delivery persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-message-size persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-message-size persistent://myprop/clust/ns1/ds1 -m 1000 -g"));
    verify(mockGlobalTopicsPolicies).setMaxMessageSize("persistent://myprop/clust/ns1/ds1", 1000);
    cmdTopics.run(split("remove-max-message-size persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-deduplication persistent://myprop/clust/ns1/ds1 --disable -g"));
    verify(mockGlobalTopicsPolicies).setDeduplicationStatus("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-deduplication persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1 -i 100 -g"));
    verify(mockGlobalTopicsPolicies).setDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1", 100);
    cmdTopics.run(split("remove-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1 -c 5 -g"));
    verify(mockGlobalTopicsPolicies).setMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1", 5);
    cmdTopics.run(split("remove-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-subscription-types-enabled persistent://myprop/clust/ns1/ds1 -t Shared,Failover -g"));
    verify(mockGlobalTopicsPolicies).setSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1", Sets.newHashSet(SubscriptionType.Shared, SubscriptionType.Failover));
    cmdTopics.run(split("get-subscription-types-enabled persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-subscription-types-enabled persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-consumers persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMaxConsumers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-consumers persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMaxConsumers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers persistent://myprop/clust/ns1/ds1 -c 99 -g"));
    verify(mockGlobalTopicsPolicies).setMaxConsumers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-compaction-threshold persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getCompactionThreshold("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-compaction-threshold persistent://myprop/clust/ns1/ds1 -t 10k -g"));
    verify(mockGlobalTopicsPolicies).setCompactionThreshold("persistent://myprop/clust/ns1/ds1", 10 * 1024);
    cmdTopics.run(split("remove-compaction-threshold persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeCompactionThreshold("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2 -g"));
    verify(mockGlobalTopicsPolicies).setReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2 -g"));
    verify(mockGlobalTopicsPolicies).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 -g"));
    verify(mockGlobalTopicsPolicies).getSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1 -s 1024 -g"));
    verify(mockGlobalTopicsPolicies).setMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1", 1024);
    cmdTopics.run(split("remove-max-subscriptions-per-topic persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-offload-policies persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).getOffloadPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-offload-policies persistent://myprop/clust/ns1/ds1 -g"));
    verify(mockGlobalTopicsPolicies).removeOffloadPolicies("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 -g"));
    verify(mockGlobalTopicsPolicies).setOffloadPolicies("persistent://myprop/clust/ns1/ds1", OffloadPoliciesImpl.create("s3", "region", "bucket", "endpoint", null, null, null, null, 8, 9, 10L, null, OffloadedReadPriority.TIERED_STORAGE_FIRST));
}
Also used : RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) TopicPolicies(org.apache.pulsar.client.admin.TopicPolicies) PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) Lookup(org.apache.pulsar.client.admin.Lookup) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) Schemas(org.apache.pulsar.client.admin.Schemas) Test(org.testng.annotations.Test)

Aggregations

PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)18 Schemas (org.apache.pulsar.client.admin.Schemas)18 Test (org.testng.annotations.Test)12 Lookup (org.apache.pulsar.client.admin.Lookup)9 Topics (org.apache.pulsar.client.admin.Topics)9 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 SchemaInfo (org.apache.pulsar.common.schema.SchemaInfo)5 InactiveTopicPolicies (org.apache.pulsar.common.policies.data.InactiveTopicPolicies)4 PersistencePolicies (org.apache.pulsar.common.policies.data.PersistencePolicies)4 PublishRate (org.apache.pulsar.common.policies.data.PublishRate)4 SubscribeRate (org.apache.pulsar.common.policies.data.SubscribeRate)4 ByteBuf (io.netty.buffer.ByteBuf)3 Field (java.lang.reflect.Field)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3