InMemoryDOMDataTreeShardThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { @SuppressWarnings("checkstyle:IllegalCatch") @Override public ListenableFuture<Boolean> canCommit() { try { dataTree.validate(modification); LOG.debug("DataTreeModification {} validated", modification); return CAN_COMMIT_FUTURE; } catch (DataValidationFailedException e) { LOG.warn("Data validation failed for {}", modification); LOG.trace("dataTree : {}", dataTree); return Futures.immediateFailedFuture(new TransactionCommitFailedException( "Data did not pass validation.", e)); } catch (Exception e) { LOG.warn("Unexpected failure in validation phase", e); return Futures.immediateFailedFuture(e); } } InMemoryDOMDataTreeShardThreePhaseCommitCohort(final DataTree dataTree,
                                                   final DataTreeModification modification,
                                                   final InMemoryDOMDataTreeShardChangePublisher changePublisher); @SuppressWarnings("checkstyle:IllegalCatch") @Override ListenableFuture<Boolean> canCommit(); @SuppressWarnings("checkstyle:IllegalCatch") @Override ListenableFuture<Void> preCommit(); @Override ListenableFuture<Void> abort(); @Override ListenableFuture<Void> commit();  }
@Test public void canCommitWithDataValidationFailedExceptionTest() throws Exception { doThrow(new DataValidationFailedException(YangInstanceIdentifier.empty(), "testException")) .when(DATA_TREE).validate(any()); try { IN_MEMORY_DOM_DATA_TREE_SHARD_THREE_PHASE_COMMIT_COHORT.canCommit().get(); } catch (ExecutionException e) { assertTrue(e.getCause() instanceof TransactionCommitFailedException); } }
@Test public void canCommitWithExceptionTest() throws Exception { doThrow(new RuntimeException("testException")).when(DATA_TREE).validate(any()); try { IN_MEMORY_DOM_DATA_TREE_SHARD_THREE_PHASE_COMMIT_COHORT.canCommit().get(); fail("Expected Exception"); } catch (ExecutionException e) { assertTrue(e.getCause().getMessage().contains("testException")); } }