Search in sources :

Example 1 with CheckedConsumer

use of org.apache.ratis.util.function.CheckedConsumer in project incubator-ratis by apache.

the class DataStreamClusterTests method transferToWritableByteChannel.

static CheckedConsumer<DataStreamOutputImpl, Exception> transferToWritableByteChannel(File f, int size) {
    return new CheckedConsumer<DataStreamOutputImpl, Exception>() {

        @Override
        public void accept(DataStreamOutputImpl out) throws Exception {
            try (FileInputStream in = new FileInputStream(f)) {
                final long transferred = in.getChannel().transferTo(0, size, out.getWritableByteChannel());
                Assert.assertEquals(size, transferred);
            }
        }

        @Override
        public String toString() {
            return "transferToWritableByteChannel";
        }
    };
}
Also used : CheckedConsumer(org.apache.ratis.util.function.CheckedConsumer) DataStreamOutputImpl(org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl) FileInputStream(java.io.FileInputStream)

Example 2 with CheckedConsumer

use of org.apache.ratis.util.function.CheckedConsumer in project incubator-ratis by apache.

the class DataStreamClusterTests method writeAsyncDefaultFileRegion.

static CheckedConsumer<DataStreamOutputImpl, Exception> writeAsyncDefaultFileRegion(File f, int size) {
    return new CheckedConsumer<DataStreamOutputImpl, Exception>() {

        @Override
        public void accept(DataStreamOutputImpl out) {
            final DataStreamReply dataStreamReply = out.writeAsync(f).join();
            DataStreamTestUtils.assertSuccessReply(Type.STREAM_DATA, size, dataStreamReply);
        }

        @Override
        public String toString() {
            return "writeAsyncDefaultFileRegion";
        }
    };
}
Also used : CheckedConsumer(org.apache.ratis.util.function.CheckedConsumer) DataStreamOutputImpl(org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl) DataStreamReply(org.apache.ratis.protocol.DataStreamReply)

Aggregations

DataStreamOutputImpl (org.apache.ratis.client.impl.DataStreamClientImpl.DataStreamOutputImpl)2 CheckedConsumer (org.apache.ratis.util.function.CheckedConsumer)2 FileInputStream (java.io.FileInputStream)1 DataStreamReply (org.apache.ratis.protocol.DataStreamReply)1