use of com.alipay.sofa.jraft.Status in project sofa-jraft by sofastack.
the class ReplicatorTest method testOnHeartbeatReturnedTermMismatch.
@Test
public void testOnHeartbeatReturnedTermMismatch() {
final Replicator r = getReplicator();
final RpcRequests.AppendEntriesRequest request = createEmptyEntriesRequest();
final RpcRequests.AppendEntriesResponse response = //
RpcRequests.AppendEntriesResponse.newBuilder().setSuccess(//
false).setLastLogIndex(//
12).setTerm(//
2).build();
this.id.unlock();
Replicator.onHeartbeatReturned(this.id, Status.OK(), request, response, Utils.monotonicMs());
Mockito.verify(this.node).increaseTermTo(2, new Status(RaftError.EHIGHERTERMRESPONSE, "Leader receives higher term heartbeat_response from peer:%s", this.peerId));
assertNull(r.id);
}
use of com.alipay.sofa.jraft.Status in project sofa-jraft by sofastack.
the class ReplicatorTest method testOnRpcReturnedWaitMoreEntries.
@Test
public void testOnRpcReturnedWaitMoreEntries() throws Exception {
final Replicator r = getReplicator();
assertEquals(-1, r.getWaitId());
final RpcRequests.AppendEntriesRequest request = createEmptyEntriesRequest();
final RpcRequests.AppendEntriesResponse response = //
RpcRequests.AppendEntriesResponse.newBuilder().setSuccess(//
true).setLastLogIndex(//
10).setTerm(//
1).build();
this.id.unlock();
Mockito.when(this.logManager.wait(eq(10L), Mockito.any(), same(this.id))).thenReturn(99L);
final CountDownLatch latch = new CountDownLatch(1);
Replicator.waitForCaughtUp(this.id, 1, System.currentTimeMillis() + 5000, new CatchUpClosure() {
@Override
public void run(final Status status) {
assertTrue(status.isOk());
latch.countDown();
}
});
Replicator.onRpcReturned(this.id, Replicator.RequestType.AppendEntries, Status.OK(), request, response, 0, 0, Utils.monotonicMs());
assertEquals(r.statInfo.runningState, Replicator.RunningState.IDLE);
this.id.unlock();
assertEquals(11, Replicator.getNextIndex(this.id));
assertEquals(99, r.getWaitId());
// make sure catch up closure is invoked.
latch.await();
}
use of com.alipay.sofa.jraft.Status in project sofa-jraft by sofastack.
the class FSMCallerTest method testOnError.
@Test
public void testOnError() throws Exception {
this.fsmCaller.onError(new RaftException(ErrorType.ERROR_TYPE_LOG, new Status(-1, "test")));
this.fsmCaller.flush();
assertFalse(this.fsmCaller.getError().getStatus().isOk());
assertEquals(ErrorType.ERROR_TYPE_LOG, this.fsmCaller.getError().getType());
Mockito.verify(this.node).onError(Mockito.any());
Mockito.verify(this.fsm).onError(Mockito.any());
}
use of com.alipay.sofa.jraft.Status in project sofa-jraft by sofastack.
the class FSMCallerTest method testOnLeaderStartStop.
@Test
public void testOnLeaderStartStop() throws Exception {
this.fsmCaller.onLeaderStart(11);
this.fsmCaller.flush();
Mockito.verify(this.fsm).onLeaderStart(11);
final Status status = new Status(-1, "test");
this.fsmCaller.onLeaderStop(status);
this.fsmCaller.flush();
Mockito.verify(this.fsm).onLeaderStop(status);
}
use of com.alipay.sofa.jraft.Status in project sofa-jraft by sofastack.
the class FSMCallerTest method testOnSnapshotSaveEmptyConf.
@Test
public void testOnSnapshotSaveEmptyConf() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
this.fsmCaller.onSnapshotSave(new SaveSnapshotClosure() {
@Override
public void run(final Status status) {
assertFalse(status.isOk());
assertEquals("Empty conf entry for lastAppliedIndex=10", status.getErrorMsg());
latch.countDown();
}
@Override
public SnapshotWriter start(final SnapshotMeta meta) {
// TODO Auto-generated method stub
return null;
}
});
latch.await();
}
Aggregations