+ @Test
+ public void testGetFromWithMax(){
+ List<ReplicatedLogEntry> from = replicatedLogImpl.getFrom(0, 1);
+ Assert.assertEquals(1, from.size());
+ Assert.assertEquals(1, from.get(0).getTerm());
+
+ from = replicatedLogImpl.getFrom(0, 20);
+ Assert.assertEquals(4, from.size());
+ Assert.assertEquals(2, from.get(3).getTerm());
+
+ from = replicatedLogImpl.getFrom(1, 2);
+ Assert.assertEquals(2, from.size());
+ Assert.assertEquals(1, from.get(1).getTerm());
+
+ }
+
+ @Test
+ public void testSnapshotPreCommit() {
+ replicatedLogImpl.append(new MockReplicatedLogEntry(2, 4, new MockPayload("E")));
+ replicatedLogImpl.append(new MockReplicatedLogEntry(2, 5, new MockPayload("F")));
+ replicatedLogImpl.append(new MockReplicatedLogEntry(3, 6, new MockPayload("G")));
+ replicatedLogImpl.append(new MockReplicatedLogEntry(3, 7, new MockPayload("H")));
+
+ replicatedLogImpl.snapshotPreCommit(4, 3);
+ assertEquals(3, replicatedLogImpl.size());
+ assertEquals(4, replicatedLogImpl.getSnapshotIndex());
+
+ replicatedLogImpl.snapshotPreCommit(6, 3);
+ assertEquals(1, replicatedLogImpl.size());
+ assertEquals(6, replicatedLogImpl.getSnapshotIndex());
+
+ replicatedLogImpl.snapshotPreCommit(7, 3);
+ assertEquals(0, replicatedLogImpl.size());
+ assertEquals(7, replicatedLogImpl.getSnapshotIndex());
+
+ //running it again on an empty list should not throw exception
+ replicatedLogImpl.snapshotPreCommit(7, 3);
+ assertEquals(0, replicatedLogImpl.size());
+ assertEquals(7, replicatedLogImpl.getSnapshotIndex());
+
+
+ }
+