Search in sources :

Example 6 with RemotingException

use of com.alipay.sofa.jraft.error.RemotingException in project sofa-jraft by sofastack.

the class AbstractClientServiceTest method testConnectException.

@Test
public void testConnectException() throws Exception {
    Mockito.when(this.rpcClient.invokeSync(eq(this.endpoint), Mockito.any(), // 
    eq((long) this.rpcOptions.getRpcConnectTimeoutMs()))).thenThrow(new RemotingException("test"));
    assertFalse(this.clientService.connect(this.endpoint));
}
Also used : RemotingException(com.alipay.sofa.jraft.error.RemotingException) Test(org.junit.Test)

Example 7 with RemotingException

use of com.alipay.sofa.jraft.error.RemotingException in project sofa-jraft by sofastack.

the class AbstractClientServiceTest method testInvokeWithDoneException.

@Test
public void testInvokeWithDoneException() throws Exception {
    InvokeContext invokeCtx = new InvokeContext();
    invokeCtx.put(InvokeContext.CRC_SWITCH, false);
    ArgumentCaptor<InvokeCallback> callbackArg = ArgumentCaptor.forClass(InvokeCallback.class);
    PingRequest request = TestUtils.createPingRequest();
    Mockito.doThrow(new RemotingException()).when(this.rpcClient).invokeAsync(eq(this.endpoint), eq(request), eq(invokeCtx), callbackArg.capture(), eq((long) this.rpcOptions.getRpcDefaultTimeout()));
    MockRpcResponseClosure<ErrorResponse> done = new MockRpcResponseClosure<>();
    Future<Message> future = this.clientService.invokeWithDone(this.endpoint, request, invokeCtx, done, -1);
    InvokeCallback cb = callbackArg.getValue();
    assertNotNull(cb);
    assertNotNull(future);
    assertTrue(future.isDone());
    try {
        future.get();
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof RemotingException);
    }
    done.latch.await();
    assertNotNull(done.status);
    assertEquals(RaftError.EINTERNAL.getNumber(), done.status.getCode());
}
Also used : PingRequest(com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest) Message(com.google.protobuf.Message) RemotingException(com.alipay.sofa.jraft.error.RemotingException) ExecutionException(java.util.concurrent.ExecutionException) ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 8 with RemotingException

use of com.alipay.sofa.jraft.error.RemotingException in project jdchain-core by blockchain-jd-com.

the class RaftMessageService method sendRequest.

private void sendRequest(Endpoint endpoint, SubmitTxRequest txRequest, int retry, CompletableAsyncFuture<byte[]> asyncFuture) throws RemotingException, InterruptedException {
    if (retry >= MAX_RETRY_TIMES) {
        asyncFuture.error(new RuntimeException("raft client send request exceed max retries"));
        return;
    }
    if (endpoint == null) {
        asyncFuture.error(new RuntimeException("raft client send request find leader endpoint is null"));
        return;
    }
    clientService.getRpcClient().invokeAsync(endpoint, txRequest, (o, throwable) -> {
        LoggerUtils.debugIfEnabled(LOGGER, "raft client send request: {} response: {} throwable: {}", txRequest, o, throwable);
        if (throwable != null) {
            LOGGER.error("raft client send request error, request: {}", txRequest, throwable);
            asyncFuture.error(throwable);
            return;
        }
        RpcResponse response = (RpcResponse) o;
        if (response.isRedirect()) {
            LoggerUtils.debugIfEnabled(LOGGER, "request should redirect to leader. current peer: {} , redirect leader: {}", endpoint, response.getLeaderEndpoint());
            try {
                sendRequest(JRaftUtils.getEndPoint(response.getLeaderEndpoint()), txRequest, retry + 1, asyncFuture);
            } catch (Exception e) {
                throw new RaftClientRequestException(e);
            }
            return;
        }
        if (response.isSuccess()) {
            asyncFuture.complete(response.getResult());
        } else {
            asyncFuture.complete(null);
        }
    }, rpcTimeoutMs);
}
Also used : RpcResponse(com.jd.blockchain.consensus.raft.rpc.RpcResponse) RemotingException(com.alipay.sofa.jraft.error.RemotingException)

Aggregations

RemotingException (com.alipay.sofa.jraft.error.RemotingException)8 Message (com.google.protobuf.Message)4 ErrorResponse (com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse)3 Status (com.alipay.sofa.jraft.Status)2 InvokeTimeoutException (com.alipay.sofa.jraft.error.InvokeTimeoutException)2 RpcClient (com.alipay.sofa.jraft.rpc.RpcClient)2 PingRequest (com.alipay.sofa.jraft.rpc.RpcRequests.PingRequest)2 Executor (java.util.concurrent.Executor)2 Test (org.junit.Test)2 InvokeCallback (com.alipay.sofa.jraft.rpc.InvokeCallback)1 FutureImpl (com.alipay.sofa.jraft.rpc.impl.FutureImpl)1 DirectExecutor (com.alipay.sofa.jraft.util.DirectExecutor)1 Descriptors (com.google.protobuf.Descriptors)1 RpcResponse (com.jd.blockchain.consensus.raft.rpc.RpcResponse)1 CallOptions (io.grpc.CallOptions)1 Channel (io.grpc.Channel)1 ManagedChannel (io.grpc.ManagedChannel)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1