+
+ String errorMsg = "mock OptimisticLockFailedException";
+ Throwable cause = new ConflictingModificationAppliedException(TestModel.TEST_PATH, "mock");
+ doReturn(Futures.immediateFailedFuture(new org.opendaylight.mdsal.common.api.TransactionCommitFailedException(
+ errorMsg, cause))).when(mockCommitCohort).canCommit();
+
+ try {
+ tx = adapter.newWriteOnlyTransaction();
+ tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
+ commit(tx);
+ fail("Expected TransactionCommitFailedException");
+ } catch (TransactionCommitFailedException e) {
+ assertEquals("getMessage", errorMsg, e.getMessage());
+ assertEquals("getCause", cause, e.getCause());
+ }
+ }
+
+ @SuppressWarnings("checkstyle:AvoidHidingCauseException")
+ private static void commit(DOMDataWriteTransaction tx)
+ throws TransactionCommitFailedException, InterruptedException, TimeoutException {
+ try {
+ tx.commit().get(5, TimeUnit.SECONDS);
+ } catch (ExecutionException e) {
+ assertTrue("Expected TransactionCommitFailedException. Actual: " + e.getCause(),
+ e.getCause() instanceof TransactionCommitFailedException);
+ throw (TransactionCommitFailedException)e.getCause();
+ }