Stop failing discard-changes operation when tx wasn't initialized 50/28050/2
authorTomas Cere <tcere@cisco.com>
Thu, 8 Oct 2015 10:05:26 +0000 (12:05 +0200)
committerTomas Cere <tcere@cisco.com>
Thu, 8 Oct 2015 10:12:26 +0000 (12:12 +0200)
Change-Id: Icea5b5830caf4fffd034108eb4e524c3aa5d4397
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java
opendaylight/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java

index 3bad8d0c078743bb92773f5797c596e083043196..23da0f5617fc2822184190fd4adfd7c52a09c565 100644 (file)
@@ -94,7 +94,10 @@ public class TransactionProvider implements AutoCloseable{
     public synchronized void abortTransaction() {
         LOG.debug("Aborting current candidateTransaction");
         Optional<DOMDataReadWriteTransaction> otx = getCandidateTransaction();
-        Preconditions.checkState(otx.isPresent(), NO_TRANSACTION_FOUND_FOR_SESSION + netconfSessionIdForReporting);
+        if (!otx.isPresent()) {
+            LOG.warn("discard-changes triggerd on an empty transaction for session: {}", netconfSessionIdForReporting );
+            return;
+        }
         candidateTransaction.cancel();
         allOpenReadWriteTransactions.remove(candidateTransaction);
         candidateTransaction = null;
index 0c3576ca94896a71486f20ca9a0f98e1747631d9..06c4c48d140bb70bd9e9c035ad48188ea63cbfb2 100644 (file)
@@ -146,19 +146,6 @@ public class NetconfMDSalMappingTest {
         assertEmptyDatastore(getConfigRunning());
     }
 
-    @Test
-    public void testDiscard() throws Exception {
-
-        try {
-            discardChanges();
-            fail("Should have failed, need to execute an edit before discard");
-        } catch (DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.error);
-            assertTrue(e.getErrorTag() == ErrorTag.operation_failed);
-            assertTrue(e.getErrorType() == ErrorType.application);
-        }
-    }
-
     @Test
     public void testIncorrectGet() throws Exception {