use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.
the class ConfigChangeBatchListenRequestHandlerTest method setUp.
@Before
public void setUp() {
configQueryRequestHandler = new ConfigChangeBatchListenRequestHandler();
ReflectionTestUtils.setField(configQueryRequestHandler, "configChangeListenContext", configChangeListenContext);
requestMeta = new RequestMeta();
requestMeta.setClientIp("1.1.1.1");
Mockito.mockStatic(ConfigCacheService.class);
}
use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.
the class ConfigRemoveRequestHandlerTest method testHandle.
@Test
public void testHandle() {
ConfigRemoveRequest configRemoveRequest = new ConfigRemoveRequest();
configRemoveRequest.setRequestId("requestId");
configRemoveRequest.setGroup("group");
configRemoveRequest.setDataId("dataId");
configRemoveRequest.setTenant("tenant");
RequestMeta meta = new RequestMeta();
meta.setClientIp("1.1.1.1");
try {
ConfigRemoveResponse configRemoveResponse = configRemoveRequestHandler.handle(configRemoveRequest, meta);
Assert.assertEquals(ResponseCode.SUCCESS.getCode(), configRemoveResponse.getResultCode());
} catch (NacosException e) {
e.printStackTrace();
}
}
use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.
the class InternalConfigChangeNotifier method loadLocalConfigLikeClient.
private String loadLocalConfigLikeClient(String dataId, String group) throws NacosException {
ConfigQueryRequest queryRequest = new ConfigQueryRequest();
queryRequest.setDataId(dataId);
queryRequest.setGroup(group);
RequestMeta meta = new RequestMeta();
meta.setClientIp(NetUtils.localIP());
ConfigQueryResponse handle = configQueryRequestHandler.handle(queryRequest, meta);
if (handle == null) {
throw new NacosException(NacosException.SERVER_ERROR, "load local config fail,response is null");
}
if (handle.isSuccess()) {
return handle.getContent();
} else if (handle.getErrorCode() == ConfigQueryResponse.CONFIG_NOT_FOUND) {
return null;
} else {
Loggers.REMOTE.error("connection limit rule load fail,errorCode={}", handle.getErrorCode());
throw new NacosException(NacosException.SERVER_ERROR, "load local config fail,error code=" + handle.getErrorCode());
}
}
use of com.alibaba.nacos.api.remote.request.RequestMeta 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);
}
use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.
the class GrpcRequestAcceptorTest method testConnectionNotRegister.
@Test
public void testConnectionNotRegister() {
ApplicationUtils.setStarted(true);
Mockito.when(requestHandlerRegistry.getByRequestType(Mockito.anyString())).thenReturn(mockHandler);
Mockito.when(connectionManager.checkValid(Mockito.any())).thenReturn(false);
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.UN_REGISTER);
}
@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);
}
Aggregations