use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class ShardDataTreeTest method testAbortWithFailedRebase.
@SuppressWarnings("unchecked")
@Test
public void testAbortWithFailedRebase() throws Exception {
immediatePayloadReplication(shardDataTree, mockShard);
final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()));
NormalizedNode<?, ?> peopleNode = PeopleModel.create();
final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(PeopleModel.BASE_PATH, peopleNode));
immediateCanCommit(cohort1);
FutureCallback<Void> canCommitCallback2 = coordinatedCanCommit(cohort2);
coordinatedPreCommit(cohort1);
verify(canCommitCallback2).onSuccess(null);
FutureCallback<Void> mockAbortCallback = mock(FutureCallback.class);
doNothing().when(mockAbortCallback).onSuccess(null);
cohort1.abort(mockAbortCallback);
verify(mockAbortCallback).onSuccess(null);
FutureCallback<DataTreeCandidate> preCommitCallback2 = coordinatedPreCommit(cohort2);
verify(preCommitCallback2).onFailure(any(Throwable.class));
immediateCanCommit(cohort3);
immediatePreCommit(cohort3);
immediateCommit(cohort3);
final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot();
Optional<NormalizedNode<?, ?>> optional = snapshot.readNode(PeopleModel.BASE_PATH);
assertEquals("People node present", true, optional.isPresent());
assertEquals("People node", peopleNode, optional.get());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class ShardDataTreeTest method testAbortWithPendingCommits.
@SuppressWarnings("unchecked")
@Test
public void testAbortWithPendingCommits() throws Exception {
final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> snapshot.write(PeopleModel.BASE_PATH, PeopleModel.create()));
final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()));
YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
MapEntryNode carNode = CarsModel.newCarEntry("optima", new BigInteger("100"));
final ShardDataTreeCohort cohort4 = newShardDataTreeCohort(snapshot -> snapshot.write(carPath, carNode));
coordinatedCanCommit(cohort2);
immediateCanCommit(cohort1);
coordinatedCanCommit(cohort3);
coordinatedCanCommit(cohort4);
coordinatedPreCommit(cohort1);
coordinatedPreCommit(cohort2);
coordinatedPreCommit(cohort3);
FutureCallback<Void> mockAbortCallback = mock(FutureCallback.class);
doNothing().when(mockAbortCallback).onSuccess(null);
cohort2.abort(mockAbortCallback);
verify(mockAbortCallback).onSuccess(null);
coordinatedPreCommit(cohort4);
coordinatedCommit(cohort1);
coordinatedCommit(cohort3);
coordinatedCommit(cohort4);
InOrder inOrder = inOrder(mockShard);
inOrder.verify(mockShard).persistPayload(eq(cohort1.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
inOrder.verify(mockShard).persistPayload(eq(cohort3.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
inOrder.verify(mockShard).persistPayload(eq(cohort4.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
// The payload instance doesn't matter - it just needs to be of type CommitTransactionPayload.
CommitTransactionPayload mockPayload = CommitTransactionPayload.create(nextTransactionId(), cohort1.getCandidate());
shardDataTree.applyReplicatedPayload(cohort1.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort3.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort4.getIdentifier(), mockPayload);
final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot();
Optional<NormalizedNode<?, ?>> optional = snapshot.readNode(carPath);
assertEquals("Car node present", true, optional.isPresent());
assertEquals("Car node", carNode, optional.get());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class ShardDataTreeTest method testPipelinedTransactionsWithImmediateCommits.
@Test
public void testPipelinedTransactionsWithImmediateCommits() throws Exception {
final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()));
YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
MapEntryNode carNode = CarsModel.newCarEntry("optima", new BigInteger("100"));
final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(carPath, carNode));
final FutureCallback<UnsignedLong> commitCallback2 = immediate3PhaseCommit(cohort2);
final FutureCallback<UnsignedLong> commitCallback3 = immediate3PhaseCommit(cohort3);
final FutureCallback<UnsignedLong> commitCallback1 = immediate3PhaseCommit(cohort1);
InOrder inOrder = inOrder(mockShard);
inOrder.verify(mockShard).persistPayload(eq(cohort1.getIdentifier()), any(CommitTransactionPayload.class), eq(true));
inOrder.verify(mockShard).persistPayload(eq(cohort2.getIdentifier()), any(CommitTransactionPayload.class), eq(true));
inOrder.verify(mockShard).persistPayload(eq(cohort3.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
// The payload instance doesn't matter - it just needs to be of type CommitTransactionPayload.
CommitTransactionPayload mockPayload = CommitTransactionPayload.create(nextTransactionId(), cohort1.getCandidate());
shardDataTree.applyReplicatedPayload(cohort1.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort2.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort3.getIdentifier(), mockPayload);
inOrder = inOrder(commitCallback1, commitCallback2, commitCallback3);
inOrder.verify(commitCallback1).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback2).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback3).onSuccess(any(UnsignedLong.class));
final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot();
Optional<NormalizedNode<?, ?>> optional = snapshot.readNode(carPath);
assertEquals("Car node present", true, optional.isPresent());
assertEquals("Car node", carNode, optional.get());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testTransactionReadsWithShardNotInitiallyReady.
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionReadsWithShardNotInitiallyReady() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
final String testName = "testTransactionReadsWithShardNotInitiallyReady";
final String shardName = "test-1";
// Setup the InMemoryJournal to block shard recovery to ensure
// the shard isn't
// initialized until we create the Tx.
final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, testName, false, shardName)) {
// Create the read-write Tx
final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", readWriteTx);
// Do some reads on the Tx on a separate thread.
final AtomicReference<CheckedFuture<Boolean, ReadFailedException>> txExistsFuture = new AtomicReference<>();
final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>> txReadFuture = new AtomicReference<>();
final AtomicReference<Exception> caughtEx = new AtomicReference<>();
final CountDownLatch txReadsDone = new CountDownLatch(1);
final Thread txThread = new Thread(() -> {
try {
readWriteTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
txExistsFuture.set(readWriteTx.exists(TestModel.TEST_PATH));
txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
} catch (Exception e) {
caughtEx.set(e);
} finally {
txReadsDone.countDown();
}
});
txThread.start();
// Wait for the Tx operations to complete.
boolean done = Uninterruptibles.awaitUninterruptibly(txReadsDone, 5, TimeUnit.SECONDS);
if (caughtEx.get() != null) {
throw caughtEx.get();
}
assertEquals("Tx reads done", true, done);
// At this point the Tx operations should be waiting for the
// shard to initialize so
// trigger the latch to let the shard recovery to continue.
blockRecoveryLatch.countDown();
// Wait for the reads to complete and verify.
assertEquals("exists", true, txExistsFuture.get().checkedGet(5, TimeUnit.SECONDS));
assertEquals("read", true, txReadFuture.get().checkedGet(5, TimeUnit.SECONDS).isPresent());
readWriteTx.close();
}
}
};
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testTransactionChainWithSingleShard.
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionChainWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testTransactionChainWithSingleShard", "test-1")) {
// 1. Create a Tx chain and write-only Tx
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
// 2. Write some data
final NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
writeTx.write(TestModel.TEST_PATH, testNode);
// 3. Ready the Tx for commit
final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
// 4. Commit the Tx on another thread that first waits for
// the second read Tx.
final CountDownLatch continueCommit1 = new CountDownLatch(1);
final CountDownLatch commit1Done = new CountDownLatch(1);
final AtomicReference<Exception> commit1Error = new AtomicReference<>();
new Thread(() -> {
try {
continueCommit1.await();
doCommit(cohort1);
} catch (Exception e) {
commit1Error.set(e);
} finally {
commit1Done.countDown();
}
}).start();
// 5. Create a new read Tx from the chain to read and verify
// the data from the first
// Tx is visible after being readied.
DOMStoreReadTransaction readTx = txChain.newReadOnlyTransaction();
Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", testNode, optional.get());
// 6. Create a new RW Tx from the chain, write more data,
// and ready it
final DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
final MapNode outerNode = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
rwTx.write(TestModel.OUTER_LIST_PATH, outerNode);
final DOMStoreThreePhaseCommitCohort cohort2 = rwTx.ready();
// 7. Create a new read Tx from the chain to read the data
// from the last RW Tx to
// verify it is visible.
readTx = txChain.newReadWriteTransaction();
optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", outerNode, optional.get());
// 8. Wait for the 2 commits to complete and close the
// chain.
continueCommit1.countDown();
Uninterruptibles.awaitUninterruptibly(commit1Done, 5, TimeUnit.SECONDS);
if (commit1Error.get() != null) {
throw commit1Error.get();
}
doCommit(cohort2);
txChain.close();
// 9. Create a new read Tx from the data store and verify
// committed data.
readTx = dataStore.newReadOnlyTransaction();
optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", outerNode, optional.get());
}
}
};
}
Aggregations