@SuppressWarnings({ "checkstyle:IllegalThrows", "checkstyle:avoidHidingCauseException" }) @Test(expected = UnsupportedOperationException.class) public void canCommitTestWithUnknownException() throws Throwable { doThrow(new UnsupportedOperationException("testException")) .when(IN_MEMORY_DOM_DATA_STORE).validate(any()); try { inMemoryDOMStoreThreePhaseCommitCohort.canCommit().get(); fail("Expected exception"); } catch (ExecutionException e) { assertTrue(e.getCause() instanceof UnsupportedOperationException); throw e.getCause(); } }
@SuppressWarnings("checkstyle:IllegalCatch") @Override public final ListenableFuture<Boolean> canCommit() { if (operationError != null) { return Futures.immediateFailedFuture(operationError); } try { store.validate(modification); LOG.debug("Store Transaction: {} can be committed", getTransaction().getIdentifier()); return CAN_COMMIT_FUTURE; } catch (ConflictingModificationAppliedException e) { LOG.warn("Store Tx: {} Conflicting modification for {}.", getTransaction().getIdentifier(), e.getPath()); warnDebugContext(getTransaction()); return Futures.immediateFailedFuture(new OptimisticLockFailedException("Optimistic lock failed.", e)); } catch (DataValidationFailedException e) { LOG.warn("Store Tx: {} Data Precondition failed for {}.", getTransaction().getIdentifier(), e.getPath(), e); warnDebugContext(getTransaction()); LOG.trace("Store Tx: {} modifications: {} tree: {}", getTransaction().getIdentifier(), modification, store); 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); } }
InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { @SuppressWarnings("checkstyle:IllegalCatch") @Override public final ListenableFuture<Boolean> canCommit() { if (operationError != null) { return Futures.immediateFailedFuture(operationError); } try { store.validate(modification); LOG.debug("Store Transaction: {} can be committed", getTransaction().getIdentifier()); return CAN_COMMIT_FUTURE; } catch (ConflictingModificationAppliedException e) { LOG.warn("Store Tx: {} Conflicting modification for {}.", getTransaction().getIdentifier(), e.getPath()); warnDebugContext(getTransaction()); return Futures.immediateFailedFuture(new OptimisticLockFailedException("Optimistic lock failed.", e)); } catch (DataValidationFailedException e) { LOG.warn("Store Tx: {} Data Precondition failed for {}.", getTransaction().getIdentifier(), e.getPath(), e); warnDebugContext(getTransaction()); LOG.trace("Store Tx: {} modifications: {} tree: {}", getTransaction().getIdentifier(), modification, store); 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); } } }
InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { @SuppressWarnings("checkstyle:IllegalCatch") @Override public final ListenableFuture<Boolean> canCommit() { if (operationError != null) { return Futures.immediateFailedFuture(operationError); } try { store.validate(modification); LOG.debug("Store Transaction: {} can be committed", getTransaction().getIdentifier()); return CAN_COMMIT_FUTURE; } catch (ConflictingModificationAppliedException e) { LOG.warn("Store Tx: {} Conflicting modification for {}.", getTransaction().getIdentifier(), e.getPath()); warnDebugContext(getTransaction()); return Futures.immediateFailedFuture(new OptimisticLockFailedException("Optimistic lock failed.", e)); } catch (DataValidationFailedException e) { LOG.warn("Store Tx: {} Data Precondition failed for {}.", getTransaction().getIdentifier(), e.getPath(), e); warnDebugContext(getTransaction()); LOG.trace("Store Tx: {} modifications: {} tree: {}", getTransaction().getIdentifier(), modification, store); 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); } } InMemoryDOMStoreThreePhaseCommitCohort(final InMemoryDOMDataStore store,
                                           final SnapshotBackedWriteTransaction<String> writeTransaction,
                                           final DataTreeModification modification,
                                           final Exception operationError); }
InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { @SuppressWarnings("checkstyle:IllegalCatch") @Override public final ListenableFuture<Boolean> canCommit() { if (operationError != null) { return Futures.immediateFailedFuture(operationError); } try { store.validate(modification); LOG.debug("Store Transaction: {} can be committed", getTransaction().getIdentifier()); return CAN_COMMIT_FUTURE; } catch (ConflictingModificationAppliedException e) { LOG.warn("Store Tx: {} Conflicting modification for {}.", getTransaction().getIdentifier(), e.getPath()); warnDebugContext(getTransaction()); return Futures.immediateFailedFuture(new OptimisticLockFailedException("Optimistic lock failed.", e)); } catch (DataValidationFailedException e) { LOG.warn("Store Tx: {} Data Precondition failed for {}.", getTransaction().getIdentifier(), e.getPath(), e); warnDebugContext(getTransaction()); LOG.trace("Store Tx: {} modifications: {} tree: {}", getTransaction().getIdentifier(), modification, store); 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); } } InMemoryDOMStoreThreePhaseCommitCohort(final InMemoryDOMDataStore store,
                                           final SnapshotBackedWriteTransaction<String> writeTransaction,
                                           final DataTreeModification modification,
                                           final Exception operationError); @SuppressWarnings("checkstyle:IllegalCatch") @Override final ListenableFuture<Boolean> canCommit(); @SuppressWarnings("checkstyle:IllegalCatch") @Override final ListenableFuture<Void> preCommit(); @Override final ListenableFuture<Void> abort(); @Override ListenableFuture<Void> commit(); }
InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { @SuppressWarnings("checkstyle:IllegalCatch") @Override public final ListenableFuture<Boolean> canCommit() { if (operationError != null) { return Futures.immediateFailedFuture(operationError); } try { store.validate(modification); LOG.debug("Store Transaction: {} can be committed", getTransaction().getIdentifier()); return CAN_COMMIT_FUTURE; } catch (ConflictingModificationAppliedException e) { LOG.warn("Store Tx: {} Conflicting modification for {}.", getTransaction().getIdentifier(), e.getPath()); warnDebugContext(getTransaction()); return Futures.immediateFailedFuture(new OptimisticLockFailedException("Optimistic lock failed.", e)); } catch (DataValidationFailedException e) { LOG.warn("Store Tx: {} Data Precondition failed for {}.", getTransaction().getIdentifier(), e.getPath(), e); warnDebugContext(getTransaction()); LOG.trace("Store Tx: {} modifications: {} tree: {}", getTransaction().getIdentifier(), modification, store); 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); } } InMemoryDOMStoreThreePhaseCommitCohort(final InMemoryDOMDataStore store,
                                           final SnapshotBackedWriteTransaction<String> writeTransaction,
                                           final DataTreeModification modification,
                                           final Exception operationError); @SuppressWarnings("checkstyle:IllegalCatch") @Override final ListenableFuture<Boolean> canCommit(); @SuppressWarnings("checkstyle:IllegalCatch") @Override final ListenableFuture<Void> preCommit(); @Override final ListenableFuture<Void> abort(); @Override ListenableFuture<Void> commit();  }