Search in sources :

Example 46 with TenantInfoImpl

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

the class TopicsConsumerImplTest method testGetConsumersAndGetTopics.

@Test(timeOut = testTimeout)
public void testGetConsumersAndGetTopics() throws Exception {
    String key = "TopicsConsumerGet";
    final String subscriptionName = "my-ex-subscription-" + key;
    final String topicName1 = "persistent://prop/use/ns-abc/topic-1-" + key;
    final String topicName2 = "persistent://prop/use/ns-abc/topic-2-" + key;
    final String topicName3 = "persistent://prop/use/ns-abc/topic-3-" + key;
    List<String> topicNames = Lists.newArrayList(topicName1, topicName2);
    TenantInfoImpl tenantInfo = createDefaultTenantInfo();
    admin.tenants().createTenant("prop", tenantInfo);
    admin.topics().createPartitionedTopic(topicName2, 2);
    admin.topics().createPartitionedTopic(topicName3, 3);
    // 2. Create consumer
    Consumer<byte[]> consumer = pulsarClient.newConsumer().topics(topicNames).topic(topicName3).subscriptionName(subscriptionName).subscriptionType(SubscriptionType.Shared).ackTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS).receiverQueueSize(4).subscribe();
    assertTrue(consumer instanceof MultiTopicsConsumerImpl);
    assertTrue(consumer.getTopic().startsWith(MultiTopicsConsumerImpl.DUMMY_TOPIC_NAME_PREFIX));
    List<String> topics = ((MultiTopicsConsumerImpl<byte[]>) consumer).getPartitions();
    List<ConsumerImpl<byte[]>> consumers = ((MultiTopicsConsumerImpl) consumer).getConsumers();
    topics.forEach(topic -> log.info("topic: {}", topic));
    consumers.forEach(c -> log.info("consumer: {}", c.getTopic()));
    IntStream.range(0, 6).forEach(index -> assertEquals(consumers.get(index).getTopic(), topics.get(index)));
    assertEquals(((MultiTopicsConsumerImpl<byte[]>) consumer).getPartitionedTopics().size(), 2);
    consumer.unsubscribe();
    consumer.close();
}
Also used : TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) Test(org.testng.annotations.Test)

Example 47 with TenantInfoImpl

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

the class TopicsConsumerImplTest method multiTopicsInDifferentNameSpace.

@Test(timeOut = testTimeout)
public void multiTopicsInDifferentNameSpace() throws PulsarAdminException, PulsarClientException {
    List<String> topics = new ArrayList<>();
    topics.add("persistent://prop/use/ns-abc/topic-1");
    topics.add("persistent://prop/use/ns-abc/topic-2");
    topics.add("persistent://prop/use/ns-abc1/topic-3");
    admin.clusters().createCluster("use", ClusterData.builder().serviceUrl(brokerUrl.toString()).build());
    admin.tenants().createTenant("prop", new TenantInfoImpl(null, Sets.newHashSet("use")));
    admin.namespaces().createNamespace("prop/use/ns-abc");
    admin.namespaces().createNamespace("prop/use/ns-abc1");
    Consumer consumer = pulsarClient.newConsumer().topics(topics).subscriptionName("multiTopicSubscription").subscriptionType(SubscriptionType.Exclusive).subscribe();
    // create Producer
    Producer<String> producer = pulsarClient.newProducer(Schema.STRING).topic("persistent://prop/use/ns-abc/topic-1").producerName("producer").create();
    Producer<String> producer1 = pulsarClient.newProducer(Schema.STRING).topic("persistent://prop/use/ns-abc/topic-2").producerName("producer1").create();
    Producer<String> producer2 = pulsarClient.newProducer(Schema.STRING).topic("persistent://prop/use/ns-abc1/topic-3").producerName("producer2").create();
    // send message
    producer.send("ns-abc/topic-1-Message1");
    producer1.send("ns-abc/topic-2-Message1");
    producer2.send("ns-abc1/topic-3-Message1");
    int messageSet = 0;
    Message<byte[]> message = consumer.receive();
    do {
        messageSet++;
        consumer.acknowledge(message);
        log.info("Consumer acknowledged : " + new String(message.getData()));
        message = consumer.receive(200, TimeUnit.MILLISECONDS);
    } while (message != null);
    assertEquals(messageSet, 3);
    consumer.unsubscribe();
    consumer.close();
    producer.close();
    producer1.close();
    producer2.close();
}
Also used : Consumer(org.apache.pulsar.client.api.Consumer) ArrayList(java.util.ArrayList) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) Test(org.testng.annotations.Test)

Example 48 with TenantInfoImpl

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

the class TopicsConsumerImplTest method testDefaultBacklogTTL.

@Test(timeOut = testTimeout)
public void testDefaultBacklogTTL() throws Exception {
    int defaultTTLSec = 5;
    int totalMessages = 10;
    this.conf.setTtlDurationDefaultInSeconds(defaultTTLSec);
    final String namespace = "prop/use/expiry";
    final String topicName = "persistent://" + namespace + "/expiry";
    final String subName = "expiredSub";
    admin.clusters().createCluster("use", ClusterData.builder().serviceUrl(brokerUrl.toString()).build());
    admin.tenants().createTenant("prop", new TenantInfoImpl(null, Sets.newHashSet("use")));
    admin.namespaces().createNamespace(namespace);
    Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).subscriptionType(SubscriptionType.Shared).ackTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS).subscribe();
    consumer.close();
    Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName).enableBatching(false).create();
    for (int i = 0; i < totalMessages; i++) {
        producer.send(("" + i).getBytes());
    }
    Optional<Topic> topic = pulsar.getBrokerService().getTopic(topicName, false).get();
    assertTrue(topic.isPresent());
    PersistentSubscription subscription = (PersistentSubscription) topic.get().getSubscription(subName);
    Thread.sleep((defaultTTLSec - 1) * 1000);
    topic.get().checkMessageExpiry();
    // Wait the message expire task done and make sure the message does not expire early.
    Thread.sleep(1000);
    assertEquals(subscription.getNumberOfEntriesInBacklog(false), 10);
    Thread.sleep(2000);
    topic.get().checkMessageExpiry();
    // Wait the message expire task done and make sure the message expired.
    retryStrategically((test) -> subscription.getNumberOfEntriesInBacklog(false) == 0, 5, 200);
    assertEquals(subscription.getNumberOfEntriesInBacklog(false), 0);
}
Also used : Topic(org.apache.pulsar.broker.service.Topic) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) Test(org.testng.annotations.Test)

Example 49 with TenantInfoImpl

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

the class TableViewTest method setup.

@BeforeClass
@Override
protected void setup() throws Exception {
    conf.setAllowAutoTopicCreation(true);
    super.internalSetup(conf);
    admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
    // so that clients can test short names
    admin.tenants().createTenant("public", new TenantInfoImpl(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test")));
    admin.namespaces().createNamespace("public/default");
    admin.namespaces().setNamespaceReplicationClusters("public/default", Sets.newHashSet("test"));
}
Also used : TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) BeforeClass(org.testng.annotations.BeforeClass)

Example 50 with TenantInfoImpl

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

the class CompactionTest method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    super.internalSetup();
    admin.clusters().createCluster("use", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
    admin.tenants().createTenant("my-property", new TenantInfoImpl(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("use")));
    admin.namespaces().createNamespace("my-property/use/my-ns");
    compactionScheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("compaction-%d").setDaemon(true).build());
    bk = pulsar.getBookKeeperClientFactory().create(this.conf, null, null, Optional.empty(), null);
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

TenantInfoImpl (org.apache.pulsar.common.policies.data.TenantInfoImpl)690 Test (org.testng.annotations.Test)458 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)211 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)146 BeforeMethod (org.testng.annotations.BeforeMethod)144 Cleanup (lombok.Cleanup)139 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)136 PulsarClient (org.apache.pulsar.client.api.PulsarClient)91 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)72 HashSet (java.util.HashSet)55 HashMap (java.util.HashMap)49 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)48 CompletableFuture (java.util.concurrent.CompletableFuture)41 List (java.util.List)38 PulsarService (org.apache.pulsar.broker.PulsarService)37 AuthAction (org.apache.pulsar.common.policies.data.AuthAction)36 ArrayList (java.util.ArrayList)33 WebTarget (javax.ws.rs.client.WebTarget)33 Policies (org.apache.pulsar.common.policies.data.Policies)33 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)31