BUG 4017: Notification publish service is not available from provider context
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / ReplicatedLogImplTest.java
index 72ccae7626db83e3d83d274b95d6e0aa22215bf8..cc81e712ec221ff46c2c005014462c8c365c13d2 100644 (file)
@@ -8,8 +8,9 @@
 package org.opendaylight.controller.cluster.raft;
 
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.verify;
@@ -31,7 +32,7 @@ import org.mockito.internal.matchers.Same;
 import org.opendaylight.controller.cluster.DataPersistenceProvider;
 import org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload;
 import org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockReplicatedLogEntry;
-import org.opendaylight.controller.cluster.raft.RaftActor.DeleteEntries;
+import org.opendaylight.controller.cluster.raft.base.messages.DeleteEntries;
 import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -50,9 +51,6 @@ public class ReplicatedLogImplTest {
     @Mock
     private RaftActorBehavior mockBehavior;
 
-    @Mock
-    private SnapshotManager mockSnapshotManager;
-
     private RaftActorContext context;
     private final DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
 
@@ -60,14 +58,11 @@ public class ReplicatedLogImplTest {
     public void setup() {
         MockitoAnnotations.initMocks(this);
 
+        doNothing().when(mockPersistence).persist(any(Object.class), any(Procedure.class));
+
         context = new RaftActorContextImpl(null, null, "test",
                 new ElectionTermImpl(mockPersistence, "test", LOG),
-                -1, -1, Collections.<String,String>emptyMap(), configParams, LOG)  {
-            @Override
-            public SnapshotManager getSnapshotManager() {
-                return mockSnapshotManager;
-            }
-        };
+                -1, -1, Collections.<String,String>emptyMap(), configParams, mockPersistence, LOG);
     }
 
     private void verifyPersist(Object message) throws Exception {
@@ -85,7 +80,7 @@ public class ReplicatedLogImplTest {
     @SuppressWarnings("unchecked")
     @Test
     public void testAppendAndPersistExpectingNoCapture() throws Exception {
-        ReplicatedLog log = ReplicatedLogImpl.newInstance(context, mockPersistence, mockBehavior);
+        ReplicatedLog log = ReplicatedLogImpl.newInstance(context, mockBehavior);
 
         MockReplicatedLogEntry logEntry = new MockReplicatedLogEntry(1, 1, new MockPayload("1"));
 
@@ -97,13 +92,15 @@ public class ReplicatedLogImplTest {
 
         reset(mockPersistence);
 
+        doNothing().when(mockPersistence).persist(any(MockReplicatedLogEntry.class), any(Procedure.class));
+
         Procedure<ReplicatedLogEntry> mockCallback = Mockito.mock(Procedure.class);
+        doNothing().when(mockCallback).apply(logEntry);
         log.appendAndPersist(logEntry, mockCallback);
 
         verifyPersist(logEntry);
 
         verify(mockCallback).apply(same(logEntry));
-        verifyNoMoreInteractions(mockSnapshotManager);
 
         assertEquals("size", 2, log.size());
     }
@@ -114,7 +111,7 @@ public class ReplicatedLogImplTest {
 
         doReturn(1L).when(mockBehavior).getReplicatedToAllIndex();
 
-        ReplicatedLog log = ReplicatedLogImpl.newInstance(context, mockPersistence, mockBehavior);
+        ReplicatedLog log = ReplicatedLogImpl.newInstance(context, mockBehavior);
 
         MockReplicatedLogEntry logEntry1 = new MockReplicatedLogEntry(1, 2, new MockPayload("2"));
         MockReplicatedLogEntry logEntry2 = new MockReplicatedLogEntry(1, 3, new MockPayload("3"));
@@ -122,13 +119,13 @@ public class ReplicatedLogImplTest {
         log.appendAndPersist(logEntry1);
         verifyPersist(logEntry1);
 
-        verifyNoMoreInteractions(mockSnapshotManager);
         reset(mockPersistence);
 
+        doNothing().when(mockPersistence).persist(any(MockReplicatedLogEntry.class), any(Procedure.class));
+
         log.appendAndPersist(logEntry2);
         verifyPersist(logEntry2);
 
-        verify(mockSnapshotManager).capture(same(logEntry2), eq(1L));
 
         assertEquals("size", 2, log.size());
     }
@@ -144,34 +141,30 @@ public class ReplicatedLogImplTest {
             }
         });
 
-        ReplicatedLog log = ReplicatedLogImpl.newInstance(context, mockPersistence, mockBehavior);
+        ReplicatedLog log = ReplicatedLogImpl.newInstance(context, mockBehavior);
 
         int dataSize = 600;
         MockReplicatedLogEntry logEntry = new MockReplicatedLogEntry(1, 2, new MockPayload("2", dataSize));
 
-        doReturn(true).when(mockSnapshotManager).capture(same(logEntry), eq(1L));
-
         log.appendAndPersist(logEntry);
         verifyPersist(logEntry);
 
-        verify(mockSnapshotManager).capture(same(logEntry), eq(1L));
+        reset(mockPersistence);
 
-        reset(mockPersistence, mockSnapshotManager);
+        doNothing().when(mockPersistence).persist(any(MockReplicatedLogEntry.class), any(Procedure.class));
 
         logEntry = new MockReplicatedLogEntry(1, 3, new MockPayload("3", 5));
 
         log.appendAndPersist(logEntry);
         verifyPersist(logEntry);
 
-        verifyNoMoreInteractions(mockSnapshotManager);
-
         assertEquals("size", 2, log.size());
     }
 
     @Test
     public void testRemoveFromAndPersist() throws Exception {
 
-        ReplicatedLog log = ReplicatedLogImpl.newInstance(context, mockPersistence, mockBehavior);
+        ReplicatedLog log = ReplicatedLogImpl.newInstance(context, mockBehavior);
 
         log.append(new MockReplicatedLogEntry(1, 0, new MockPayload("0")));
         log.append(new MockReplicatedLogEntry(1, 1, new MockPayload("1")));