use of org.opendaylight.controller.cluster.access.client.RequestTimeoutException in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testTransactionCommitFailureWithNoShardLeader.
@SuppressWarnings("checkstyle:IllegalCatch")
private void testTransactionCommitFailureWithNoShardLeader(final boolean writeOnly, final String testName) throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
final String shardName = "default";
// We don't want the shard to become the leader so prevent shard
// elections.
datastoreContextBuilder.customRaftPolicyImplementation("org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy");
// The ShardManager uses the election timeout for FindPrimary so
// reset it low so it will timeout quickly.
datastoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(1).shardInitializationTimeout(200, TimeUnit.MILLISECONDS).frontendRequestTimeoutInSeconds(2);
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, testName, false, shardName)) {
final Object result = dataStore.getActorContext().executeOperation(dataStore.getActorContext().getShardManager(), new FindLocalShard(shardName, true));
assertTrue("Expected LocalShardFound. Actual: " + result, result instanceof LocalShardFound);
// Create the write Tx.
DOMStoreWriteTransaction writeTxToClose = null;
try {
writeTxToClose = writeOnly ? dataStore.newWriteOnlyTransaction() : dataStore.newReadWriteTransaction();
final DOMStoreWriteTransaction writeTx = writeTxToClose;
assertNotNull("newReadWriteTransaction returned null", writeTx);
// Do some modifications and ready the Tx on a separate
// thread.
final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
final AtomicReference<Exception> caughtEx = new AtomicReference<>();
final CountDownLatch txReady = new CountDownLatch(1);
final Thread txThread = new Thread(() -> {
try {
writeTx.write(TestModel.JUNK_PATH, ImmutableNodes.containerNode(TestModel.JUNK_QNAME));
txCohort.set(writeTx.ready());
} catch (Exception e) {
caughtEx.set(e);
} finally {
txReady.countDown();
}
});
txThread.start();
// Wait for the Tx operations to complete.
boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
if (caughtEx.get() != null) {
throw caughtEx.get();
}
assertEquals("Tx ready", true, done);
// exception cause.
try {
txCohort.get().canCommit().get(10, TimeUnit.SECONDS);
fail("Expected NoShardLeaderException");
} catch (final ExecutionException e) {
final String msg = "Unexpected exception: " + Throwables.getStackTraceAsString(e.getCause());
if (DistributedDataStore.class.equals(testParameter)) {
assertTrue(Throwables.getRootCause(e) instanceof NoShardLeaderException);
} else {
assertTrue(msg, Throwables.getRootCause(e) instanceof RequestTimeoutException);
}
}
} finally {
try {
if (writeTxToClose != null) {
writeTxToClose.close();
}
} catch (Exception e) {
// FIXME TransactionProxy.close throws IllegalStateException:
// Transaction is ready, it cannot be closed
}
}
}
}
};
}
use of org.opendaylight.controller.cluster.access.client.RequestTimeoutException in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testTransactionWithCreateTxFailureDueToNoLeader.
@Test
public void testTransactionWithCreateTxFailureDueToNoLeader() throws Exception {
followerDatastoreContextBuilder.frontendRequestTimeoutInSeconds(2);
initDatastoresWithCars("testTransactionWithCreateTxFailureDueToNoLeader");
// Do an initial read to get the primary shard info cached.
final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
readTx.read(CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
// Shutdown the leader and try to create a new tx.
TestKit.shutdownActorSystem(leaderSystem, true);
Cluster.get(followerSystem).leave(MEMBER_1_ADDRESS);
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder.operationTimeoutInMillis(10).shardElectionTimeoutFactor(1).customRaftPolicyImplementation(null));
final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
try {
followerTestKit.doCommit(rwTx.ready());
fail("Exception expected");
} catch (final ExecutionException e) {
final String msg = "Unexpected exception: " + Throwables.getStackTraceAsString(e.getCause());
if (DistributedDataStore.class.equals(testParameter)) {
assertTrue(msg, Throwables.getRootCause(e) instanceof NoShardLeaderException);
} else {
assertTrue(msg, Throwables.getRootCause(e) instanceof RequestTimeoutException);
}
}
}
use of org.opendaylight.controller.cluster.access.client.RequestTimeoutException in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testTransactionWithShardLeaderNotResponding.
@Test
public void testTransactionWithShardLeaderNotResponding() throws Exception {
followerDatastoreContextBuilder.frontendRequestTimeoutInSeconds(2);
followerDatastoreContextBuilder.shardElectionTimeoutFactor(50);
initDatastoresWithCars("testTransactionWithShardLeaderNotResponding");
// Do an initial read to get the primary shard info cached.
final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
readTx.read(CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
// Shutdown the leader and try to create a new tx.
TestKit.shutdownActorSystem(leaderSystem, true);
followerDatastoreContextBuilder.operationTimeoutInMillis(50).shardElectionTimeoutFactor(1);
sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder);
final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
try {
followerTestKit.doCommit(rwTx.ready());
fail("Exception expected");
} catch (final ExecutionException e) {
final String msg = "Unexpected exception: " + Throwables.getStackTraceAsString(e.getCause());
if (DistributedDataStore.class.equals(testParameter)) {
assertTrue(msg, Throwables.getRootCause(e) instanceof NoShardLeaderException || e.getCause() instanceof ShardLeaderNotRespondingException);
} else {
assertTrue(msg, Throwables.getRootCause(e) instanceof RequestTimeoutException);
}
}
}
Aggregations