Search in sources :

Example 1 with ByteString

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

the class FileStoreWriter method verify.

FileStoreWriter verify() throws IOException {
    final Random r = new Random(seed);
    final int size = fileSize.getSizeInt();
    for (int offset = 0; offset < size; ) {
        final int remaining = size - offset;
        final int n = Math.min(remaining, buffer.length);
        final ByteString read = client.read(fileName, offset, n);
        final ByteBuffer expected = randomBytes(n, r);
        verify(read, offset, n, expected);
        offset += n;
    }
    return this;
}
Also used : Random(java.util.Random) ThreadLocalRandom(org.apache.ratis.thirdparty.io.netty.util.internal.ThreadLocalRandom) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) ByteBuffer(java.nio.ByteBuffer)

Example 2 with ByteString

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

the class DataStreamTestUtils method assertCloseReply.

static CompletableFuture<RaftClientReply> assertCloseReply(DataStreamOutputImpl out, DataStreamReply dataStreamReply, long bytesWritten, RaftPeerId leader, ClientId primaryClientId, ClientId clientId, boolean stepDownLeader) {
    // Test close idempotent
    Assert.assertSame(dataStreamReply, out.closeAsync().join());
    Assert.assertEquals(dataStreamReply.getClientId(), clientId);
    BaseTest.testFailureCase("writeAsync should fail", () -> out.writeAsync(DataStreamRequestByteBuffer.EMPTY_BYTE_BUFFER).join(), CompletionException.class, (Logger) null, AlreadyClosedException.class);
    final DataStreamReplyByteBuffer buffer = (DataStreamReplyByteBuffer) dataStreamReply;
    try {
        final RaftClientReply reply = ClientProtoUtils.toRaftClientReply(buffer.slice());
        assertRaftClientMessage(out.getHeader(), leader, reply, primaryClientId, stepDownLeader);
        if (reply.isSuccess()) {
            final ByteString bytes = reply.getMessage().getContent();
            if (!bytes.equals(MOCK)) {
                Assert.assertEquals(bytesWritten2ByteString(bytesWritten), bytes);
            }
        }
        return CompletableFuture.completedFuture(reply);
    } catch (Throwable t) {
        return JavaUtils.completeExceptionally(t);
    }
}
Also used : RaftClientReply(org.apache.ratis.protocol.RaftClientReply) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) DataStreamReplyByteBuffer(org.apache.ratis.datastream.impl.DataStreamReplyByteBuffer)

Example 3 with ByteString

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

the class TestClientProtoUtils method runTestToRaftClientRequestProto.

void runTestToRaftClientRequestProto(int n, SizeInBytes messageSize) throws Exception {
    final ClientId clientId = ClientId.randomId();
    final RaftPeerId leaderId = RaftPeerId.valueOf("s0");
    final RaftGroupId groupId = RaftGroupId.randomId();
    TimeDuration toProto = TimeDuration.ZERO;
    TimeDuration toRequest = TimeDuration.ZERO;
    for (int i = 0; i < n; i++) {
        final ByteString bytes = newByteString(messageSize.getSizeInt(), i);
        final RaftClientRequest request = RaftClientRequest.newBuilder().setClientId(clientId).setServerId(leaderId).setGroupId(groupId).setCallId(1).setMessage(() -> bytes).setType(RaftClientRequest.writeRequestType()).build();
        final Timestamp startTime = Timestamp.currentTime();
        final RaftClientRequestProto proto = ClientProtoUtils.toRaftClientRequestProto(request);
        final TimeDuration p = startTime.elapsedTime();
        final RaftClientRequest computed = ClientProtoUtils.toRaftClientRequest(proto);
        final TimeDuration r = startTime.elapsedTime().subtract(p);
        Assert.assertEquals(request.getMessage().getContent(), computed.getMessage().getContent());
        toProto = toProto.add(p);
        toRequest = toRequest.add(r);
    }
    System.out.printf("%nmessageSize=%s, n=%d%n", messageSize, n);
    print("toProto  ", toProto, n);
    print("toRequest", toRequest, n);
}
Also used : RaftClientRequest(org.apache.ratis.protocol.RaftClientRequest) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) ClientId(org.apache.ratis.protocol.ClientId) RaftClientRequestProto(org.apache.ratis.proto.RaftProtos.RaftClientRequestProto) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) TimeDuration(org.apache.ratis.util.TimeDuration) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) Timestamp(org.apache.ratis.util.Timestamp)

Example 4 with ByteString

use of org.apache.ratis.thirdparty.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.thirdparty.com.google.protobuf.ByteString) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 5 with ByteString

use of org.apache.ratis.thirdparty.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.thirdparty.com.google.protobuf.ByteString) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Aggregations

ByteString (org.apache.ratis.thirdparty.com.google.protobuf.ByteString)19 FileStoreRequestProto (org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto)4 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)4 InvalidProtocolBufferException (org.apache.ratis.thirdparty.com.google.protobuf.InvalidProtocolBufferException)4 Test (org.junit.Test)4 BaseTest (org.apache.ratis.BaseTest)3 SimpleMessage (org.apache.ratis.RaftTestUtil.SimpleMessage)3 RaftClient (org.apache.ratis.client.RaftClient)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 WriteRequestHeaderProto (org.apache.ratis.proto.ExamplesProtos.WriteRequestHeaderProto)2 StateMachineLogEntryProto (org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto)2 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)2 TimeDuration (org.apache.ratis.util.TimeDuration)2 Gauge (com.codahale.metrics.Gauge)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Random (java.util.Random)1