use of com.yahoo.pulsar.broker.stats.metrics.ManagedLedgerMetrics in project pulsar by yahoo.
the class ManagedLedgerMetricsTest method testManagedLedgerMetrics.
@Test
public void testManagedLedgerMetrics() throws Exception {
ManagedLedgerMetrics metrics = new ManagedLedgerMetrics(pulsar);
final String addEntryRateKey = "brk_ml_AddEntryMessagesRate";
List<Metrics> list1 = metrics.generate();
Assert.assertTrue(list1.isEmpty());
Producer producer = pulsarClient.createProducer("persistent://my-property/use/my-ns/my-topic1");
for (int i = 0; i < 10; i++) {
String message = "my-message-" + i;
producer.send(message.getBytes());
}
for (Entry<String, ManagedLedgerImpl> ledger : ((ManagedLedgerFactoryImpl) pulsar.getManagedLedgerFactory()).getManagedLedgers().entrySet()) {
ManagedLedgerMBeanImpl stats = (ManagedLedgerMBeanImpl) ledger.getValue().getStats();
stats.refreshStats(1, TimeUnit.SECONDS);
}
List<Metrics> list2 = metrics.generate();
Assert.assertEquals(list2.get(0).getMetrics().get(addEntryRateKey), 10.0D);
for (int i = 0; i < 5; i++) {
String message = "my-message-" + i;
producer.send(message.getBytes());
}
for (Entry<String, ManagedLedgerImpl> ledger : ((ManagedLedgerFactoryImpl) pulsar.getManagedLedgerFactory()).getManagedLedgers().entrySet()) {
ManagedLedgerMBeanImpl stats = (ManagedLedgerMBeanImpl) ledger.getValue().getStats();
stats.refreshStats(1, TimeUnit.SECONDS);
}
List<Metrics> list3 = metrics.generate();
Assert.assertEquals(list3.get(0).getMetrics().get(addEntryRateKey), 5.0D);
}
Aggregations