@Test public void testErrorThroughRpc() { final AtomicReference<Response> reference = new AtomicReference<>(); RpcContext context = new RpcContext() { @Override public void sendResponse(Object responseObj) { reference.set((Response) responseObj); } @Override public Connection getConnection() { return null; } @Override public String getRemoteAddress() { return null; } }; AbstractProcessor processor = new NacosLogProcessor(server, SerializeFactory.getDefault()); processor.execute(server, context, Log.newBuilder().build(), new JRaftServer.RaftGroupTuple()); Response response = reference.get(); Assert.assertNotNull(response); Assert.assertEquals("Error message transmission", response.getErrMsg()); Assert.assertFalse(response.getSuccess()); }
protected void execute(JRaftServer server, final RpcContext asyncCtx, final Message log, final JRaftServer.RaftGroupTuple tuple) { FailoverClosure closure = new FailoverClosure() { Response data; Throwable ex; @Override public void setResponse(Response data) { this.data = data; } @Override public void setThrowable(Throwable throwable) { this.ex = throwable; } @Override public void run(Status status) { if (Objects.nonNull(ex)) { Loggers.RAFT.error("execute has error : {}", ex); asyncCtx.sendResponse(Response.newBuilder().setErrMsg(ex.toString()).setSuccess(false).build()); } else { asyncCtx.sendResponse(data); } } }; server.applyOperation(tuple.getNode(), log, closure); }
AbstractProcessor { protected void execute(JRaftServer server, final RpcContext asyncCtx, final Message log, final JRaftServer.RaftGroupTuple tuple) { FailoverClosure closure = new FailoverClosure() { Response data; Throwable ex; @Override public void setResponse(Response data) { this.data = data; } @Override public void setThrowable(Throwable throwable) { this.ex = throwable; } @Override public void run(Status status) { if (Objects.nonNull(ex)) { Loggers.RAFT.error("execute has error : {}", ex); asyncCtx.sendResponse(Response.newBuilder().setErrMsg(ex.toString()).setSuccess(false).build()); } else { asyncCtx.sendResponse(data); } } }; server.applyOperation(tuple.getNode(), log, closure); } }
AbstractProcessor { protected void execute(JRaftServer server, final RpcContext asyncCtx, final Message log, final JRaftServer.RaftGroupTuple tuple) { FailoverClosure closure = new FailoverClosure() { Response data; Throwable ex; @Override public void setResponse(Response data) { this.data = data; } @Override public void setThrowable(Throwable throwable) { this.ex = throwable; } @Override public void run(Status status) { if (Objects.nonNull(ex)) { Loggers.RAFT.error("execute has error : {}", ex); asyncCtx.sendResponse(Response.newBuilder().setErrMsg(ex.toString()).setSuccess(false).build()); } else { asyncCtx.sendResponse(data); } } }; server.applyOperation(tuple.getNode(), log, closure); } AbstractProcessor(Serializer serializer); }
AbstractProcessor { protected void execute(JRaftServer server, final RpcContext asyncCtx, final Message log, final JRaftServer.RaftGroupTuple tuple) { FailoverClosure closure = new FailoverClosure() { Response data; Throwable ex; @Override public void setResponse(Response data) { this.data = data; } @Override public void setThrowable(Throwable throwable) { this.ex = throwable; } @Override public void run(Status status) { if (Objects.nonNull(ex)) { Loggers.RAFT.error("execute has error : {}", ex); asyncCtx.sendResponse(Response.newBuilder().setErrMsg(ex.toString()).setSuccess(false).build()); } else { asyncCtx.sendResponse(data); } } }; server.applyOperation(tuple.getNode(), log, closure); } AbstractProcessor(Serializer serializer);  }
AbstractProcessor { protected void execute(JRaftServer server, final RpcContext asyncCtx, final Message log, final JRaftServer.RaftGroupTuple tuple) { FailoverClosure closure = new FailoverClosure() { Response data; Throwable ex; @Override public void setResponse(Response data) { this.data = data; } @Override public void setThrowable(Throwable throwable) { this.ex = throwable; } @Override public void run(Status status) { if (Objects.nonNull(ex)) { Loggers.RAFT.error("execute has error : {}", ex); asyncCtx.sendResponse(Response.newBuilder().setErrMsg(ex.toString()).setSuccess(false).build()); } else { asyncCtx.sendResponse(data); } } }; server.applyOperation(tuple.getNode(), log, closure); } AbstractProcessor(Serializer serializer);   }