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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations