+ @Test
+ public void testChainWithReadOnlyTxAfterPreviousReady() throws Exception {
+ new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+ {
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testChainWithReadOnlyTxAfterPreviousReady", "test-1")) {
+
+ final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+
+ // Create a write tx and submit.
+ final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+ final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
+
+ // Create read-only tx's and issue a read.
+ FluentFuture<Optional<NormalizedNode<?, ?>>> readFuture1 = txChain
+ .newReadOnlyTransaction().read(TestModel.TEST_PATH);
+
+ FluentFuture<Optional<NormalizedNode<?, ?>>> readFuture2 = txChain
+ .newReadOnlyTransaction().read(TestModel.TEST_PATH);
+
+ // Create another write tx and issue the write.
+ DOMStoreWriteTransaction writeTx2 = txChain.newWriteOnlyTransaction();
+ writeTx2.write(TestModel.OUTER_LIST_PATH,
+ ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+
+ // Ensure the reads succeed.
+
+ assertEquals("isPresent", true, readFuture1.get(5, TimeUnit.SECONDS).isPresent());
+ assertEquals("isPresent", true, readFuture2.get(5, TimeUnit.SECONDS).isPresent());
+
+ // Ensure the writes succeed.
+ DOMStoreThreePhaseCommitCohort cohort2 = writeTx2.ready();
+
+ doCommit(cohort1);
+ doCommit(cohort2);
+
+ assertEquals("isPresent", true, txChain.newReadOnlyTransaction().read(TestModel.OUTER_LIST_PATH)
+ .get(5, TimeUnit.SECONDS).isPresent());
+ }
+ }
+ };
+ }
+
+ @Test
+ public void testChainedTransactionFailureWithSingleShard() throws Exception {
+ new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+ {
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testChainedTransactionFailureWithSingleShard", "cars-1")) {
+
+ final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
+ ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
+ .put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
+ MoreExecutors.directExecutor());
+
+ final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+ final DOMTransactionChain txChain = broker.createTransactionChain(listener);
+
+ final DOMDataTreeReadWriteTransaction writeTx = txChain.newReadWriteTransaction();
+
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH,
+ PeopleModel.emptyContainer());
+
+ final ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
+ .withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
+
+ writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
+
+ try {
+ writeTx.commit().get(5, TimeUnit.SECONDS);
+ fail("Expected TransactionCommitFailedException");
+ } catch (final ExecutionException e) {
+ // Expected
+ }
+
+ verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx),
+ any(Throwable.class));
+
+ txChain.close();
+ broker.close();
+ }
+ }
+ };
+ }
+
+ @Test
+ public void testChainedTransactionFailureWithMultipleShards() throws Exception {
+ new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+ {
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1")) {
+
+ final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
+ ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
+ .put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
+ MoreExecutors.directExecutor());
+
+ final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+ final DOMTransactionChain txChain = broker.createTransactionChain(listener);
+
+ final DOMDataTreeWriteTransaction writeTx = txChain.newReadWriteTransaction();
+
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH,
+ PeopleModel.emptyContainer());
+
+ final ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
+ .withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
+
+ writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
+
+ // Note that merge will validate the data and fail but put
+ // succeeds b/c deep validation is not
+ // done for put for performance reasons.
+ try {
+ writeTx.commit().get(5, TimeUnit.SECONDS);
+ fail("Expected TransactionCommitFailedException");
+ } catch (final ExecutionException e) {
+ // Expected