use of com.yahoo.pulsar.client.admin.BrokerStats in project pulsar by yahoo.
the class BrokerServiceTest method testBrokerStatsMetrics.
@Test
public void testBrokerStatsMetrics() throws Exception {
final String topicName = "persistent://prop/use/ns-abc/newTopic";
final String subName = "newSub";
BrokerStats brokerStatsClient = admin.brokerStats();
ConsumerConfiguration conf = new ConsumerConfiguration();
conf.setSubscriptionType(SubscriptionType.Exclusive);
Consumer consumer = pulsarClient.subscribe(topicName, subName, conf);
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
Producer producer = pulsarClient.createProducer(topicName);
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
for (int i = 0; i < 10; i++) {
String message = "my-message-" + i;
producer.send(message.getBytes());
}
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
Message msg = null;
for (int i = 0; i < 10; i++) {
msg = consumer.receive();
consumer.acknowledge(msg);
}
consumer.close();
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
JsonArray metrics = brokerStatsClient.getMetrics();
assertEquals(metrics.size(), 4, metrics.toString());
// these metrics seem to be arriving in different order at different times...
// is the order really relevant here?
boolean namespaceDimensionFound = false;
boolean topicLoadTimesDimensionFound = false;
for (int i = 0; i < metrics.size(); i++) {
try {
String data = metrics.get(i).getAsJsonObject().get("dimensions").toString();
if (!namespaceDimensionFound && data.contains("prop/use/ns-abc")) {
namespaceDimensionFound = true;
}
if (!topicLoadTimesDimensionFound && data.contains("prop/use/ns-abc")) {
topicLoadTimesDimensionFound = true;
}
} catch (Exception e) {
/* it's possible there's no dimensions */
}
}
assertTrue(namespaceDimensionFound && topicLoadTimesDimensionFound);
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
}
use of com.yahoo.pulsar.client.admin.BrokerStats in project pulsar by yahoo.
the class BrokerServiceTest method testBrokerServiceNamespaceStats.
@SuppressWarnings("unchecked")
@Test
public void testBrokerServiceNamespaceStats() throws Exception {
final int numBundles = 4;
final String ns1 = "prop/use/stats1";
final String ns2 = "prop/use/stats2";
List<String> nsList = Lists.newArrayList(ns1, ns2);
List<Producer> producerList = Lists.newArrayList();
BrokerStats brokerStatsClient = admin.brokerStats();
for (String ns : nsList) {
admin.namespaces().createNamespace(ns, numBundles);
String topic1 = String.format("persistent://%s/topic1", ns);
producerList.add(pulsarClient.createProducer(topic1));
String topic2 = String.format("persistent://%s/topic2", ns);
producerList.add(pulsarClient.createProducer(topic2));
}
rolloverPerIntervalStats();
JsonObject destinationStats = brokerStatsClient.getDestinations();
assertEquals(destinationStats.size(), 2, destinationStats.toString());
for (String ns : nsList) {
JsonObject nsObject = destinationStats.getAsJsonObject(ns);
List<String> topicList = admin.namespaces().getDestinations(ns);
for (String topic : topicList) {
NamespaceBundle bundle = (NamespaceBundle) pulsar.getNamespaceService().getBundle(DestinationName.get(topic));
JsonObject bundleObject = nsObject.getAsJsonObject(bundle.getBundleRange());
JsonObject topicObject = bundleObject.getAsJsonObject("persistent");
AtomicBoolean topicPresent = new AtomicBoolean();
topicObject.entrySet().iterator().forEachRemaining(persistentTopic -> {
if (persistentTopic.getKey().equals(topic)) {
topicPresent.set(true);
}
});
assertTrue(topicPresent.get());
}
}
for (Producer producer : producerList) {
producer.close();
}
for (String ns : nsList) {
List<String> destinations = admin.namespaces().getDestinations(ns);
for (String dest : destinations) {
admin.persistentTopics().delete(dest);
}
admin.namespaces().deleteNamespace(ns);
}
}
Aggregations