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);
}
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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations