Add create/create test for PingPongTransactionChain 64/101264/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 23 May 2022 11:55:57 +0000 (13:55 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 23 May 2022 11:56:48 +0000 (13:56 +0200)
Extend the test to cover allocation of concurrent transactions.

Change-Id: I5ba10cfe335499645441afe0a7ec8d5e6a6691ce
JIRA: MDSAL-698
Signed-off-by: Samuel Schneider <samuel.schneider@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/PingPongTransactionChainTest.java

index f3e2e645ce444c462386476bd0e5265d5265e3b4..866bfdb34d039108adb9af4eaaf73b765bbd5f7e 100644 (file)
@@ -7,6 +7,10 @@
  */
 package org.opendaylight.mdsal.dom.spi;
 
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -212,6 +216,17 @@ public class PingPongTransactionChainTest {
         assertNotNull(pingPong.newWriteOnlyTransaction());
     }
 
+    @Test
+    public void testNewAfterNew() {
+        assertNotNull(pingPong.newWriteOnlyTransaction());
+        doReturn(true).when(rwTx).cancel();
+        doReturn("mock").when(rwTx).toString();
+        final var ex = assertThrows(IllegalStateException.class, () -> pingPong.newWriteOnlyTransaction());
+        assertThat(ex.getMessage(), allOf(
+            startsWith("New transaction PingPongTransaction"),
+            containsString(" raced with transaction PingPongTransaction")));
+    }
+
     private static <T> T assertDone(final FluentFuture<T> future) {
         try {
             return Futures.getDone(future);