use of com.alibaba.nacos.api.naming.remote.request.InstanceRequest in project nacos by alibaba.
the class InstanceRequestHandlerTest method testHandle.
@Test
public void testHandle() throws NacosException {
InstanceRequest instanceRequest = new InstanceRequest();
instanceRequest.setType(NamingRemoteConstants.REGISTER_INSTANCE);
Instance instance = new Instance();
instanceRequest.setInstance(instance);
RequestMeta requestMeta = new RequestMeta();
instanceRequestHandler.handle(instanceRequest, requestMeta);
Mockito.verify(clientOperationService).registerInstance(Mockito.any(), Mockito.any(), Mockito.anyString());
instanceRequest.setType(NamingRemoteConstants.DE_REGISTER_INSTANCE);
instanceRequestHandler.handle(instanceRequest, requestMeta);
Mockito.verify(clientOperationService).deregisterInstance(Mockito.any(), Mockito.any(), Mockito.anyString());
instanceRequest.setType("xxx");
try {
instanceRequestHandler.handle(instanceRequest, requestMeta);
} catch (Exception e) {
Assert.assertEquals(((NacosException) e).getErrCode(), NacosException.INVALID_PARAM);
}
}
use of com.alibaba.nacos.api.naming.remote.request.InstanceRequest in project nacos by alibaba.
the class NamingGrpcClientProxy method doDeregisterService.
/**
* Execute deregister operation.
*
* @param serviceName service name
* @param groupName group name
* @param instance instance
* @throws NacosException nacos exception
*/
public void doDeregisterService(String serviceName, String groupName, Instance instance) throws NacosException {
InstanceRequest request = new InstanceRequest(namespaceId, serviceName, groupName, NamingRemoteConstants.DE_REGISTER_INSTANCE, instance);
requestToServer(request, Response.class);
redoService.removeInstanceForRedo(serviceName, groupName);
}
use of com.alibaba.nacos.api.naming.remote.request.InstanceRequest in project nacos by alibaba.
the class GrpcRequestAcceptorTest method testNoRequestHandler.
@Test
public void testNoRequestHandler() {
ApplicationUtils.setStarted(true);
RequestMeta metadata = new RequestMeta();
metadata.setClientIp("127.0.0.1");
metadata.setConnectionId(connectId);
InstanceRequest instanceRequest = new InstanceRequest();
instanceRequest.setRequestId(requestId);
Payload request = GrpcUtils.convert(instanceRequest, 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.NO_HANDLER);
}
@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.naming.remote.request.InstanceRequest in project nacos by alibaba.
the class NamingGrpcClientProxy method doRegisterService.
/**
* Execute register operation.
*
* @param serviceName name of service
* @param groupName group of service
* @param instance instance to register
* @throws NacosException nacos exception
*/
public void doRegisterService(String serviceName, String groupName, Instance instance) throws NacosException {
InstanceRequest request = new InstanceRequest(namespaceId, serviceName, groupName, NamingRemoteConstants.REGISTER_INSTANCE, instance);
requestToServer(request, Response.class);
redoService.instanceRegistered(serviceName, groupName);
}
use of com.alibaba.nacos.api.naming.remote.request.InstanceRequest in project nacos by alibaba.
the class GrpcRequestAcceptorTest method testHandleRequestError.
@Test
public void testHandleRequestError() {
ApplicationUtils.setStarted(true);
Mockito.when(requestHandlerRegistry.getByRequestType(Mockito.anyString())).thenReturn(mockHandler);
Mockito.when(connectionManager.checkValid(Mockito.any())).thenReturn(true);
RequestMeta metadata = new RequestMeta();
metadata.setClientIp("127.0.0.1");
metadata.setConnectionId(connectId);
InstanceRequest instanceRequest = new InstanceRequest();
Payload payload = GrpcUtils.convert(instanceRequest, 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.SERVER_ERROR);
}
@Override
public void onError(Throwable throwable) {
Assert.fail(throwable.getMessage());
}
@Override
public void onCompleted() {
System.out.println("complete");
}
};
streamStub.request(payload, streamObserver);
ApplicationUtils.setStarted(false);
}
Aggregations