use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class PersistentClientOperationServiceImplTest method testOnApply.
@Test
public void testOnApply() {
PersistentClientOperationServiceImpl.InstanceStoreRequest request = new PersistentClientOperationServiceImpl.InstanceStoreRequest();
Service service1 = Service.newService("A", "B", "C");
request.setService(service1);
request.setClientId("xxxx");
request.setInstance(new Instance());
Mockito.when(serializer.deserialize(Mockito.any())).thenReturn(request);
Mockito.when(clientManager.contains(Mockito.anyString())).thenReturn(true);
IpPortBasedClient ipPortBasedClient = Mockito.mock(IpPortBasedClient.class);
Mockito.when(clientManager.getClient(Mockito.anyString())).thenReturn(ipPortBasedClient);
WriteRequest writeRequest = WriteRequest.newBuilder().setOperation(DataOperation.ADD.name()).build();
Response response = persistentClientOperationServiceImpl.onApply(writeRequest);
Assert.assertTrue(response.getSuccess());
writeRequest = WriteRequest.newBuilder().setOperation(DataOperation.DELETE.name()).build();
response = persistentClientOperationServiceImpl.onApply(writeRequest);
Assert.assertTrue(response.getSuccess());
ServiceManager.getInstance().removeSingleton(service1);
writeRequest = WriteRequest.newBuilder().setOperation(DataOperation.VERIFY.name()).build();
response = persistentClientOperationServiceImpl.onApply(writeRequest);
Assert.assertFalse(response.getSuccess());
}
Aggregations