use of org.apache.pulsar.transaction.coordinator.TxnMeta in project pulsar by yahoo.
the class TransactionMetadataStoreServiceTest method testTimeoutTracker.
@Test
public void testTimeoutTracker() throws Exception {
pulsar.getTransactionMetadataStoreService().handleTcClientConnect(TransactionCoordinatorID.get(0));
Awaitility.await().until(() -> pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0)) != null);
MLTransactionMetadataStore transactionMetadataStore = (MLTransactionMetadataStore) pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0));
checkTransactionMetadataStoreReady(transactionMetadataStore);
Field field = MLTransactionMetadataStore.class.getDeclaredField("txnMetaMap");
field.setAccessible(true);
ConcurrentSkipListMap<Long, Pair<TxnMeta, List<Position>>> txnMap = (ConcurrentSkipListMap<Long, Pair<TxnMeta, List<Position>>>) field.get(transactionMetadataStore);
int i = -1;
while (++i < 1000) {
try {
transactionMetadataStore.newTransaction(2000).get();
} catch (Exception e) {
// no operation
}
}
txnMap.forEach((txnID, txnMetaListPair) -> Assert.assertEquals(txnMetaListPair.getLeft().status(), TxnStatus.OPEN));
Awaitility.await().atLeast(1000, TimeUnit.MICROSECONDS).until(() -> txnMap.size() == 0);
}
use of org.apache.pulsar.transaction.coordinator.TxnMeta in project pulsar by yahoo.
the class TransactionMetadataStoreServiceTest method transactionTimeoutRecoverTest.
@Test
public void transactionTimeoutRecoverTest() throws Exception {
int timeout = 2000;
pulsar.getTransactionMetadataStoreService().handleTcClientConnect(TransactionCoordinatorID.get(0));
Awaitility.await().until(() -> pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0)) != null);
MLTransactionMetadataStore transactionMetadataStore = (MLTransactionMetadataStore) pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0));
checkTransactionMetadataStoreReady(transactionMetadataStore);
transactionMetadataStore.newTransaction(timeout);
pulsar.getTransactionMetadataStoreService().removeTransactionMetadataStore(TransactionCoordinatorID.get(0));
pulsar.getTransactionMetadataStoreService().handleTcClientConnect(TransactionCoordinatorID.get(0));
Awaitility.await().until(() -> pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0)) != null);
transactionMetadataStore = (MLTransactionMetadataStore) pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0));
checkTransactionMetadataStoreReady(transactionMetadataStore);
Field field = MLTransactionMetadataStore.class.getDeclaredField("txnMetaMap");
field.setAccessible(true);
ConcurrentSkipListMap<Long, Pair<TxnMeta, List<Position>>> txnMap = (ConcurrentSkipListMap<Long, Pair<TxnMeta, List<Position>>>) field.get(transactionMetadataStore);
Awaitility.await().until(() -> txnMap.size() == 0);
}
use of org.apache.pulsar.transaction.coordinator.TxnMeta in project pulsar by yahoo.
the class TransactionMetadataStoreServiceTest method testEndTransactionOpRetry.
@Test(dataProvider = "txnStatus")
public void testEndTransactionOpRetry(TxnStatus txnStatus) throws Exception {
int timeOut = 3000;
pulsar.getTransactionMetadataStoreService().handleTcClientConnect(TransactionCoordinatorID.get(0));
Awaitility.await().until(() -> pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0)) != null);
MLTransactionMetadataStore transactionMetadataStore = (MLTransactionMetadataStore) pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0));
checkTransactionMetadataStoreReady(transactionMetadataStore);
TxnID txnID = transactionMetadataStore.newTransaction(timeOut - 2000).get();
TxnMeta txnMeta = transactionMetadataStore.getTxnMeta(txnID).get();
txnMeta.updateTxnStatus(txnStatus, TxnStatus.OPEN);
Field field = TransactionMetadataStoreState.class.getDeclaredField("state");
field.setAccessible(true);
field.set(transactionMetadataStore, TransactionMetadataStoreState.State.None);
CompletableFuture<Void> completableFuture = null;
try {
completableFuture = pulsar.getTransactionMetadataStoreService().endTransaction(txnID, TxnAction.COMMIT.getValue(), false);
completableFuture.get(5, TimeUnit.SECONDS);
fail();
} catch (Exception e) {
if (txnStatus == TxnStatus.OPEN || txnStatus == TxnStatus.COMMITTING) {
assertTrue(e instanceof TimeoutException);
} else if (txnStatus == TxnStatus.ABORTING) {
assertTrue(e.getCause() instanceof CoordinatorException.InvalidTxnStatusException);
} else {
fail();
}
}
assertEquals(txnMeta.status(), txnStatus);
field = TransactionMetadataStoreState.class.getDeclaredField("state");
field.setAccessible(true);
field.set(transactionMetadataStore, TransactionMetadataStoreState.State.Ready);
if (txnStatus == TxnStatus.ABORTING) {
pulsar.getTransactionMetadataStoreService().endTransaction(txnID, TxnAction.ABORT.getValue(), false).get();
}
Awaitility.await().atMost(timeOut, TimeUnit.MILLISECONDS).until(() -> {
try {
transactionMetadataStore.getTxnMeta(txnID).get();
return false;
} catch (ExecutionException e) {
return e.getCause() instanceof CoordinatorException.TransactionNotFoundException;
}
});
}
use of org.apache.pulsar.transaction.coordinator.TxnMeta in project pulsar by yahoo.
the class TransactionMetadataStoreServiceTest method testAddAckedPartitionToTxn.
@Test
public void testAddAckedPartitionToTxn() throws Exception {
TransactionMetadataStoreService transactionMetadataStoreService = pulsar.getTransactionMetadataStoreService();
transactionMetadataStoreService.handleTcClientConnect(TransactionCoordinatorID.get(0)).get();
Awaitility.await().until(() -> transactionMetadataStoreService.getStores().size() == 1);
MLTransactionMetadataStore transactionMetadataStore = (MLTransactionMetadataStore) pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0));
checkTransactionMetadataStoreReady(transactionMetadataStore);
TxnID txnID = transactionMetadataStoreService.newTransaction(TransactionCoordinatorID.get(0), 5000).get();
List<TransactionSubscription> partitions = new ArrayList<>();
partitions.add(TransactionSubscription.builder().topic("ptn-1").subscription("sub-1").build());
partitions.add(TransactionSubscription.builder().topic("ptn-2").subscription("sub-1").build());
partitions.add(TransactionSubscription.builder().topic("ptn-3").subscription("sub-1").build());
transactionMetadataStoreService.addAckedPartitionToTxn(txnID, partitions);
TxnMeta txn = transactionMetadataStoreService.getTxnMeta(txnID).get();
assertEquals(txn.status(), TxnStatus.OPEN);
transactionMetadataStoreService.removeTransactionMetadataStore(TransactionCoordinatorID.get(0));
Assert.assertEquals(transactionMetadataStoreService.getStores().size(), 0);
}
use of org.apache.pulsar.transaction.coordinator.TxnMeta in project incubator-pulsar by apache.
the class TransactionMetadataStoreServiceTest method transactionTimeoutRecoverTest.
@Test
public void transactionTimeoutRecoverTest() throws Exception {
int timeout = 2000;
pulsar.getTransactionMetadataStoreService().handleTcClientConnect(TransactionCoordinatorID.get(0));
Awaitility.await().until(() -> pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0)) != null);
MLTransactionMetadataStore transactionMetadataStore = (MLTransactionMetadataStore) pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0));
checkTransactionMetadataStoreReady(transactionMetadataStore);
transactionMetadataStore.newTransaction(timeout);
pulsar.getTransactionMetadataStoreService().removeTransactionMetadataStore(TransactionCoordinatorID.get(0));
pulsar.getTransactionMetadataStoreService().handleTcClientConnect(TransactionCoordinatorID.get(0));
Awaitility.await().until(() -> pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0)) != null);
transactionMetadataStore = (MLTransactionMetadataStore) pulsar.getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(0));
checkTransactionMetadataStoreReady(transactionMetadataStore);
Field field = MLTransactionMetadataStore.class.getDeclaredField("txnMetaMap");
field.setAccessible(true);
ConcurrentSkipListMap<Long, Pair<TxnMeta, List<Position>>> txnMap = (ConcurrentSkipListMap<Long, Pair<TxnMeta, List<Position>>>) field.get(transactionMetadataStore);
Awaitility.await().until(() -> txnMap.size() == 0);
}
Aggregations