Search in sources :

Example 16 with DOMStoreReadTransaction

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());
    }
}
Also used : DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) Builder(org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test)

Example 17 with DOMStoreReadTransaction

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);
        }
    }
}
Also used : RequestTimeoutException(org.opendaylight.controller.cluster.access.client.RequestTimeoutException) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) AddressFromURIString(akka.actor.AddressFromURIString) ExecutionException(java.util.concurrent.ExecutionException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) Test(org.junit.Test)

Example 18 with DOMStoreReadTransaction

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);
}
Also used : DOMStoreTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransaction) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) Test(org.junit.Test)

Example 19 with 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());
}
Also used : DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)

Aggregations

DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)19 Test (org.junit.Test)16 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)10 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)10 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 AddressFromURIString (akka.actor.AddressFromURIString)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)5 ExecutionException (java.util.concurrent.ExecutionException)4 RequestTimeoutException (org.opendaylight.controller.cluster.access.client.RequestTimeoutException)4 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)4 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)3 DOMStoreTransactionChain (org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain)3 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)2 TransactionChainClosedException (org.opendaylight.mdsal.common.api.TransactionChainClosedException)2 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)2