Search in sources :

Example 16 with BlockingInputStream

use of org.jgroups.util.BlockingInputStream in project JGroups by belaban.

the class BlockingInputStreamTest method testLargeTransfer2.

public void testLargeTransfer2() throws IOException {
    final BlockingInputStream in = new BlockingInputStream(8192);
    final byte[] buffer = generateBuffer(1000000);
    new Writer(in, buffer).start();
    byte[] tmp = new byte[buffer.length];
    // reads 1 million bytes in one go
    int bytes = in.read(tmp);
    System.out.println("read " + bytes + " bytes");
    assert bytes == buffer.length : "read " + bytes + " bytes but expected " + buffer.length;
    System.out.print("Verifying that the buffers are the same: ");
    for (int i = 0; i < tmp.length; i++) assert buffer[i] == tmp[i];
    System.out.println("OK");
}
Also used : BlockingInputStream(org.jgroups.util.BlockingInputStream)

Example 17 with BlockingInputStream

use of org.jgroups.util.BlockingInputStream in project JGroups by belaban.

the class BlockingInputStreamTest method testCreation.

public void testCreation() throws IOException {
    BlockingInputStream in = new BlockingInputStream(2000);
    System.out.println("in = " + in);
    assert in.available() == 0 && in.capacity() == 2000;
    in.write(new byte[] { 'b', 'e', 'l', 'a' });
    System.out.println("in = " + in);
    assert in.available() == 4 && in.capacity() == 2000;
}
Also used : BlockingInputStream(org.jgroups.util.BlockingInputStream)

Example 18 with BlockingInputStream

use of org.jgroups.util.BlockingInputStream in project JGroups by belaban.

the class BlockingInputStreamTest method testWriterMultipleChunks.

public void testWriterMultipleChunks() throws Exception {
    final BlockingInputStream in = new BlockingInputStream(100);
    final byte[] buffer = generateBuffer(500);
    Writer writer = new Writer(in, buffer, 5, true);
    writer.start();
    byte[] tmp = new byte[20];
    int num = 0;
    while (true) {
        int read = in.read(tmp);
        if (read == -1)
            break;
        num += read;
    }
    System.out.println("read " + num + " bytes");
    assert num == 5 * buffer.length;
}
Also used : BlockingInputStream(org.jgroups.util.BlockingInputStream)

Aggregations

BlockingInputStream (org.jgroups.util.BlockingInputStream)18 CountDownLatch (java.util.concurrent.CountDownLatch)2 Tuple (org.jgroups.util.Tuple)1