Search in sources :

Example 1 with ByteString

use of org.apache.ratis.shaded.com.google.protobuf.ByteString in project incubator-ratis by apache.

the class TestRaftId method testClientId.

@Test
public void testClientId() {
    final ClientId id = ClientId.randomId();
    final ByteString bytes = id.toByteString();
    Assert.assertEquals(bytes, id.toByteString());
    Assert.assertEquals(id, ClientId.valueOf(bytes));
}
Also used : ByteString(org.apache.ratis.shaded.com.google.protobuf.ByteString) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 2 with ByteString

use of org.apache.ratis.shaded.com.google.protobuf.ByteString in project incubator-ratis by apache.

the class TestRaftId method testRaftGroupId.

@Test
public void testRaftGroupId() {
    final RaftGroupId id = RaftGroupId.randomId();
    final ByteString bytes = id.toByteString();
    Assert.assertEquals(bytes, id.toByteString());
    Assert.assertEquals(id, RaftGroupId.valueOf(bytes));
}
Also used : ByteString(org.apache.ratis.shaded.com.google.protobuf.ByteString) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 3 with ByteString

use of org.apache.ratis.shaded.com.google.protobuf.ByteString in project incubator-ratis by apache.

the class TestRaftId method testRaftPeerId.

@Test
public void testRaftPeerId() {
    final RaftPeerId id = RaftPeerId.valueOf("abc");
    final ByteString bytes = id.toByteString();
    Assert.assertEquals(bytes, id.toByteString());
    Assert.assertEquals(id, RaftPeerId.valueOf(bytes));
}
Also used : ByteString(org.apache.ratis.shaded.com.google.protobuf.ByteString) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 4 with ByteString

use of org.apache.ratis.shaded.com.google.protobuf.ByteString in project incubator-ratis by apache.

the class FileStoreClient method write.

public long write(String path, long offset, boolean close, ByteBuffer buffer) throws IOException {
    final int chunkSize = FileStoreCommon.getChunkSize(buffer.remaining());
    buffer.limit(chunkSize);
    final ByteString reply = writeImpl(this::send, path, offset, close, buffer);
    return WriteReplyProto.parseFrom(reply).getLength();
}
Also used : ByteString(org.apache.ratis.shaded.com.google.protobuf.ByteString)

Example 5 with ByteString

use of org.apache.ratis.shaded.com.google.protobuf.ByteString in project incubator-ratis by apache.

the class FileStoreStateMachine method writeStateMachineData.

@Override
public CompletableFuture<Integer> writeStateMachineData(LogEntryProto entry) {
    final SMLogEntryProto smLog = entry.getSmLogEntry();
    final ByteString data = smLog.getData();
    final FileStoreRequestProto proto;
    try {
        proto = FileStoreRequestProto.parseFrom(data);
    } catch (InvalidProtocolBufferException e) {
        return FileStoreCommon.completeExceptionally(entry.getIndex(), "Failed to parse data, entry=" + entry, e);
    }
    if (proto.getRequestCase() != FileStoreRequestProto.RequestCase.WRITEHEADER) {
        return null;
    }
    final WriteRequestHeaderProto h = proto.getWriteHeader();
    final CompletableFuture<Integer> f = files.write(entry.getIndex(), h.getPath().toStringUtf8(), h.getClose(), h.getOffset(), smLog.getStateMachineData());
    // sync only if closing the file
    return h.getClose() ? f : null;
}
Also used : SMLogEntryProto(org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto) ByteString(org.apache.ratis.shaded.com.google.protobuf.ByteString) InvalidProtocolBufferException(org.apache.ratis.shaded.com.google.protobuf.InvalidProtocolBufferException)

Aggregations

ByteString (org.apache.ratis.shaded.com.google.protobuf.ByteString)8 BaseTest (org.apache.ratis.BaseTest)3 SMLogEntryProto (org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 StateMachineException (org.apache.ratis.protocol.StateMachineException)1 InvalidProtocolBufferException (org.apache.ratis.shaded.com.google.protobuf.InvalidProtocolBufferException)1 LogEntryProto (org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto)1 TransactionContextImpl (org.apache.ratis.statemachine.impl.TransactionContextImpl)1