use of org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testTransactionRetryWithInitialAskTimeoutExOnCreateTx.
@Test
public void testTransactionRetryWithInitialAskTimeoutExOnCreateTx() throws Exception {
followerDatastoreContextBuilder.backendAlivenessTimerIntervalInSeconds(2);
String testName = "testTransactionRetryWithInitialAskTimeoutExOnCreateTx";
initDatastores(testName, MODULE_SHARDS_CARS_1_2_3, CARS);
final DatastoreContext.Builder follower2DatastoreContextBuilder = DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(10);
final IntegrationTestKit follower2TestKit = new IntegrationTestKit(follower2System, follower2DatastoreContextBuilder, commitTimeout);
try (AbstractDataStore ds = follower2TestKit.setupAbstractDataStore(testParameter, testName, MODULE_SHARDS_CARS_1_2_3, false, CARS)) {
followerTestKit.waitForMembersUp("member-1", "member-3");
follower2TestKit.waitForMembersUp("member-1", "member-2");
// 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);
sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder.operationTimeoutInMillis(500).shardElectionTimeoutFactor(5).customRaftPolicyImplementation(null));
final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
followerTestKit.doCommit(rwTx.ready());
}
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction 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);
}
}
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction in project controller by opendaylight.
the class TransactionChainProxyTest method testNewReadOnlyTransaction.
@SuppressWarnings("resource")
@Test
public void testNewReadOnlyTransaction() {
DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory, historyId).newReadOnlyTransaction();
Assert.assertTrue(dst instanceof DOMStoreReadTransaction);
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction in project controller by opendaylight.
the class IntegrationTestKit method testWriteTransaction.
void testWriteTransaction(final AbstractDataStore dataStore, final YangInstanceIdentifier nodePath, final NormalizedNode<?, ?> nodeToWrite) throws Exception {
// 1. Create a write-only Tx
DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
// 2. Write some data
writeTx.write(nodePath, nodeToWrite);
// 3. Ready the Tx for commit
DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
// 4. Commit the Tx
doCommit(cohort);
// 5. Verify the data in the store
DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
Optional<NormalizedNode<?, ?>> optional = readTx.read(nodePath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", nodeToWrite, optional.get());
}
Aggregations