use of com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse 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());
}
Aggregations