use of com.alibaba.nacos.api.remote.response.Response in project nacos by alibaba.
the class ClusterRpcClientProxyTest method testAsyncRequest.
@Test
public void testAsyncRequest() {
RequestCallBack requestCallBack = new RequestCallBack() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public long getTimeout() {
return 0;
}
@Override
public void onResponse(Response response) {
}
@Override
public void onException(Throwable e) {
Assert.assertTrue(e instanceof NacosException);
}
};
Member member = new Member();
member.setIp("1.1.1.1");
try {
clusterRpcClientProxy.asyncRequest(member, new HealthCheckRequest(), requestCallBack);
} catch (NacosException e) {
Assert.assertEquals(500, e.getErrCode());
}
}
use of com.alibaba.nacos.api.remote.response.Response in project nacos by alibaba.
the class RemoteRequestAuthFilterTest method testFilter.
@Test
public void testFilter() {
Mockito.when(authConfigs.isAuthEnabled()).thenReturn(true);
Request healthCheckRequest = new HealthCheckRequest();
try {
Response healthCheckResponse = remoteRequestAuthFilter.filter(healthCheckRequest, new RequestMeta(), MockRequestHandler.class);
Assert.assertNull(healthCheckResponse);
} catch (NacosException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.alibaba.nacos.api.remote.response.Response in project nacos by alibaba.
the class NamingGrpcClientProxy method requestToServer.
private <T extends Response> T requestToServer(AbstractNamingRequest request, Class<T> responseClass) throws NacosException {
try {
request.putAllHeader(getSecurityHeaders(request.getNamespace(), request.getGroupName(), request.getServiceName()));
Response response = requestTimeout < 0 ? rpcClient.request(request) : rpcClient.request(request, requestTimeout);
if (ResponseCode.SUCCESS.getCode() != response.getResultCode()) {
throw new NacosException(response.getErrorCode(), response.getMessage());
}
if (responseClass.isAssignableFrom(response.getClass())) {
return (T) response;
}
NAMING_LOGGER.error("Server return unexpected response '{}', expected response should be '{}'", response.getClass().getName(), responseClass.getName());
} catch (Exception e) {
throw new NacosException(NacosException.SERVER_ERROR, "Request nacos server failed: ", e);
}
throw new NacosException(NacosException.SERVER_ERROR, "Server return invalid response");
}
use of com.alibaba.nacos.api.remote.response.Response in project nacos by alibaba.
the class NamingPushRequestHandlerTest method testRequestReply.
@Test
public void testRequestReply() {
// given
ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
NamingPushRequestHandler handler = new NamingPushRequestHandler(holder);
ServiceInfo info = new ServiceInfo("name", "cluster1");
Request req = NotifySubscriberRequest.buildNotifySubscriberRequest(info);
// when
Response response = handler.requestReply(req);
// then
Assert.assertTrue(response instanceof NotifySubscriberResponse);
verify(holder, times(1)).processServiceInfo(info);
}
use of com.alibaba.nacos.api.remote.response.Response in project nacos by alibaba.
the class RequestLogAspect method interfaceListenConfigRpc.
/**
* GetConfig.
*/
@Around(CLIENT_INTERFACE_LISTEN_CONFIG_RPC)
public Object interfaceListenConfigRpc(ProceedingJoinPoint pjp, ConfigBatchListenRequest request, RequestMeta meta) throws Throwable {
MetricsMonitor.getConfigMonitor().incrementAndGet();
final String requestIp = meta.getClientIp();
String appName = request.getHeader(RequestUtil.CLIENT_APPNAME_HEADER);
final long st = System.currentTimeMillis();
Response retVal = (Response) pjp.proceed();
final long rt = System.currentTimeMillis() - st;
// rt | status | requestIp | opType | listen size | listen or cancel | empty | empty |
// appName
LogUtil.CLIENT_LOG.info("{}|{}|{}|{}|{}|{}|{}|{}|{}", rt, retVal.isSuccess() ? retVal.getResultCode() : retVal.getErrorCode(), requestIp, "listen", request.getConfigListenContexts().size(), request.isListen(), "", "", appName);
return retVal;
}
Aggregations