Search in sources :

Example 6 with ReadIndexRequest

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();
}
Also used : Status(org.apache.ignite.raft.jraft.Status) ReadIndexStatus(org.apache.ignite.raft.jraft.entity.ReadIndexStatus) ReadIndexRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.ReadIndexRequest) ReadIndexClosure(org.apache.ignite.raft.jraft.closure.ReadIndexClosure) ArgumentMatcher(org.mockito.ArgumentMatcher) RpcResponseClosure(org.apache.ignite.raft.jraft.rpc.RpcResponseClosure) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

ReadIndexRequest (org.apache.ignite.raft.jraft.rpc.RpcRequests.ReadIndexRequest)6 Status (org.apache.ignite.raft.jraft.Status)5 ReadIndexClosure (org.apache.ignite.raft.jraft.closure.ReadIndexClosure)4 ReadIndexStatus (org.apache.ignite.raft.jraft.entity.ReadIndexStatus)4 Test (org.junit.jupiter.api.Test)4 ArgumentMatcher (org.mockito.ArgumentMatcher)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 RpcResponseClosure (org.apache.ignite.raft.jraft.rpc.RpcResponseClosure)3 ArrayList (java.util.ArrayList)1 ReadIndexState (org.apache.ignite.raft.jraft.entity.ReadIndexState)1 ReadIndexRequestBuilder (org.apache.ignite.raft.jraft.rpc.ReadIndexRequestBuilder)1 ByteString (org.apache.ignite.raft.jraft.util.ByteString)1