use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.
the class GrpcBiStreamRequestAcceptorTest method testConnectionSetupRequest.
@Test
public void testConnectionSetupRequest() {
StreamObserver<Payload> streamObserver = new StreamObserver<Payload>() {
@Override
public void onNext(Payload payload) {
System.out.println("Receive data from server, data: " + payload);
Assert.assertNotNull(payload);
ConnectResetRequest connectResetRequest = (ConnectResetRequest) GrpcUtils.parse(payload);
Response response = new ConnectResetResponse();
response.setRequestId(connectResetRequest.getRequestId());
Payload res = GrpcUtils.convert(response);
payloadStreamObserver.onNext(res);
payloadStreamObserver.onCompleted();
}
@Override
public void onError(Throwable throwable) {
Assert.fail(throwable.getMessage());
}
@Override
public void onCompleted() {
System.out.println("complete");
}
};
payloadStreamObserver = streamStub.requestBiStream(streamObserver);
RequestMeta metadata = new RequestMeta();
metadata.setClientIp("127.0.0.1");
metadata.setConnectionId(connectId);
ConnectionSetupRequest connectionSetupRequest = new ConnectionSetupRequest();
connectionSetupRequest.setRequestId(requestId);
connectionSetupRequest.setClientVersion("2.0.3");
Payload payload = GrpcUtils.convert(connectionSetupRequest, metadata);
payloadStreamObserver.onNext(payload);
}
use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.
the class GrpcRequestFilterTest method testFilter.
@Test
public void testFilter() throws NacosException {
Mockito.when(upgradeJudgement.isUseGrpcFeatures()).thenReturn(true).thenReturn(false);
Response response = grpcRequestFilter.filter(new InstanceRequest(), new RequestMeta(), InstanceRequestHandler.class);
Assert.assertNull(response);
try {
grpcRequestFilter.filter(new InstanceRequest(), new RequestMeta(), InstanceRequestHandler.class);
} catch (Exception e) {
Assert.assertTrue(e instanceof NacosException);
}
}
use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.
the class DistroDataRequestHandlerTest method testHandle.
@Test
public void testHandle() throws NacosException {
Mockito.when(distroProtocol.onVerify(Mockito.any(), Mockito.anyString())).thenReturn(false);
DistroDataRequest distroDataRequest = new DistroDataRequest();
distroDataRequest.setDataOperation(VERIFY);
RequestMeta requestMeta = new RequestMeta();
DistroDataResponse response = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
Assert.assertEquals(response.getErrorCode(), ResponseCode.FAIL.getCode());
DistroData distroData = new DistroData();
Mockito.when(distroProtocol.onSnapshot(Mockito.any())).thenReturn(distroData);
distroDataRequest.setDataOperation(SNAPSHOT);
DistroDataResponse response1 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
Assert.assertEquals(response1.getDistroData(), distroData);
distroDataRequest.setDataOperation(DELETE);
Mockito.when(distroProtocol.onReceive(Mockito.any())).thenReturn(false);
DistroDataResponse response2 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
Assert.assertEquals(response2.getErrorCode(), ResponseCode.FAIL.getCode());
distroDataRequest.setDataOperation(QUERY);
Mockito.when(distroProtocol.onQuery(Mockito.any())).thenReturn(distroData);
distroDataRequest.setDistroData(new DistroData());
DistroDataResponse response3 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
Assert.assertEquals(response3.getDistroData(), distroData);
distroDataRequest.setDataOperation(ADD);
DistroDataResponse response4 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
Assert.assertNull(response4.getDistroData());
}
use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.
the class ServiceListRequestHandlerTest method testHandle.
@Test
public void testHandle() throws NacosException {
ServiceListRequest serviceListRequest = new ServiceListRequest();
serviceListRequest.setNamespace("A");
serviceListRequest.setPageNo(1);
serviceListRequest.setPageSize(10);
serviceListRequest.setGroupName("B");
ServiceListRequestHandler serviceListRequestHandler = new ServiceListRequestHandler();
ServiceListResponse serviceListResponse = serviceListRequestHandler.handle(serviceListRequest, new RequestMeta());
Assert.assertEquals(serviceListResponse.getCount(), 1);
Assert.assertTrue(serviceListResponse.getServiceNames().contains("C"));
}
use of com.alibaba.nacos.api.remote.request.RequestMeta in project nacos by alibaba.
the class ServiceQueryRequestHandlerTest method testHandle.
@Test
public void testHandle() throws NacosException {
Instance instance = new Instance();
instance.setIp("1.1.1.1");
List<Instance> instances = Arrays.asList(instance);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setGroupName("A");
serviceInfo.setGroupName("B");
serviceInfo.setName("C");
serviceInfo.setHosts(instances);
Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
ServiceMetadata serviceMetadata = new ServiceMetadata();
Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(serviceMetadata));
ServiceQueryRequest serviceQueryRequest = new ServiceQueryRequest();
serviceQueryRequest.setNamespace("A");
serviceQueryRequest.setGroupName("B");
serviceQueryRequest.setServiceName("C");
serviceQueryRequest.setHealthyOnly(false);
QueryServiceResponse queryServiceResponse = serviceQueryRequestHandler.handle(serviceQueryRequest, new RequestMeta());
Assert.assertEquals(queryServiceResponse.getServiceInfo().getName(), "C");
}
Aggregations