Search in sources :

Example 1 with ManagedLedgerMetrics

use of org.apache.pulsar.broker.stats.metrics.ManagedLedgerMetrics in project incubator-pulsar by apache.

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<byte[]> producer = pulsarClient.newProducer().topic("persistent://my-property/use/my-ns/my-topic1").create();
    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);
}
Also used : ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) Metrics(org.apache.pulsar.common.stats.Metrics) ManagedLedgerMetrics(org.apache.pulsar.broker.stats.metrics.ManagedLedgerMetrics) ManagedLedgerMBeanImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerMBeanImpl) ManagedLedgerMetrics(org.apache.pulsar.broker.stats.metrics.ManagedLedgerMetrics) Test(org.testng.annotations.Test)

Aggregations

ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)1 ManagedLedgerMBeanImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerMBeanImpl)1 ManagedLedgerMetrics (org.apache.pulsar.broker.stats.metrics.ManagedLedgerMetrics)1 Metrics (org.apache.pulsar.common.stats.Metrics)1 Test (org.testng.annotations.Test)1