Search in sources :

Example 1 with PersistentTopics

use of com.yahoo.pulsar.client.admin.PersistentTopics in project pulsar by yahoo.

the class PulsarAdminToolTest method persistentTopics.

@Test
void persistentTopics() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    PersistentTopics mockTopics = mock(PersistentTopics.class);
    when(admin.persistentTopics()).thenReturn(mockTopics);
    CmdPersistentTopics topics = new CmdPersistentTopics(admin);
    topics.run(split("delete persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).delete("persistent://myprop/clust/ns1/ds1");
    topics.run(split("list myprop/clust/ns1"));
    verify(mockTopics).getList("myprop/clust/ns1");
    topics.run(split("subscriptions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getSubscriptions("persistent://myprop/clust/ns1/ds1");
    topics.run(split("unsubscribe persistent://myprop/clust/ns1/ds1 -s sub1"));
    verify(mockTopics).deleteSubscription("persistent://myprop/clust/ns1/ds1", "sub1");
    topics.run(split("stats persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getStats("persistent://myprop/clust/ns1/ds1");
    topics.run(split("stats-internal persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getInternalStats("persistent://myprop/clust/ns1/ds1");
    topics.run(split("partitioned-stats persistent://myprop/clust/ns1/ds1 --per-partition"));
    verify(mockTopics).getPartitionedStats("persistent://myprop/clust/ns1/ds1", true);
    topics.run(split("skip-all persistent://myprop/clust/ns1/ds1 -s sub1"));
    verify(mockTopics).skipAllMessages("persistent://myprop/clust/ns1/ds1", "sub1");
    topics.run(split("skip persistent://myprop/clust/ns1/ds1 -s sub1 -n 100"));
    verify(mockTopics).skipMessages("persistent://myprop/clust/ns1/ds1", "sub1", 100);
    topics.run(split("expire-messages persistent://myprop/clust/ns1/ds1 -s sub1 -t 100"));
    verify(mockTopics).expireMessages("persistent://myprop/clust/ns1/ds1", "sub1", 100);
    topics.run(split("expire-messages-all-subscriptions persistent://myprop/clust/ns1/ds1 -t 100"));
    verify(mockTopics).expireMessagesForAllSubscriptions("persistent://myprop/clust/ns1/ds1", 100);
    topics.run(split("create-partitioned-topic persistent://myprop/clust/ns1/ds1 --partitions 32"));
    verify(mockTopics).createPartitionedTopic("persistent://myprop/clust/ns1/ds1", 32);
    topics.run(split("get-partitioned-topic-metadata persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPartitionedTopicMetadata("persistent://myprop/clust/ns1/ds1");
    topics.run(split("delete-partitioned-topic persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).deletePartitionedTopic("persistent://myprop/clust/ns1/ds1");
    topics.run(split("peek-messages persistent://myprop/clust/ns1/ds1 -s sub1 -n 3"));
    verify(mockTopics).peekMessages("persistent://myprop/clust/ns1/ds1", "sub1", 3);
    // range of +/- 1 second of the expected timestamp
    class TimestampMatcher extends ArgumentMatcher<Long> {

        @Override
        public boolean matches(Object argument) {
            long timestamp = (Long) argument;
            long expectedTimestamp = System.currentTimeMillis() - (1 * 60 * 1000);
            if (timestamp < (expectedTimestamp + 1000) && timestamp > (expectedTimestamp - 1000)) {
                return true;
            }
            return false;
        }
    }
    topics.run(split("reset-cursor persistent://myprop/clust/ns1/ds1 -s sub1 -t 1m"));
    verify(mockTopics).resetCursor(Matchers.eq("persistent://myprop/clust/ns1/ds1"), Matchers.eq("sub1"), Matchers.longThat(new TimestampMatcher()));
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) ArgumentMatcher(org.mockito.ArgumentMatcher) PersistentTopics(com.yahoo.pulsar.client.admin.PersistentTopics) Test(org.testng.annotations.Test)

Aggregations

PersistentTopics (com.yahoo.pulsar.client.admin.PersistentTopics)1 PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1 Test (org.testng.annotations.Test)1