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());
}
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");
}
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);
}
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"));
}
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);
}
Aggregations