use of com.alibaba.nacos.api.remote.request.ServerCheckRequest in project nacos by alibaba.
the class GrpcRequestAcceptorTest method testApplicationUnStarted.
@Test
public void testApplicationUnStarted() {
RequestMeta metadata = new RequestMeta();
metadata.setClientIp("127.0.0.1");
metadata.setConnectionId(connectId);
ServerCheckRequest serverCheckRequest = new ServerCheckRequest();
serverCheckRequest.setRequestId(requestId);
Payload request = GrpcUtils.convert(serverCheckRequest, metadata);
StreamObserver<Payload> streamObserver = new StreamObserver<Payload>() {
@Override
public void onNext(Payload payload) {
System.out.println("Receive data from server: " + payload);
Object res = GrpcUtils.parse(payload);
Assert.assertTrue(res instanceof ErrorResponse);
ErrorResponse errorResponse = (ErrorResponse) res;
Assert.assertEquals(errorResponse.getErrorCode(), NacosException.INVALID_SERVER_STATUS);
}
@Override
public void onError(Throwable throwable) {
Assert.fail(throwable.getMessage());
}
@Override
public void onCompleted() {
System.out.println("complete");
}
};
streamStub.request(request, streamObserver);
}
use of com.alibaba.nacos.api.remote.request.ServerCheckRequest in project nacos by alibaba.
the class GrpcRequestAcceptorTest method testServerCheckRequest.
@Test
public void testServerCheckRequest() {
ApplicationUtils.setStarted(true);
RequestMeta metadata = new RequestMeta();
metadata.setClientIp("127.0.0.1");
metadata.setConnectionId(connectId);
ServerCheckRequest serverCheckRequest = new ServerCheckRequest();
serverCheckRequest.setRequestId(requestId);
Payload request = GrpcUtils.convert(serverCheckRequest, metadata);
StreamObserver<Payload> streamObserver = new StreamObserver<Payload>() {
@Override
public void onNext(Payload payload) {
System.out.println("Receive data from server: " + payload);
Object res = GrpcUtils.parse(payload);
Assert.assertTrue(res instanceof ServerCheckResponse);
}
@Override
public void onError(Throwable throwable) {
Assert.fail(throwable.getMessage());
}
@Override
public void onCompleted() {
System.out.println("complete");
}
};
streamStub.request(request, streamObserver);
ApplicationUtils.setStarted(false);
}
use of com.alibaba.nacos.api.remote.request.ServerCheckRequest in project nacos by alibaba.
the class GrpcClient method serverCheck.
/**
* check server if success.
*
* @param requestBlockingStub requestBlockingStub used to check server.
* @return success or not
*/
private Response serverCheck(String ip, int port, RequestGrpc.RequestFutureStub requestBlockingStub) {
try {
if (requestBlockingStub == null) {
return null;
}
ServerCheckRequest serverCheckRequest = new ServerCheckRequest();
Payload grpcRequest = GrpcUtils.convert(serverCheckRequest);
ListenableFuture<Payload> responseFuture = requestBlockingStub.request(grpcRequest);
Payload response = responseFuture.get(3000L, TimeUnit.MILLISECONDS);
// receive connection unregister response here,not check response is success.
return (Response) GrpcUtils.parse(response);
} catch (Exception e) {
LoggerUtils.printIfErrorEnabled(LOGGER, "Server check fail, please check server {} ,port {} is available , error ={}", ip, port, e);
return null;
}
}
Aggregations