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