use of org.apache.ignite.raft.jraft.rpc.RpcRequests.ReadIndexRequest in project ignite-3 by apache.
the class ReadOnlyServiceTest method testAddRequestOnResponseSuccess.
@Test
public void testAddRequestOnResponseSuccess() throws Exception {
Mockito.when(this.fsmCaller.getLastAppliedIndex()).thenReturn(2L);
final byte[] requestContext = TestUtils.getRandomBytes();
final CountDownLatch latch = new CountDownLatch(1);
this.readOnlyServiceImpl.addRequest(requestContext, new ReadIndexClosure() {
@Override
public void run(final Status status, final long index, final byte[] reqCtx) {
assertTrue(status.isOk());
assertEquals(index, 1);
assertArrayEquals(reqCtx, requestContext);
latch.countDown();
}
});
this.readOnlyServiceImpl.flush();
final ArgumentCaptor<RpcResponseClosure> closureCaptor = ArgumentCaptor.forClass(RpcResponseClosure.class);
Mockito.verify(this.node).handleReadIndexRequest(Mockito.argThat(new ArgumentMatcher<ReadIndexRequest>() {
@Override
public boolean matches(ReadIndexRequest argument) {
if (argument != null) {
final ReadIndexRequest req = (ReadIndexRequest) argument;
return "test".equals(req.groupId()) && "localhost:8081:0".equals(req.serverId()) && Utils.size(req.entriesList()) == 1 && Arrays.equals(requestContext, req.entriesList().get(0).toByteArray());
}
return false;
}
}), closureCaptor.capture());
final RpcResponseClosure closure = closureCaptor.getValue();
assertNotNull(closure);
closure.setResponse(msgFactory.readIndexResponse().index(1).success(true).build());
closure.run(Status.OK());
latch.await();
}
Aggregations