Search in sources :

Example 11 with WriteRequest

use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.

the class JRaftProtocolTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    raftProtocol = new JRaftProtocol(memberManager);
    ReadRequest.Builder readRequestBuilder = ReadRequest.newBuilder();
    readRequest = readRequestBuilder.build();
    WriteRequest.Builder writeRequestBuilder = WriteRequest.newBuilder();
    writeRequest = writeRequestBuilder.build();
    Field raftServerField = JRaftProtocol.class.getDeclaredField("raftServer");
    raftServerField.setAccessible(true);
    raftServerField.set(raftProtocol, serverMock);
    Field jRaftMaintainServiceField = JRaftProtocol.class.getDeclaredField("jRaftMaintainService");
    jRaftMaintainServiceField.setAccessible(true);
    jRaftMaintainServiceField.set(raftProtocol, jRaftMaintainService);
    when(serverMock.get(readRequest)).thenReturn(futureMock);
    when(serverMock.commit(any(String.class), any(Message.class), any(CompletableFuture.class))).thenReturn(futureMock);
    groupId = "test_group";
    when(serverMock.findNodeByGroup(groupId)).thenReturn(nodeMock);
}
Also used : Field(java.lang.reflect.Field) CompletableFuture(java.util.concurrent.CompletableFuture) Message(com.google.protobuf.Message) WriteRequest(com.alibaba.nacos.consistency.entity.WriteRequest) ReadRequest(com.alibaba.nacos.consistency.entity.ReadRequest) Before(org.junit.Before)

Example 12 with WriteRequest

use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.

the class PersistentServiceProcessor method remove.

@Override
public void remove(String key) throws NacosException {
    final BatchWriteRequest req = new BatchWriteRequest();
    req.append(ByteUtils.toBytes(key), ByteUtils.EMPTY);
    final WriteRequest request = WriteRequest.newBuilder().setData(ByteString.copyFrom(serializer.serialize(req))).setGroup(Constants.NAMING_PERSISTENT_SERVICE_GROUP).setOperation(Op.Delete.desc).build();
    try {
        protocol.write(request);
    } catch (Exception e) {
        throw new NacosException(ErrorCode.ProtoSubmitError.getCode(), e.getMessage());
    }
}
Also used : WriteRequest(com.alibaba.nacos.consistency.entity.WriteRequest) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosException(com.alibaba.nacos.api.exception.NacosException)

Example 13 with WriteRequest

use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.

the class PersistentServiceProcessor method put.

@Override
public void put(String key, Record value) throws NacosException {
    final BatchWriteRequest req = new BatchWriteRequest();
    Datum datum = Datum.createDatum(key, value);
    req.append(ByteUtils.toBytes(key), serializer.serialize(datum));
    final WriteRequest request = WriteRequest.newBuilder().setData(ByteString.copyFrom(serializer.serialize(req))).setGroup(Constants.NAMING_PERSISTENT_SERVICE_GROUP).setOperation(Op.Write.desc).build();
    try {
        protocol.write(request);
    } catch (Exception e) {
        throw new NacosException(ErrorCode.ProtoSubmitError.getCode(), e.getMessage());
    }
}
Also used : Datum(com.alibaba.nacos.naming.consistency.Datum) WriteRequest(com.alibaba.nacos.consistency.entity.WriteRequest) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosException(com.alibaba.nacos.api.exception.NacosException)

Example 14 with WriteRequest

use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.

the class StandalonePersistentServiceProcessor method put.

@Override
public void put(String key, Record value) throws NacosException {
    final BatchWriteRequest req = new BatchWriteRequest();
    Datum datum = Datum.createDatum(key, value);
    req.append(ByteUtils.toBytes(key), serializer.serialize(datum));
    final WriteRequest request = WriteRequest.newBuilder().setData(ByteString.copyFrom(serializer.serialize(req))).setGroup(Constants.NAMING_PERSISTENT_SERVICE_GROUP).setOperation(Op.Write.desc).build();
    try {
        onApply(request);
    } catch (Exception e) {
        throw new NacosException(ErrorCode.ProtoSubmitError.getCode(), e.getMessage());
    }
}
Also used : Datum(com.alibaba.nacos.naming.consistency.Datum) WriteRequest(com.alibaba.nacos.consistency.entity.WriteRequest) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosException(com.alibaba.nacos.api.exception.NacosException)

Example 15 with WriteRequest

use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.

the class StandalonePersistentServiceProcessor method remove.

@Override
public void remove(String key) throws NacosException {
    final BatchWriteRequest req = new BatchWriteRequest();
    req.append(ByteUtils.toBytes(key), ByteUtils.EMPTY);
    final WriteRequest request = WriteRequest.newBuilder().setData(ByteString.copyFrom(serializer.serialize(req))).setGroup(Constants.NAMING_PERSISTENT_SERVICE_GROUP).setOperation(Op.Delete.desc).build();
    try {
        onApply(request);
    } catch (Exception e) {
        throw new NacosException(ErrorCode.ProtoSubmitError.getCode(), e.getMessage());
    }
}
Also used : WriteRequest(com.alibaba.nacos.consistency.entity.WriteRequest) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosException(com.alibaba.nacos.api.exception.NacosException)

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