use of com.alipay.sofa.jraft.Status in project sofa-jraft by sofastack.
the class FSMCallerTest method testOnSnapshotLoadStale.
@Test
public void testOnSnapshotLoadStale() throws Exception {
final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
final SnapshotMeta meta = SnapshotMeta.newBuilder().setLastIncludedIndex(5).setLastIncludedTerm(1).build();
Mockito.when(reader.load()).thenReturn(meta);
final CountDownLatch latch = new CountDownLatch(1);
this.fsmCaller.onSnapshotLoad(new LoadSnapshotClosure() {
@Override
public void run(final Status status) {
assertFalse(status.isOk());
assertEquals(RaftError.ESTALE, status.getRaftError());
latch.countDown();
}
@Override
public SnapshotReader start() {
return reader;
}
});
latch.await();
assertEquals(this.fsmCaller.getLastAppliedIndex(), 10);
}
use of com.alipay.sofa.jraft.Status in project sofa-jraft by sofastack.
the class FSMCallerTest method testOnSnapshotLoad.
@Test
public void testOnSnapshotLoad() throws Exception {
final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
final SnapshotMeta meta = SnapshotMeta.newBuilder().setLastIncludedIndex(12).setLastIncludedTerm(1).build();
Mockito.when(reader.load()).thenReturn(meta);
Mockito.when(this.fsm.onSnapshotLoad(reader)).thenReturn(true);
final CountDownLatch latch = new CountDownLatch(1);
this.fsmCaller.onSnapshotLoad(new LoadSnapshotClosure() {
@Override
public void run(final Status status) {
assertTrue(status.isOk());
latch.countDown();
}
@Override
public SnapshotReader start() {
return reader;
}
});
latch.await();
assertEquals(this.fsmCaller.getLastAppliedIndex(), 12);
Mockito.verify(this.fsm).onConfigurationCommitted(Mockito.any());
}
use of com.alipay.sofa.jraft.Status in project sofa-jraft by sofastack.
the class IteratorImplTest method testSetErrorAndRollback.
@Test
public void testSetErrorAndRollback() {
testNext();
assertFalse(iter.hasError());
this.iter.setErrorAndRollback(5, new Status(-1, "test"));
assertTrue(iter.hasError());
Assert.assertEquals(EnumOutter.ErrorType.ERROR_TYPE_STATE_MACHINE, iter.getError().getType());
Assert.assertEquals(RaftError.ESTATEMACHINE.getNumber(), iter.getError().getStatus().getCode());
Assert.assertEquals("StateMachine meet critical error when applying one or more tasks since index=6, Status[UNKNOWN<-1>: test]", iter.getError().getStatus().getErrorMsg());
assertEquals(6, iter.getIndex());
}
use of com.alipay.sofa.jraft.Status in project sofa-jraft by sofastack.
the class IteratorImplTest method testRunTheRestClosureWithError.
@Test
public void testRunTheRestClosureWithError() throws Exception {
testSetErrorAndRollback();
for (final Closure closure : this.closures) {
final MockClosure mc = (MockClosure) closure;
assertNull(mc.s);
}
this.iter.runTheRestClosureWithError();
Thread.sleep(500);
int i = 0;
for (final Closure closure : this.closures) {
i++;
final MockClosure mc = (MockClosure) closure;
if (i < 7) {
assertNull(mc.s);
} else {
final Status s = mc.s;
Assert.assertEquals(RaftError.ESTATEMACHINE.getNumber(), s.getCode());
assertEquals("StateMachine meet critical error when applying one or more tasks since index=6, Status[UNKNOWN<-1>: test]", s.getErrorMsg());
}
}
}
use of com.alipay.sofa.jraft.Status in project sofa-jraft by sofastack.
the class BallotBoxTest method testCommitAt.
@Test
public void testCommitAt() {
assertFalse(this.box.commitAt(1, 3, new PeerId("localhost", 8081)));
assertTrue(box.resetPendingIndex(1));
assertTrue(this.box.appendPendingTask(JRaftUtils.getConfiguration("localhost:8081,localhost:8082,localhost:8083"), JRaftUtils.getConfiguration("localhost:8081"), new Closure() {
@Override
public void run(Status status) {
}
}));
assertEquals(0, this.box.getLastCommittedIndex());
try {
this.box.commitAt(1, 3, new PeerId("localhost", 8081));
fail();
} catch (ArrayIndexOutOfBoundsException e) {
}
assertTrue(this.box.commitAt(1, 1, new PeerId("localhost", 8081)));
assertEquals(0, this.box.getLastCommittedIndex());
assertEquals(1, this.box.getPendingIndex());
assertTrue(this.box.commitAt(1, 1, new PeerId("localhost", 8082)));
assertEquals(1, this.box.getLastCommittedIndex());
assertEquals(2, this.box.getPendingIndex());
Mockito.verify(this.waiter, Mockito.only()).onCommitted(1);
}
Aggregations