Search in sources :

Example 21 with WriteRequest

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());
}
Also used : Response(com.alibaba.nacos.consistency.entity.Response) Instance(com.alibaba.nacos.api.naming.pojo.Instance) WriteRequest(com.alibaba.nacos.consistency.entity.WriteRequest) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Test(org.junit.Test)

Aggregations

WriteRequest (com.alibaba.nacos.consistency.entity.WriteRequest)21 NacosException (com.alibaba.nacos.api.exception.NacosException)7 Test (org.junit.Test)7 Response (com.alibaba.nacos.consistency.entity.Response)5 ByteString (com.google.protobuf.ByteString)5 NacosRuntimeException (com.alibaba.nacos.api.exception.runtime.NacosRuntimeException)3 RequestProcessor4CP (com.alibaba.nacos.consistency.cp.RequestProcessor4CP)3 ReadRequest (com.alibaba.nacos.consistency.entity.ReadRequest)3 Field (java.lang.reflect.Field)3 NotifyCenter (com.alibaba.nacos.common.notify.NotifyCenter)2 ExceptionUtil (com.alibaba.nacos.common.utils.ExceptionUtil)2 JacksonUtils (com.alibaba.nacos.common.utils.JacksonUtils)2 LoggerUtils (com.alibaba.nacos.common.utils.LoggerUtils)2 Serializer (com.alibaba.nacos.consistency.Serializer)2 Log (com.alibaba.nacos.consistency.entity.Log)2 ConsistencyException (com.alibaba.nacos.consistency.exception.ConsistencyException)2 SnapshotOperation (com.alibaba.nacos.consistency.snapshot.SnapshotOperation)2 Datum (com.alibaba.nacos.naming.consistency.Datum)2 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)2 ByteBuffer (java.nio.ByteBuffer)2