use of org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState in project pulsar by yahoo.
the class TransactionTest method testRetryExceptionOfEndTxn.
@Test
public void testRetryExceptionOfEndTxn() throws Exception {
Transaction transaction = pulsarClient.newTransaction().withTransactionTimeout(10, TimeUnit.SECONDS).build().get();
Class<TransactionMetadataStoreState> transactionMetadataStoreStateClass = TransactionMetadataStoreState.class;
getPulsarServiceList().get(0).getTransactionMetadataStoreService().getStores().values().forEach((transactionMetadataStore -> {
try {
Field field = transactionMetadataStoreStateClass.getDeclaredField("state");
field.setAccessible(true);
field.set(transactionMetadataStore, TransactionMetadataStoreState.State.Initializing);
} catch (Exception e) {
e.printStackTrace();
}
}));
CompletableFuture<Void> completableFuture = transaction.commit();
try {
completableFuture.get(5, TimeUnit.SECONDS);
fail();
} catch (TimeoutException ignored) {
}
getPulsarServiceList().get(0).getTransactionMetadataStoreService().getStores().values().stream().forEach((transactionMetadataStore -> {
try {
Field field = transactionMetadataStoreStateClass.getDeclaredField("state");
field.setAccessible(true);
field.set(transactionMetadataStore, TransactionMetadataStoreState.State.Ready);
} catch (Exception e) {
e.printStackTrace();
}
}));
completableFuture.get(5, TimeUnit.SECONDS);
}
use of org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState in project incubator-pulsar by apache.
the class TransactionTest method testRetryExceptionOfEndTxn.
@Test
public void testRetryExceptionOfEndTxn() throws Exception {
Transaction transaction = pulsarClient.newTransaction().withTransactionTimeout(10, TimeUnit.SECONDS).build().get();
Class<TransactionMetadataStoreState> transactionMetadataStoreStateClass = TransactionMetadataStoreState.class;
getPulsarServiceList().get(0).getTransactionMetadataStoreService().getStores().values().forEach((transactionMetadataStore -> {
try {
Field field = transactionMetadataStoreStateClass.getDeclaredField("state");
field.setAccessible(true);
field.set(transactionMetadataStore, TransactionMetadataStoreState.State.Initializing);
} catch (Exception e) {
e.printStackTrace();
}
}));
CompletableFuture<Void> completableFuture = transaction.commit();
try {
completableFuture.get(5, TimeUnit.SECONDS);
fail();
} catch (TimeoutException ignored) {
}
getPulsarServiceList().get(0).getTransactionMetadataStoreService().getStores().values().stream().forEach((transactionMetadataStore -> {
try {
Field field = transactionMetadataStoreStateClass.getDeclaredField("state");
field.setAccessible(true);
field.set(transactionMetadataStore, TransactionMetadataStoreState.State.Ready);
} catch (Exception e) {
e.printStackTrace();
}
}));
completableFuture.get(5, TimeUnit.SECONDS);
}
use of org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState in project incubator-pulsar by apache.
the class TransactionClientConnectTest method waitToReady.
public void waitToReady() throws Exception {
TransactionMetadataStoreService transactionMetadataStoreService = getPulsarServiceList().get(0).getTransactionMetadataStoreService();
Class<TransactionMetadataStoreService> transactionMetadataStoreServiceClass = TransactionMetadataStoreService.class;
Field field1 = transactionMetadataStoreServiceClass.getDeclaredField("stores");
field1.setAccessible(true);
Map<TransactionCoordinatorID, TransactionMetadataStore> stores = (Map<TransactionCoordinatorID, TransactionMetadataStore>) field1.get(transactionMetadataStoreService);
Awaitility.await().until(() -> {
for (TransactionMetadataStore transactionMetadataStore : stores.values()) {
Class<TransactionMetadataStoreState> transactionMetadataStoreStateClass = TransactionMetadataStoreState.class;
Field field = transactionMetadataStoreStateClass.getDeclaredField("state");
field.setAccessible(true);
TransactionMetadataStoreState.State state = (TransactionMetadataStoreState.State) field.get(transactionMetadataStore);
if (!state.equals(TransactionMetadataStoreState.State.Ready)) {
return false;
}
}
return true;
});
}
use of org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState in project pulsar by yahoo.
the class TransactionClientConnectTest method waitToReady.
public void waitToReady() throws Exception {
TransactionMetadataStoreService transactionMetadataStoreService = getPulsarServiceList().get(0).getTransactionMetadataStoreService();
Class<TransactionMetadataStoreService> transactionMetadataStoreServiceClass = TransactionMetadataStoreService.class;
Field field1 = transactionMetadataStoreServiceClass.getDeclaredField("stores");
field1.setAccessible(true);
Map<TransactionCoordinatorID, TransactionMetadataStore> stores = (Map<TransactionCoordinatorID, TransactionMetadataStore>) field1.get(transactionMetadataStoreService);
Awaitility.await().until(() -> {
for (TransactionMetadataStore transactionMetadataStore : stores.values()) {
Class<TransactionMetadataStoreState> transactionMetadataStoreStateClass = TransactionMetadataStoreState.class;
Field field = transactionMetadataStoreStateClass.getDeclaredField("state");
field.setAccessible(true);
TransactionMetadataStoreState.State state = (TransactionMetadataStoreState.State) field.get(transactionMetadataStore);
if (!state.equals(TransactionMetadataStoreState.State.Ready)) {
return false;
}
}
return true;
});
}
use of org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState in project pulsar by apache.
the class TransactionTest method testRetryExceptionOfEndTxn.
@Test
public void testRetryExceptionOfEndTxn() throws Exception {
Transaction transaction = pulsarClient.newTransaction().withTransactionTimeout(10, TimeUnit.SECONDS).build().get();
Class<TransactionMetadataStoreState> transactionMetadataStoreStateClass = TransactionMetadataStoreState.class;
getPulsarServiceList().get(0).getTransactionMetadataStoreService().getStores().values().forEach((transactionMetadataStore -> {
try {
Field field = transactionMetadataStoreStateClass.getDeclaredField("state");
field.setAccessible(true);
field.set(transactionMetadataStore, TransactionMetadataStoreState.State.Initializing);
} catch (Exception e) {
e.printStackTrace();
}
}));
CompletableFuture<Void> completableFuture = transaction.commit();
try {
completableFuture.get(5, TimeUnit.SECONDS);
fail();
} catch (TimeoutException ignored) {
}
getPulsarServiceList().get(0).getTransactionMetadataStoreService().getStores().values().stream().forEach((transactionMetadataStore -> {
try {
Field field = transactionMetadataStoreStateClass.getDeclaredField("state");
field.setAccessible(true);
field.set(transactionMetadataStore, TransactionMetadataStoreState.State.Ready);
} catch (Exception e) {
e.printStackTrace();
}
}));
completableFuture.get(5, TimeUnit.SECONDS);
}
Aggregations