+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testCaptureWithNullLastLogEntry() throws Exception {
+ boolean capture = snapshotManager.capture(null, 1);
+
+ assertTrue(capture);
+
+ assertEquals(true, snapshotManager.isCapturing());
+
+ ArgumentCaptor<Optional> outputStream = ArgumentCaptor.forClass(Optional.class);
+ verify(mockProcedure).accept(outputStream.capture());
+ assertEquals("isPresent", false, outputStream.getValue().isPresent());
+
+ CaptureSnapshot captureSnapshot = snapshotManager.getCaptureSnapshot();
+
+ // 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 RuntimeException("mock")).when(mockProcedure).accept(anyObject());
+
+ boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1,
+ new MockRaftActorContext.MockPayload()), 9);
+
+ assertFalse(capture);
+
+ assertEquals(false, snapshotManager.isCapturing());
+
+ verify(mockProcedure).accept(anyObject());
+ }
+
+ @SuppressWarnings("unchecked")