Search in sources :

Example 1 with TransactionBufferStats

use of org.apache.pulsar.common.policies.data.TransactionBufferStats in project pulsar by apache.

the class TopicTransactionBuffer method getStats.

@Override
public TransactionBufferStats getStats() {
    TransactionBufferStats transactionBufferStats = new TransactionBufferStats();
    transactionBufferStats.lastSnapshotTimestamps = this.lastSnapshotTimestamps;
    transactionBufferStats.state = this.getState().name();
    transactionBufferStats.maxReadPosition = this.maxReadPosition.toString();
    return transactionBufferStats;
}
Also used : TransactionBufferStats(org.apache.pulsar.common.policies.data.TransactionBufferStats)

Example 2 with TransactionBufferStats

use of org.apache.pulsar.common.policies.data.TransactionBufferStats in project pulsar by yahoo.

the class TransactionsImpl method getTransactionBufferStatsAsync.

@Override
public CompletableFuture<TransactionBufferStats> getTransactionBufferStatsAsync(String topic) {
    WebTarget path = adminV3Transactions.path("transactionBufferStats");
    path = path.path(TopicName.get(topic).getRestPath(false));
    final CompletableFuture<TransactionBufferStats> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<TransactionBufferStats>() {

        @Override
        public void completed(TransactionBufferStats stats) {
            future.complete(stats);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TransactionBufferStats(org.apache.pulsar.common.policies.data.TransactionBufferStats) WebTarget(javax.ws.rs.client.WebTarget)

Example 3 with TransactionBufferStats

use of org.apache.pulsar.common.policies.data.TransactionBufferStats in project incubator-pulsar by apache.

the class TopicTransactionBuffer method getStats.

@Override
public TransactionBufferStats getStats() {
    TransactionBufferStats transactionBufferStats = new TransactionBufferStats();
    transactionBufferStats.lastSnapshotTimestamps = this.lastSnapshotTimestamps;
    transactionBufferStats.state = this.getState().name();
    transactionBufferStats.maxReadPosition = this.maxReadPosition.toString();
    return transactionBufferStats;
}
Also used : TransactionBufferStats(org.apache.pulsar.common.policies.data.TransactionBufferStats)

Example 4 with TransactionBufferStats

use of org.apache.pulsar.common.policies.data.TransactionBufferStats in project incubator-pulsar by apache.

the class AdminApiTransactionTest method testGetTransactionBufferStats.

@Test(timeOut = 20000)
public void testGetTransactionBufferStats() throws Exception {
    initTransaction(2);
    TransactionImpl transaction = (TransactionImpl) getTransaction();
    final String topic = "persistent://public/default/testGetTransactionBufferStats";
    final String subName1 = "test1";
    final String subName2 = "test2";
    try {
        admin.transactions().getTransactionBufferStatsAsync(topic).get();
        fail("Should failed here");
    } catch (ExecutionException ex) {
        assertTrue(ex.getCause() instanceof PulsarAdminException.NotFoundException);
        PulsarAdminException.NotFoundException cause = (PulsarAdminException.NotFoundException) ex.getCause();
        assertEquals(cause.getMessage(), "Topic not found");
    }
    try {
        pulsar.getBrokerService().getTopic(topic, false);
        admin.transactions().getTransactionBufferStatsAsync(topic).get();
        fail("Should failed here");
    } catch (ExecutionException ex) {
        assertTrue(ex.getCause() instanceof PulsarAdminException.NotFoundException);
        PulsarAdminException.NotFoundException cause = (PulsarAdminException.NotFoundException) ex.getCause();
        assertEquals(cause.getMessage(), "Topic not found");
    }
    admin.topics().createNonPartitionedTopic(topic);
    Producer<byte[]> producer = pulsarClient.newProducer(Schema.BYTES).sendTimeout(0, TimeUnit.SECONDS).topic(topic).create();
    Consumer<byte[]> consumer1 = pulsarClient.newConsumer(Schema.BYTES).topic(topic).subscriptionName(subName1).subscribe();
    Consumer<byte[]> consumer2 = pulsarClient.newConsumer(Schema.BYTES).topic(topic).subscriptionName(subName2).subscribe();
    long currentTime = System.currentTimeMillis();
    MessageId messageId = producer.newMessage(transaction).value("Hello pulsar!".getBytes()).send();
    transaction.commit().get();
    transaction = (TransactionImpl) getTransaction();
    consumer1.acknowledgeAsync(messageId, transaction).get();
    consumer2.acknowledgeAsync(messageId, transaction).get();
    TransactionBufferStats transactionBufferStats = admin.transactions().getTransactionBufferStatsAsync(topic).get();
    assertEquals(transactionBufferStats.state, "Ready");
    assertEquals(transactionBufferStats.maxReadPosition, PositionImpl.get(((MessageIdImpl) messageId).getLedgerId(), ((MessageIdImpl) messageId).getEntryId() + 1).toString());
    assertTrue(transactionBufferStats.lastSnapshotTimestamps > currentTime);
}
Also used : TransactionBufferStats(org.apache.pulsar.common.policies.data.TransactionBufferStats) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl) BatchMessageIdImpl(org.apache.pulsar.client.impl.BatchMessageIdImpl) TransactionImpl(org.apache.pulsar.client.impl.transaction.TransactionImpl) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ExecutionException(java.util.concurrent.ExecutionException) MessageId(org.apache.pulsar.client.api.MessageId) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 5 with TransactionBufferStats

use of org.apache.pulsar.common.policies.data.TransactionBufferStats in project incubator-pulsar by apache.

the class TransactionsImpl method getTransactionBufferStatsAsync.

@Override
public CompletableFuture<TransactionBufferStats> getTransactionBufferStatsAsync(String topic) {
    WebTarget path = adminV3Transactions.path("transactionBufferStats");
    path = path.path(TopicName.get(topic).getRestPath(false));
    final CompletableFuture<TransactionBufferStats> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<TransactionBufferStats>() {

        @Override
        public void completed(TransactionBufferStats stats) {
            future.complete(stats);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TransactionBufferStats(org.apache.pulsar.common.policies.data.TransactionBufferStats) WebTarget(javax.ws.rs.client.WebTarget)

Aggregations

TransactionBufferStats (org.apache.pulsar.common.policies.data.TransactionBufferStats)9 CompletableFuture (java.util.concurrent.CompletableFuture)3 WebTarget (javax.ws.rs.client.WebTarget)3 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)3 MessageId (org.apache.pulsar.client.api.MessageId)3 BatchMessageIdImpl (org.apache.pulsar.client.impl.BatchMessageIdImpl)3 MessageIdImpl (org.apache.pulsar.client.impl.MessageIdImpl)3 TransactionImpl (org.apache.pulsar.client.impl.transaction.TransactionImpl)3 Test (org.testng.annotations.Test)3 ExecutionException (java.util.concurrent.ExecutionException)2 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)2