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));
}
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());
}
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);
}
Aggregations