Bug 2461 : Adding capture snapshot JMX operation.
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / SnapshotManagerTest.java
index 023f60909e0b3d41b044ebba3668f54144bc3ceb..df83f8f55843b4f82ad9f4f8336c8b6913482c5b 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
 package org.opendaylight.controller.cluster.raft;
 
 import static org.junit.Assert.assertArrayEquals;
@@ -152,6 +160,35 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
     }
 
+    @Test
+    public void testCaptureWithNullLastLogEntry() throws Exception {
+        boolean capture = snapshotManager.capture(null, 1);
+
+        assertTrue(capture);
+
+        assertEquals(true, snapshotManager.isCapturing());
+
+        verify(mockProcedure).apply(null);
+
+        CaptureSnapshot captureSnapshot = snapshotManager.getCaptureSnapshot();
+
+        System.out.println(captureSnapshot);
+
+        // LastIndex and LastTerm are picked up from the lastLogEntry
+        assertEquals(-1L, captureSnapshot.getLastIndex());
+        assertEquals(-1L, captureSnapshot.getLastTerm());
+
+        // Since the actor does not have any followers (no peer addresses) lastApplied will be from lastLogEntry
+        assertEquals(-1L, captureSnapshot.getLastAppliedIndex());
+        assertEquals(-1L, captureSnapshot.getLastAppliedTerm());
+
+        //
+        assertEquals(-1L, captureSnapshot.getReplicatedToAllIndex());
+        assertEquals(-1L, captureSnapshot.getReplicatedToAllTerm());
+        actorRef.underlyingActor().clear();
+
+    }
+
     @Test
     public void testCaptureWithCreateProcedureError () throws Exception {
         doThrow(new Exception("mock")).when(mockProcedure).apply(null);