Update DOMStoreThreePhaseCommitCohort design
[mdsal.git] / dom / mdsal-dom-broker / src / test / java / org / opendaylight / mdsal / dom / broker / DOMNotificationRouterTest.java
index 12a728ba26b055036e7b096ced0ed8b47554bf83..be0345eb54e92ad2bb05e22311a4f78eedded77a 100644 (file)
@@ -13,13 +13,14 @@ import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
+import static org.opendaylight.mdsal.dom.broker.TestUtils.TEST_CHILD;
 
 import com.google.common.collect.Multimap;
 import com.google.common.util.concurrent.ListenableFuture;
-import com.lmax.disruptor.PhasedBackoffWaitStrategy;
-import com.lmax.disruptor.WaitStrategy;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -33,17 +34,13 @@ import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
 import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener;
 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
 import org.opendaylight.yangtools.util.ListenerRegistry;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 
-public class DOMNotificationRouterTest extends TestUtils {
-
-    private static final WaitStrategy DEFAULT_STRATEGY = PhasedBackoffWaitStrategy.withLock(
-            1L, 30L, TimeUnit.MILLISECONDS);
+public class DOMNotificationRouterTest {
 
     @Test
     public void create() throws Exception {
-        assertNotNull(DOMNotificationRouter.create(1,1,1,TimeUnit.SECONDS));
-        assertNotNull(DOMNotificationRouter.create(1));
+        assertNotNull(DOMNotificationRouter.create(1024));
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
@@ -51,15 +48,19 @@ public class DOMNotificationRouterTest extends TestUtils {
     public void complexTest() throws Exception {
         final DOMNotificationSubscriptionListener domNotificationSubscriptionListener =
                 mock(DOMNotificationSubscriptionListener.class);
+        doNothing().when(domNotificationSubscriptionListener).onSubscriptionChanged(any());
+
         final CountDownLatch latch = new CountDownLatch(1);
         final DOMNotificationListener domNotificationListener = new TestListener(latch);
-        final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(1);
+        final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(1024);
 
-        Multimap<SchemaPath, ?> listeners = domNotificationRouter.listeners();
+        Multimap<Absolute, ?> listeners = domNotificationRouter.listeners();
 
         assertTrue(listeners.isEmpty());
-        assertNotNull(domNotificationRouter.registerNotificationListener(domNotificationListener, SchemaPath.ROOT));
-        assertNotNull(domNotificationRouter.registerNotificationListener(domNotificationListener, SchemaPath.SAME));
+        assertNotNull(domNotificationRouter.registerNotificationListener(domNotificationListener,
+            Absolute.of(TestModel.TEST_QNAME)));
+        assertNotNull(domNotificationRouter.registerNotificationListener(domNotificationListener,
+            Absolute.of(TestModel.TEST2_QNAME)));
 
         listeners = domNotificationRouter.listeners();
 
@@ -77,7 +78,7 @@ public class DOMNotificationRouterTest extends TestUtils {
 
         final DOMNotification domNotification = mock(DOMNotification.class);
         doReturn("test").when(domNotification).toString();
-        doReturn(SchemaPath.ROOT).when(domNotification).getType();
+        doReturn(Absolute.of(TestModel.TEST_QNAME)).when(domNotification).getType();
         doReturn(TEST_CHILD).when(domNotification).getBody();
 
         assertNotNull(domNotificationRouter.offerNotification(domNotification));
@@ -86,6 +87,7 @@ public class DOMNotificationRouterTest extends TestUtils {
             assertNotNull(domNotificationRouter.offerNotification(domNotification, 1, TimeUnit.SECONDS));
             assertNotNull(domNotificationRouter.offerNotification(domNotification, 1, TimeUnit.SECONDS));
         } catch (Exception e) {
+            // FIXME: what is the point here?!
             assertTrue(e instanceof UnsupportedOperationException);
         }
 
@@ -94,9 +96,9 @@ public class DOMNotificationRouterTest extends TestUtils {
 
     @Test
     public void offerNotification() throws Exception {
-        final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(1);
+        final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(1024);
         final DOMNotification domNotification = mock(DOMNotification.class);
-        doReturn(SchemaPath.ROOT).when(domNotification).getType();
+        doReturn(Absolute.of(TestModel.TEST_QNAME)).when(domNotification).getType();
         doReturn(TEST_CHILD).when(domNotification).getBody();
         assertNotNull(domNotificationRouter.putNotification(domNotification));
         assertNotNull(domNotificationRouter.offerNotification(domNotification));
@@ -109,12 +111,12 @@ public class DOMNotificationRouterTest extends TestUtils {
         final TestListener testListener = new TestListener(latch);
         final DOMNotification domNotification = mock(DOMNotification.class);
         doReturn("test").when(domNotification).toString();
-        doReturn(SchemaPath.ROOT).when(domNotification).getType();
+        doReturn(Absolute.of(TestModel.TEST_QNAME)).when(domNotification).getType();
         doReturn(TEST_CHILD).when(domNotification).getBody();
 
         try (TestRouter testRouter = new TestRouter(1)) {
-            assertNotNull(testRouter.registerNotificationListener(testListener, SchemaPath.ROOT));
-            assertNotNull(testRouter.registerNotificationListener(testListener, SchemaPath.SAME));
+            assertNotNull(testRouter.registerNotificationListener(testListener, Absolute.of(TestModel.TEST_QNAME)));
+            assertNotNull(testRouter.registerNotificationListener(testListener, Absolute.of(TestModel.TEST2_QNAME)));
 
             assertNotEquals(DOMNotificationPublishService.REJECTED,
                 testRouter.offerNotification(domNotification, 3, TimeUnit.SECONDS));
@@ -122,14 +124,14 @@ public class DOMNotificationRouterTest extends TestUtils {
             assertEquals("Received notifications", 1, testListener.getReceivedNotifications().size());
 
             assertEquals(DOMNotificationPublishService.REJECTED,
-                testRouter.offerNotification(domNotification, 1, TimeUnit.SECONDS));
+                    testRouter.offerNotification(domNotification, 1, TimeUnit.SECONDS));
             assertEquals("Received notifications", 1, testListener.getReceivedNotifications().size());
         }
     }
 
     @Test
     public void close() throws Exception {
-        final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(1);
+        final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(1024);
         final ExecutorService executor = domNotificationRouter.executor();
         final ExecutorService observer = domNotificationRouter.observer();
 
@@ -160,14 +162,22 @@ public class DOMNotificationRouterTest extends TestUtils {
     }
 
     private static class TestRouter extends DOMNotificationRouter {
+
+        private boolean triggerRejected = false;
+
         TestRouter(final int queueDepth) {
-            super(queueDepth, DEFAULT_STRATEGY);
+            super(queueDepth);
         }
 
         @Override
-        protected ListenableFuture<? extends Object> tryPublish(final DOMNotification notification,
+        ListenableFuture<? extends Object> publish(final DOMNotification notification,
                 final Collection<AbstractListenerRegistration<? extends DOMNotificationListener>> subscribers) {
-            return DOMNotificationPublishService.REJECTED;
+            if (triggerRejected) {
+                return REJECTED;
+            }
+
+            triggerRejected = true;
+            return super.publish(notification, subscribers);
         }
 
         @Override