Search in sources :

Example 1 with ManagedLedgerMetrics

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);
}
Also used : ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) ManagedLedgerMetrics(com.yahoo.pulsar.broker.stats.metrics.ManagedLedgerMetrics) Producer(com.yahoo.pulsar.client.api.Producer) ManagedLedgerMBeanImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerMBeanImpl) ManagedLedgerMetrics(com.yahoo.pulsar.broker.stats.metrics.ManagedLedgerMetrics) Test(org.testng.annotations.Test)

Aggregations

ManagedLedgerMetrics (com.yahoo.pulsar.broker.stats.metrics.ManagedLedgerMetrics)1 Producer (com.yahoo.pulsar.client.api.Producer)1 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)1 ManagedLedgerMBeanImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerMBeanImpl)1 Test (org.testng.annotations.Test)1