Search in sources :

Example 6 with DistroDataResponse

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());
}
Also used : DistroDataRequest(com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) DistroDataResponse(com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData) Test(org.junit.Test)

Aggregations

DistroDataResponse (com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse)6 DistroData (com.alibaba.nacos.core.distributed.distro.entity.DistroData)4 DistroDataRequest (com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest)3 NacosException (com.alibaba.nacos.api.exception.NacosException)2 Response (com.alibaba.nacos.api.remote.response.Response)2 Member (com.alibaba.nacos.core.cluster.Member)2 DistroException (com.alibaba.nacos.core.distributed.distro.exception.DistroException)2 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)1 DistroKey (com.alibaba.nacos.core.distributed.distro.entity.DistroKey)1 Test (org.junit.Test)1