use of com.alipay.sofa.jraft.Closure in project sofa-jraft by sofastack.
the class AddPeerRequestProcessorTest method verify.
@Override
public void verify(String interest, Node node, ArgumentCaptor<Closure> doneArg) {
assertEquals(interest, AddPeerRequest.class.getName());
Mockito.verify(node).addPeer(eq(new PeerId("test", 8181)), doneArg.capture());
Closure done = doneArg.getValue();
assertNotNull(done);
done.run(Status.OK());
assertNotNull(this.asyncContext.getResponseObject());
assertEquals("[localhost:8081, localhost:8082, localhost:8083]", this.asyncContext.as(AddPeerResponse.class).getOldPeersList().toString());
assertEquals("[localhost:8081, localhost:8082, localhost:8083, test:8181]", this.asyncContext.as(AddPeerResponse.class).getNewPeersList().toString());
}
use of com.alipay.sofa.jraft.Closure in project sofa-jraft by sofastack.
the class RemoveLearnersRequestProcessorTest method verify.
@Override
public void verify(final String interest, final Node node, final ArgumentCaptor<Closure> doneArg) {
assertEquals(interest, RemoveLearnersRequest.class.getName());
Mockito.verify(node).removeLearners(eq(Arrays.asList(new PeerId("learner", 8082), new PeerId("test", 8183))), doneArg.capture());
Closure done = doneArg.getValue();
assertNotNull(done);
done.run(Status.OK());
assertNotNull(this.asyncContext.getResponseObject());
assertEquals("[learner:8081, learner:8082, learner:8083]", this.asyncContext.as(LearnersOpResponse.class).getOldLearnersList().toString());
assertEquals("[learner:8081, learner:8083]", this.asyncContext.as(LearnersOpResponse.class).getNewLearnersList().toString());
}
use of com.alipay.sofa.jraft.Closure in project sofa-jraft by sofastack.
the class RemovePeerRequestProcessorTest method verify.
@Override
public void verify(String interest, Node node, ArgumentCaptor<Closure> doneArg) {
assertEquals(interest, RemovePeerRequest.class.getName());
Mockito.verify(node).removePeer(eq(new PeerId("localhost", 8082)), doneArg.capture());
Closure done = doneArg.getValue();
assertNotNull(done);
done.run(Status.OK());
assertNotNull(this.asyncContext.getResponseObject());
assertEquals("[localhost:8081, localhost:8082, localhost:8083]", this.asyncContext.as(RemovePeerResponse.class).getOldPeersList().toString());
assertEquals("[localhost:8081, localhost:8083]", this.asyncContext.as(RemovePeerResponse.class).getNewPeersList().toString());
}
use of com.alipay.sofa.jraft.Closure 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.Closure 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