Search in sources :

Example 6 with DataStreamOutputImpl

use of org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl in project incubator-ratis by apache.

the class DataStreamBaseTest method runTestMockCluster.

void runTestMockCluster(ClientId clientId, int bufferSize, int bufferNum, Exception expectedException, Exception headerException) throws IOException {
    try (final RaftClient client = newRaftClientForDataStream(clientId)) {
        final DataStreamOutputImpl out = (DataStreamOutputImpl) client.getDataStreamApi().stream(null, DataStreamTestUtils.getRoutingTableChainTopology(peers, getPrimaryServer().getPeer()));
        if (headerException != null) {
            final DataStreamReply headerReply = out.getHeaderFuture().join();
            Assert.assertFalse(headerReply.isSuccess());
            final RaftClientReply clientReply = ClientProtoUtils.toRaftClientReply(((DataStreamReplyByteBuffer) headerReply).slice());
            Assert.assertTrue(clientReply.getException().getMessage().contains(headerException.getMessage()));
            return;
        }
        final RaftClientReply clientReply = DataStreamTestUtils.writeAndCloseAndAssertReplies(CollectionUtils.as(servers, Server::getRaftServer), null, out, bufferSize, bufferNum, getPrimaryClientId(), client.getId(), false).join();
        if (expectedException != null) {
            Assert.assertFalse(clientReply.isSuccess());
            Assert.assertTrue(clientReply.getException().getMessage().contains(expectedException.getMessage()));
        } else {
            Assert.assertTrue(clientReply.isSuccess());
        }
    }
}
Also used : DataStreamOutputImpl(org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) DataStreamServer(org.apache.ratis.server.DataStreamServer) RaftServer(org.apache.ratis.server.RaftServer) DataStreamReply(org.apache.ratis.protocol.DataStreamReply) RaftClient(org.apache.ratis.client.RaftClient)

Aggregations

DataStreamOutputImpl (org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl)6 RaftClient (org.apache.ratis.client.RaftClient)4 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)4 RaftPeer (org.apache.ratis.protocol.RaftPeer)3 DataStreamReply (org.apache.ratis.protocol.DataStreamReply)2 RaftClientRequest (org.apache.ratis.protocol.RaftClientRequest)2 RaftServer (org.apache.ratis.server.RaftServer)2 CheckedConsumer (org.apache.ratis.util.function.CheckedConsumer)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 ClientId (org.apache.ratis.protocol.ClientId)1 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)1 DataStreamServer (org.apache.ratis.server.DataStreamServer)1 Timestamp (org.apache.ratis.util.Timestamp)1