import akka.testkit.TestActorRef;
import com.google.common.base.Optional;
import com.google.common.base.Stopwatch;
-import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteSource;
@Override
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
if (follower != null) {
follower.close();
}
}
@Override
- protected Follower createBehavior(RaftActorContext actorContext) {
+ protected Follower createBehavior(final RaftActorContext actorContext) {
return spy(new Follower(actorContext));
}
}
@Override
- protected MockRaftActorContext createActorContext(ActorRef actorRef) {
+ protected MockRaftActorContext createActorContext(final ActorRef actorRef) {
MockRaftActorContext context = new MockRaftActorContext("follower", getSystem(), actorRef);
context.setPayloadVersion(payloadVersion);
return context;
@Test
- public void testHandleFirstAppendEntries() throws Exception {
+ public void testHandleFirstAppendEntries() {
logStart("testHandleFirstAppendEntries");
MockRaftActorContext context = createActorContext();
}
@Test
- public void testHandleFirstAppendEntriesWithPrevIndexMinusOne() throws Exception {
+ public void testHandleFirstAppendEntriesWithPrevIndexMinusOne() {
logStart("testHandleFirstAppendEntries");
MockRaftActorContext context = createActorContext();
}
@Test
- public void testHandleFirstAppendEntriesWithPrevIndexMinusOneAndReplicatedToAllIndexPresentInLog()
- throws Exception {
+ public void testHandleFirstAppendEntriesWithPrevIndexMinusOneAndReplicatedToAllIndexPresentInLog() {
logStart("testHandleFirstAppendEntries");
MockRaftActorContext context = createActorContext();
}
@Test
- public void testHandleFirstAppendEntriesWithPrevIndexMinusOneAndReplicatedToAllIndexPresentInSnapshot()
- throws Exception {
+ public void testHandleFirstAppendEntriesWithPrevIndexMinusOneAndReplicatedToAllIndexPresentInSnapshot() {
logStart("testHandleFirstAppendEntries");
MockRaftActorContext context = createActorContext();
}
@Test
- public void testFirstAppendEntriesWithNoPrevIndexAndReplicatedToAllPresentInSnapshotButCalculatedPrevEntryMissing()
- throws Exception {
+ public void testFirstAppendEntriesWithNoPrevIndexAndReplToAllPresentInSnapshotButCalculatedPrevEntryMissing() {
logStart(
"testFirstAppendEntriesWithNoPrevIndexAndReplicatedToAllPresentInSnapshotButCalculatedPrevEntryMissing");
}
@Test
- public void testHandleSyncUpAppendEntries() throws Exception {
+ public void testHandleSyncUpAppendEntries() {
logStart("testHandleSyncUpAppendEntries");
MockRaftActorContext context = createActorContext();
context.setLastApplied(101);
context.setCommitIndex(101);
- setLastLogEntry(context, 1, 101,
- new MockRaftActorContext.MockPayload(""));
+ setLastLogEntry(context, 1, 101, new MockRaftActorContext.MockPayload(""));
- entries = Arrays.asList(
- newReplicatedLogEntry(2, 101, "foo"));
+ entries = Arrays.asList(newReplicatedLogEntry(2, 101, "foo"));
// The new commitIndex is 101
appendEntries = new AppendEntries(2, "leader-1", 101, 1, entries, 102, 101, (short)0);
syncStatus = MessageCollectorActor.getFirstMatching(followerActor, FollowerInitialSyncUpStatus.class);
assertNull(syncStatus);
-
}
@Test
- public void testHandleAppendEntriesLeaderChangedBeforeSyncUpComplete() throws Exception {
+ public void testHandleAppendEntriesLeaderChangedBeforeSyncUpComplete() {
logStart("testHandleAppendEntriesLeaderChangedBeforeSyncUpComplete");
MockRaftActorContext context = createActorContext();
// We get a new message saying initial status is not done
assertFalse(syncStatus.isInitialSyncDone());
-
}
-
@Test
- public void testHandleAppendEntriesLeaderChangedAfterSyncUpComplete() throws Exception {
+ public void testHandleAppendEntriesLeaderChangedAfterSyncUpComplete() {
logStart("testHandleAppendEntriesLeaderChangedAfterSyncUpComplete");
MockRaftActorContext context = createActorContext();
// We get a new message saying initial status is not done
assertFalse(syncStatus.isInitialSyncDone());
-
}
-
/**
* This test verifies that when an AppendEntries RPC is received by a RaftActor
* with a commitIndex that is greater than what has been applied to the
* sets it current applied state to the commitIndex of the sender.
*/
@Test
- public void testHandleAppendEntriesWithNewerCommitIndex() throws Exception {
+ public void testHandleAppendEntriesWithNewerCommitIndex() {
logStart("testHandleAppendEntriesWithNewerCommitIndex");
MockRaftActorContext context = createActorContext();
* the follower its applied correctly.
*/
@Test
- public void testHandleInstallSnapshot() throws Exception {
+ public void testHandleInstallSnapshot() {
logStart("testHandleInstallSnapshot");
MockRaftActorContext context = createActorContext();
assertNull("Expected null SnapshotTracker", follower.getSnapshotTracker());
}
-
/**
* Verify that when an AppendEntries is sent to a follower during a snapshot install
* the Follower short-circuits the processing of the AppendEntries message.
*/
@Test
- public void testReceivingAppendEntriesDuringInstallSnapshot() throws Exception {
+ public void testReceivingAppendEntriesDuringInstallSnapshot() {
logStart("testReceivingAppendEntriesDuringInstallSnapshot");
MockRaftActorContext context = createActorContext();
}
@Test
- public void testReceivingAppendEntriesDuringInstallSnapshotFromDifferentLeader() throws Exception {
+ public void testReceivingAppendEntriesDuringInstallSnapshotFromDifferentLeader() {
logStart("testReceivingAppendEntriesDuringInstallSnapshotFromDifferentLeader");
MockRaftActorContext context = createActorContext();
}
@Test
- public void testInitialSyncUpWithHandleInstallSnapshotFollowedByAppendEntries() throws Exception {
+ public void testInitialSyncUpWithHandleInstallSnapshotFollowedByAppendEntries() {
logStart("testInitialSyncUpWithHandleInstallSnapshot");
MockRaftActorContext context = createActorContext();
}
@Test
- public void testHandleOutOfSequenceInstallSnapshot() throws Exception {
+ public void testHandleOutOfSequenceInstallSnapshot() {
logStart("testHandleOutOfSequenceInstallSnapshot");
MockRaftActorContext context = createActorContext();
}
@Test
- public void testCaptureSnapshotOnLastEntryInAppendEntries() throws Exception {
+ public void testCaptureSnapshotOnLastEntryInAppendEntries() {
String id = "testCaptureSnapshotOnLastEntryInAppendEntries";
logStart(id);
}
@Test
- public void testCaptureSnapshotOnMiddleEntryInAppendEntries() throws Exception {
+ public void testCaptureSnapshotOnMiddleEntryInAppendEntries() {
String id = "testCaptureSnapshotOnMiddleEntryInAppendEntries";
logStart(id);
}
@Test
- public void testCaptureSnapshotOnAppendEntriesWithUnapplied() throws Exception {
+ public void testCaptureSnapshotOnAppendEntriesWithUnapplied() {
String id = "testCaptureSnapshotOnAppendEntriesWithUnapplied";
logStart(id);
}
@SuppressWarnings("checkstyle:IllegalCatch")
- private RaftActorSnapshotCohort newRaftActorSnapshotCohort(final AtomicReference<MockRaftActor> followerRaftActor) {
+ private static RaftActorSnapshotCohort newRaftActorSnapshotCohort(
+ final AtomicReference<MockRaftActor> followerRaftActor) {
RaftActorSnapshotCohort snapshotCohort = new RaftActorSnapshotCohort() {
@Override
- public void createSnapshot(ActorRef actorRef, java.util.Optional<OutputStream> installSnapshotStream) {
+ public void createSnapshot(final ActorRef actorRef,
+ final java.util.Optional<OutputStream> installSnapshotStream) {
try {
actorRef.tell(new CaptureSnapshotReply(new MockSnapshotState(followerRaftActor.get().getState()),
installSnapshotStream), actorRef);
+ } catch (RuntimeException e) {
+ throw e;
} catch (Exception e) {
- Throwables.propagate(e);
+ throw new RuntimeException(e);
}
}
@Override
- public void applySnapshot(State snapshotState) {
+ public void applySnapshot(final State snapshotState) {
}
@Override
- public State deserializeSnapshot(ByteSource snapshotBytes) {
+ public State deserializeSnapshot(final ByteSource snapshotBytes) {
throw new UnsupportedOperationException();
}
};
return snapshotCohort;
}
- public byte[] getNextChunk(ByteString bs, int offset, int chunkSize) {
+ public byte[] getNextChunk(final ByteString bs, final int offset, final int chunkSize) {
int snapshotLength = bs.size();
int start = offset;
int size = chunkSize;
return nextChunk;
}
- private void expectAndVerifyAppendEntriesReply(int expTerm, boolean expSuccess,
- String expFollowerId, long expLogLastTerm, long expLogLastIndex) {
+ private void expectAndVerifyAppendEntriesReply(final int expTerm, final boolean expSuccess,
+ final String expFollowerId, final long expLogLastTerm, final long expLogLastIndex) {
expectAndVerifyAppendEntriesReply(expTerm, expSuccess, expFollowerId, expLogLastTerm, expLogLastIndex, false);
}
- private void expectAndVerifyAppendEntriesReply(int expTerm, boolean expSuccess,
- String expFollowerId, long expLogLastTerm, long expLogLastIndex,
- boolean expForceInstallSnapshot) {
+ private void expectAndVerifyAppendEntriesReply(final int expTerm, final boolean expSuccess,
+ final String expFollowerId, final long expLogLastTerm, final long expLogLastIndex,
+ final boolean expForceInstallSnapshot) {
AppendEntriesReply reply = MessageCollectorActor.expectFirstMatching(leaderActor,
AppendEntriesReply.class);
}
- private static ReplicatedLogEntry newReplicatedLogEntry(long term, long index, String data) {
+ private static ReplicatedLogEntry newReplicatedLogEntry(final long term, final long index, final String data) {
return new SimpleReplicatedLogEntry(index, term,
new MockRaftActorContext.MockPayload(data));
}
}
@Override
- protected void assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(MockRaftActorContext actorContext,
- ActorRef actorRef, RaftRPC rpc) throws Exception {
+ protected void assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(final MockRaftActorContext actorContext,
+ final ActorRef actorRef, final RaftRPC rpc) {
super.assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(actorContext, actorRef, rpc);
String expVotedFor = rpc instanceof RequestVote ? ((RequestVote)rpc).getCandidateId() : null;
}
@Override
- protected void handleAppendEntriesAddSameEntryToLogReply(final TestActorRef<MessageCollectorActor> replyActor)
- throws Exception {
+ protected void handleAppendEntriesAddSameEntryToLogReply(final TestActorRef<MessageCollectorActor> replyActor) {
AppendEntriesReply reply = MessageCollectorActor.expectFirstMatching(replyActor, AppendEntriesReply.class);
assertEquals("isSuccess", true, reply.isSuccess());
}