Search in sources :

Example 51 with TenantInfoImpl

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

the class CompactorTest 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("compactor").setDaemon(true).build());
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 52 with TenantInfoImpl

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

the class CompactedTopicTest 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");
}
Also used : TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 53 with TenantInfoImpl

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

the class CompactionRetentionTest method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    conf.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
    conf.setManagedLedgerMaxEntriesPerLedger(2);
    conf.setTopicLevelPoliciesEnabled(true);
    conf.setSystemTopicEnabled(true);
    super.internalSetup();
    admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
    admin.tenants().createTenant("my-tenant", new TenantInfoImpl(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test")));
    admin.namespaces().createNamespace("my-tenant/my-ns", Collections.singleton("test"));
    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)

Example 54 with TenantInfoImpl

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

the class MessagePayloadProcessorTest method setup.

@BeforeClass
@Override
protected void setup() throws Exception {
    super.internalSetup();
    admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
    admin.tenants().createTenant("public", new TenantInfoImpl(Sets.newHashSet("appid"), Sets.newHashSet("test")));
    admin.namespaces().createNamespace("public/default", Sets.newHashSet("test"));
}
Also used : TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) BeforeClass(org.testng.annotations.BeforeClass)

Example 55 with TenantInfoImpl

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

the class TopicsConsumerImplTest method testConsumerDistributionInFailoverSubscriptionWhenUpdatePartitions.

@Test(timeOut = testTimeout)
public void testConsumerDistributionInFailoverSubscriptionWhenUpdatePartitions() throws Exception {
    final String topicName = "persistent://my-property/my-ns/testConsumerDistributionInFailoverSubscriptionWhenUpdatePartitions";
    final String subName = "failover-test";
    TenantInfoImpl tenantInfo = createDefaultTenantInfo();
    admin.tenants().createTenant("prop", tenantInfo);
    admin.topics().createPartitionedTopic(topicName, 2);
    assertEquals(admin.topics().getPartitionedTopicMetadata(topicName).partitions, 2);
    Consumer<String> consumer_1 = pulsarClient.newConsumer(Schema.STRING).topic(topicName).subscriptionType(SubscriptionType.Failover).subscriptionName(subName).subscribe();
    assertTrue(consumer_1 instanceof MultiTopicsConsumerImpl);
    assertEquals(((MultiTopicsConsumerImpl) consumer_1).allTopicPartitionsNumber.get(), 2);
    Producer<String> producer = pulsarClient.newProducer(Schema.STRING).topic(topicName).messageRouter(new MessageRouter() {

        @Override
        public int choosePartition(Message<?> msg, TopicMetadata metadata) {
            return Integer.parseInt(msg.getKey()) % metadata.numPartitions();
        }
    }).create();
    final int messages = 20;
    for (int i = 0; i < messages; i++) {
        producer.newMessage().key(String.valueOf(i)).value("message - " + i).send();
    }
    int received = 0;
    Message lastMessage = null;
    for (int i = 0; i < messages; i++) {
        lastMessage = consumer_1.receive();
        received++;
    }
    assertEquals(received, messages);
    consumer_1.acknowledgeCumulative(lastMessage);
    // 1.Update partition and check message consumption
    admin.topics().updatePartitionedTopic(topicName, 4);
    log.info("trigger partitionsAutoUpdateTimerTask");
    Timeout timeout = ((MultiTopicsConsumerImpl) consumer_1).getPartitionsAutoUpdateTimeout();
    timeout.task().run(timeout);
    Thread.sleep(200);
    assertEquals(((MultiTopicsConsumerImpl) consumer_1).allTopicPartitionsNumber.get(), 4);
    for (int i = 0; i < messages; i++) {
        producer.newMessage().key(String.valueOf(i)).value("message - " + i).send();
    }
    received = 0;
    lastMessage = null;
    for (int i = 0; i < messages; i++) {
        lastMessage = consumer_1.receive();
        received++;
    }
    assertEquals(received, messages);
    consumer_1.acknowledgeCumulative(lastMessage);
    // 2.Create a new consumer and check active consumer changed
    Consumer<String> consumer_2 = pulsarClient.newConsumer(Schema.STRING).topic(topicName).subscriptionType(SubscriptionType.Failover).subscriptionName(subName).subscribe();
    assertTrue(consumer_2 instanceof MultiTopicsConsumerImpl);
    assertEquals(((MultiTopicsConsumerImpl) consumer_1).allTopicPartitionsNumber.get(), 4);
    for (int i = 0; i < messages; i++) {
        producer.newMessage().key(String.valueOf(i)).value("message - " + i).send();
    }
    Map<String, AtomicInteger> activeConsumers = new HashMap<>();
    PartitionedTopicStats stats = admin.topics().getPartitionedStats(topicName, true);
    for (TopicStats value : stats.getPartitions().values()) {
        for (SubscriptionStats subscriptionStats : value.getSubscriptions().values()) {
            assertTrue(subscriptionStats.getActiveConsumerName().equals(consumer_1.getConsumerName()) || subscriptionStats.getActiveConsumerName().equals(consumer_2.getConsumerName()));
            activeConsumers.putIfAbsent(subscriptionStats.getActiveConsumerName(), new AtomicInteger(0));
            activeConsumers.get(subscriptionStats.getActiveConsumerName()).incrementAndGet();
        }
    }
    assertEquals(activeConsumers.get(consumer_1.getConsumerName()).get(), 2);
    assertEquals(activeConsumers.get(consumer_2.getConsumerName()).get(), 2);
    // 4.Check new consumer can receive half of total messages
    received = 0;
    lastMessage = null;
    for (int i = 0; i < messages / 2; i++) {
        lastMessage = consumer_1.receive();
        received++;
    }
    assertEquals(received, messages / 2);
    consumer_1.acknowledgeCumulative(lastMessage);
    received = 0;
    lastMessage = null;
    for (int i = 0; i < messages / 2; i++) {
        lastMessage = consumer_2.receive();
        received++;
    }
    assertEquals(received, messages / 2);
    consumer_2.acknowledgeCumulative(lastMessage);
}
Also used : SubscriptionStats(org.apache.pulsar.common.policies.data.SubscriptionStats) Message(org.apache.pulsar.client.api.Message) HashMap(java.util.HashMap) MessageRouter(org.apache.pulsar.client.api.MessageRouter) Timeout(io.netty.util.Timeout) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) TopicMetadata(org.apache.pulsar.client.api.TopicMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionedTopicStats(org.apache.pulsar.common.policies.data.PartitionedTopicStats) TopicStats(org.apache.pulsar.common.policies.data.TopicStats) PartitionedTopicStats(org.apache.pulsar.common.policies.data.PartitionedTopicStats) Test(org.testng.annotations.Test)

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