Search in sources :

Example 1 with TransactionPendingAckStats

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

the class PendingAckHandleImpl method getStats.

@Override
public TransactionPendingAckStats getStats() {
    TransactionPendingAckStats transactionPendingAckStats = new TransactionPendingAckStats();
    transactionPendingAckStats.state = this.getState().name();
    return transactionPendingAckStats;
}
Also used : TransactionPendingAckStats(org.apache.pulsar.common.policies.data.TransactionPendingAckStats)

Example 2 with TransactionPendingAckStats

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

the class TransactionsImpl method getPendingAckStatsAsync.

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

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

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

Example 3 with TransactionPendingAckStats

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

the class AdminApiTransactionTest method testGetPendingAckStats.

@Test(timeOut = 20000, dataProvider = "ackType")
public void testGetPendingAckStats(String ackType) throws Exception {
    initTransaction(2);
    final String topic = "persistent://public/default/testGetPendingAckStats";
    final String subName = "test1";
    admin.topics().createNonPartitionedTopic(topic);
    Producer<byte[]> producer = pulsarClient.newProducer(Schema.BYTES).sendTimeout(0, TimeUnit.SECONDS).topic(topic).create();
    Consumer<byte[]> consumer = pulsarClient.newConsumer(Schema.BYTES).topic(topic).subscriptionName(subName).subscribe();
    TransactionPendingAckStats transactionPendingAckStats = admin.transactions().getPendingAckStatsAsync(topic, subName).get();
    assertEquals(transactionPendingAckStats.state, "None");
    producer.newMessage().value("Hello pulsar!".getBytes()).send();
    TransactionImpl transaction = (TransactionImpl) getTransaction();
    if (ackType.equals("individual")) {
        consumer.acknowledgeAsync(consumer.receive().getMessageId(), transaction);
    } else {
        consumer.acknowledgeCumulativeAsync(consumer.receive().getMessageId(), transaction);
    }
    transaction.commit().get();
    transactionPendingAckStats = admin.transactions().getPendingAckStatsAsync(topic, subName).get();
    assertEquals(transactionPendingAckStats.state, "Ready");
}
Also used : TransactionImpl(org.apache.pulsar.client.impl.transaction.TransactionImpl) TransactionPendingAckStats(org.apache.pulsar.common.policies.data.TransactionPendingAckStats) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

TransactionPendingAckStats (org.apache.pulsar.common.policies.data.TransactionPendingAckStats)3 CompletableFuture (java.util.concurrent.CompletableFuture)1 WebTarget (javax.ws.rs.client.WebTarget)1 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)1 TransactionImpl (org.apache.pulsar.client.impl.transaction.TransactionImpl)1 Test (org.testng.annotations.Test)1