use of org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl in project pulsar by apache.
the class NonPersistentTopic method unsubscribe.
@Override
public CompletableFuture<Void> unsubscribe(String subscriptionName) {
// That creates deadlock. so, execute remove it in different thread.
return CompletableFuture.runAsync(() -> {
NonPersistentSubscription sub = subscriptions.remove(subscriptionName);
// preserve accumulative stats form removed subscription
SubscriptionStatsImpl stats = sub.getStats();
bytesOutFromRemovedSubscriptions.add(stats.bytesOutCounter);
msgOutFromRemovedSubscriptions.add(stats.msgOutCounter);
}, brokerService.executor());
}
use of org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl in project pulsar by apache.
the class PersistentTopicTest method testKeySharedMetadataExposedToStats.
@Test
public void testKeySharedMetadataExposedToStats() throws Exception {
PersistentTopic topic = new PersistentTopic(successTopicName, ledgerMock, brokerService);
PersistentSubscription sub1 = new PersistentSubscription(topic, "key-shared-stats1", cursorMock, false);
PersistentSubscription sub2 = new PersistentSubscription(topic, "key-shared-stats2", cursorMock, false);
PersistentSubscription sub3 = new PersistentSubscription(topic, "key-shared-stats3", cursorMock, false);
Consumer consumer1 = new Consumer(sub1, SubType.Key_Shared, topic.getName(), 1, 0, "Cons1", true, serverCnx, "myrole-1", Collections.emptyMap(), false, InitialPosition.Latest, new KeySharedMeta().setKeySharedMode(KeySharedMode.AUTO_SPLIT).setAllowOutOfOrderDelivery(false), MessageId.latest, DEFAULT_CONSUMER_EPOCH);
sub1.addConsumer(consumer1);
consumer1.close();
SubscriptionStatsImpl stats1 = sub1.getStats(false, false, false);
assertEquals(stats1.keySharedMode, "AUTO_SPLIT");
assertFalse(stats1.allowOutOfOrderDelivery);
Consumer consumer2 = new Consumer(sub2, SubType.Key_Shared, topic.getName(), 2, 0, "Cons2", true, serverCnx, "myrole-1", Collections.emptyMap(), false, InitialPosition.Latest, new KeySharedMeta().setKeySharedMode(KeySharedMode.AUTO_SPLIT).setAllowOutOfOrderDelivery(true), MessageId.latest, DEFAULT_CONSUMER_EPOCH);
sub2.addConsumer(consumer2);
consumer2.close();
SubscriptionStatsImpl stats2 = sub2.getStats(false, false, false);
assertEquals(stats2.keySharedMode, "AUTO_SPLIT");
assertTrue(stats2.allowOutOfOrderDelivery);
KeySharedMeta ksm = new KeySharedMeta().setKeySharedMode(KeySharedMode.STICKY).setAllowOutOfOrderDelivery(false);
ksm.addHashRange().setStart(0).setEnd(65535);
Consumer consumer3 = new Consumer(sub3, SubType.Key_Shared, topic.getName(), 3, 0, "Cons3", true, serverCnx, "myrole-1", Collections.emptyMap(), false, InitialPosition.Latest, ksm, MessageId.latest, DEFAULT_CONSUMER_EPOCH);
sub3.addConsumer(consumer3);
consumer3.close();
SubscriptionStatsImpl stats3 = sub3.getStats(false, false, false);
assertEquals(stats3.keySharedMode, "STICKY");
assertFalse(stats3.allowOutOfOrderDelivery);
}
use of org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl in project pulsar by apache.
the class PersistentTopicStatsTest method testPersistentTopicStatsAggregationPartialProducerIsNotSupported.
@Test
public void testPersistentTopicStatsAggregationPartialProducerIsNotSupported() {
TopicStatsImpl topicStats1 = new TopicStatsImpl();
topicStats1.msgRateIn = 1;
topicStats1.msgThroughputIn = 1;
topicStats1.msgRateOut = 1;
topicStats1.msgThroughputOut = 1;
topicStats1.averageMsgSize = 1;
topicStats1.storageSize = 1;
final PublisherStatsImpl publisherStats1 = new PublisherStatsImpl();
publisherStats1.setSupportsPartialProducer(false);
publisherStats1.setProducerName("name1");
topicStats1.addPublisher(publisherStats1);
topicStats1.subscriptions.put("test_ns", new SubscriptionStatsImpl());
topicStats1.replication.put("test_ns", new ReplicatorStatsImpl());
TopicStatsImpl topicStats2 = new TopicStatsImpl();
topicStats2.msgRateIn = 1;
topicStats2.msgThroughputIn = 2;
topicStats2.msgRateOut = 3;
topicStats2.msgThroughputOut = 4;
topicStats2.averageMsgSize = 5;
topicStats2.storageSize = 6;
final PublisherStatsImpl publisherStats2 = new PublisherStatsImpl();
publisherStats2.setSupportsPartialProducer(false);
publisherStats2.setProducerName("name1");
topicStats2.addPublisher(publisherStats2);
topicStats2.subscriptions.put("test_ns", new SubscriptionStatsImpl());
topicStats2.replication.put("test_ns", new ReplicatorStatsImpl());
TopicStatsImpl target = new TopicStatsImpl();
target.add(topicStats1);
target.add(topicStats2);
assertEquals(target.msgRateIn, 2.0);
assertEquals(target.msgThroughputIn, 3.0);
assertEquals(target.msgRateOut, 4.0);
assertEquals(target.msgThroughputOut, 5.0);
assertEquals(target.averageMsgSize, 3.0);
assertEquals(target.storageSize, 7);
assertEquals(target.getPublishers().size(), 1);
assertEquals(target.subscriptions.size(), 1);
assertEquals(target.replication.size(), 1);
}
use of org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl in project pulsar by apache.
the class PersistentTopicStatsTest method testPersistentTopicStatsAggregationByProducerName.
@Test
public void testPersistentTopicStatsAggregationByProducerName() {
TopicStatsImpl topicStats1 = new TopicStatsImpl();
topicStats1.msgRateIn = 1;
topicStats1.msgThroughputIn = 1;
topicStats1.msgRateOut = 1;
topicStats1.msgThroughputOut = 1;
topicStats1.averageMsgSize = 1;
topicStats1.storageSize = 1;
final PublisherStatsImpl publisherStats1 = new PublisherStatsImpl();
publisherStats1.setSupportsPartialProducer(true);
publisherStats1.msgRateIn = 1;
publisherStats1.setProducerName("name1");
topicStats1.addPublisher(publisherStats1);
topicStats1.subscriptions.put("test_ns", new SubscriptionStatsImpl());
topicStats1.replication.put("test_ns", new ReplicatorStatsImpl());
TopicStatsImpl topicStats2 = new TopicStatsImpl();
topicStats2.msgRateIn = 1;
topicStats2.msgThroughputIn = 2;
topicStats2.msgRateOut = 3;
topicStats2.msgThroughputOut = 4;
topicStats2.averageMsgSize = 5;
topicStats2.storageSize = 6;
final PublisherStatsImpl publisherStats2 = new PublisherStatsImpl();
publisherStats2.setSupportsPartialProducer(true);
publisherStats2.msgRateIn = 1;
publisherStats2.setProducerName("name1");
topicStats2.addPublisher(publisherStats2);
topicStats2.subscriptions.put("test_ns", new SubscriptionStatsImpl());
topicStats2.replication.put("test_ns", new ReplicatorStatsImpl());
TopicStatsImpl topicStats3 = new TopicStatsImpl();
topicStats3.msgRateIn = 0;
topicStats3.msgThroughputIn = 0;
topicStats3.msgRateOut = 0;
topicStats3.msgThroughputOut = 0;
topicStats3.averageMsgSize = 0;
topicStats3.storageSize = 0;
final PublisherStatsImpl publisherStats3 = new PublisherStatsImpl();
publisherStats3.setSupportsPartialProducer(true);
publisherStats3.msgRateIn = 1;
publisherStats3.setProducerName("name2");
topicStats3.addPublisher(publisherStats3);
topicStats3.subscriptions.put("test_ns", new SubscriptionStatsImpl());
topicStats3.replication.put("test_ns", new ReplicatorStatsImpl());
TopicStatsImpl target = new TopicStatsImpl();
target.add(topicStats1);
target.add(topicStats2);
target.add(topicStats3);
assertEquals(target.msgRateIn, 2.0);
assertEquals(target.msgThroughputIn, 3.0);
assertEquals(target.msgRateOut, 4.0);
assertEquals(target.msgThroughputOut, 5.0);
assertEquals(target.averageMsgSize, 2.0);
assertEquals(target.storageSize, 7);
assertEquals(target.getPublishers().size(), 2);
final Map<String, Double> expectedPublishersMap = Maps.newHashMap();
expectedPublishersMap.put("name1", 2.0);
expectedPublishersMap.put("name2", 1.0);
assertEquals(target.getPublishers().stream().collect(Collectors.toMap(PublisherStats::getProducerName, e -> ((PublisherStatsImpl) e).msgRateIn)), expectedPublishersMap);
assertEquals(target.subscriptions.size(), 1);
assertEquals(target.replication.size(), 1);
}
use of org.apache.pulsar.common.policies.data.stats.SubscriptionStatsImpl in project pulsar by apache.
the class PersistentTopicStatsTest method testPersistentTopicStatsAggregationPartialProducerSupported.
@Test
public void testPersistentTopicStatsAggregationPartialProducerSupported() {
TopicStatsImpl topicStats1 = new TopicStatsImpl();
topicStats1.msgRateIn = 1;
topicStats1.msgThroughputIn = 1;
topicStats1.msgRateOut = 1;
topicStats1.msgThroughputOut = 1;
topicStats1.averageMsgSize = 1;
topicStats1.storageSize = 1;
final PublisherStatsImpl publisherStats1 = new PublisherStatsImpl();
publisherStats1.setSupportsPartialProducer(true);
publisherStats1.setProducerName("name1");
topicStats1.addPublisher(publisherStats1);
topicStats1.subscriptions.put("test_ns", new SubscriptionStatsImpl());
topicStats1.replication.put("test_ns", new ReplicatorStatsImpl());
TopicStatsImpl topicStats2 = new TopicStatsImpl();
topicStats2.msgRateIn = 1;
topicStats2.msgThroughputIn = 2;
topicStats2.msgRateOut = 3;
topicStats2.msgThroughputOut = 4;
topicStats2.averageMsgSize = 5;
topicStats2.storageSize = 6;
final PublisherStatsImpl publisherStats2 = new PublisherStatsImpl();
publisherStats2.setSupportsPartialProducer(true);
publisherStats2.setProducerName("name1");
topicStats2.addPublisher(publisherStats2);
topicStats2.subscriptions.put("test_ns", new SubscriptionStatsImpl());
topicStats2.replication.put("test_ns", new ReplicatorStatsImpl());
TopicStatsImpl target = new TopicStatsImpl();
target.add(topicStats1);
target.add(topicStats2);
assertEquals(target.msgRateIn, 2.0);
assertEquals(target.msgThroughputIn, 3.0);
assertEquals(target.msgRateOut, 4.0);
assertEquals(target.msgThroughputOut, 5.0);
assertEquals(target.averageMsgSize, 3.0);
assertEquals(target.storageSize, 7);
assertEquals(target.getPublishers().size(), 1);
assertEquals(target.getPublishers().get(0).getProducerName(), "name1");
assertEquals(target.subscriptions.size(), 1);
assertEquals(target.replication.size(), 1);
}
Aggregations