Search in sources :

Example 16 with Buffers

use of org.jgroups.nio.Buffers in project JGroups by belaban.

the class BuffersTest method testMakeSpaceSimple.

public void testMakeSpaceSimple() throws Exception {
    MockSocketChannel ch = new MockSocketChannel().bytesToWrite(1000);
    Buffers buf = new Buffers(2);
    buf.add(buf1);
    check(buf, 0, 1, 1, remaining(buf1));
    boolean rc = makeSpace(buf);
    assert !rc;
    buf.write(ch);
    check(buf, 1, 1, 0, 0);
    rc = makeSpace(buf);
    assert rc;
    check(buf, 0, 0, 0, 0);
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) Buffers(org.jgroups.nio.Buffers)

Example 17 with Buffers

use of org.jgroups.nio.Buffers in project JGroups by belaban.

the class BuffersTest method testSimpleWrite.

public void testSimpleWrite() throws Exception {
    MockSocketChannel ch = new MockSocketChannel().bytesToWrite(1000);
    Buffers buf = new Buffers(2);
    boolean rc = buf.write(ch, buf1.duplicate());
    assert rc;
    check(buf, 1, 1, 0, 0);
    rc = buf.write(ch, buf2.duplicate());
    assert rc;
    check(buf, 0, 0, 0, 0);
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) Buffers(org.jgroups.nio.Buffers)

Example 18 with Buffers

use of org.jgroups.nio.Buffers in project JGroups by belaban.

the class BuffersTest method testWriteAtStartup.

public void testWriteAtStartup() throws Exception {
    Buffers bufs = new Buffers(5);
    // all writes will initially fail
    MockSocketChannel ch = new MockSocketChannel();
    boolean rc = bufs.write(ch, buf1);
    assert !rc;
    check(bufs, 0, 1, 1, remaining(buf1));
    ch.bytesToWrite(100);
    rc = bufs.write(ch, buf2);
    assert rc;
    check(bufs, 2, 2, 0, 0);
    for (int i = 0; i < 3; i++) {
        ByteBuffer b = buf3.duplicate();
        rc = bufs.write(ch, b);
        assert rc;
    }
    check(bufs, 0, 0, 0, 0);
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) Buffers(org.jgroups.nio.Buffers) ByteBuffer(java.nio.ByteBuffer)

Example 19 with Buffers

use of org.jgroups.nio.Buffers in project JGroups by belaban.

the class BuffersTest method testWrite2.

public void testWrite2() throws Exception {
    ByteBuffer b = buffer();
    Buffers bufs = new Buffers(ByteBuffer.allocate(Global.INT_SIZE), null);
    MockSocketChannel ch = new MockSocketChannel().bytesToWrite(15);
    boolean rc = bufs.write(ch, b);
    assert rc;
    // write only a portion of the data
    ch.bytesToWrite(10);
    b.clear();
    rc = bufs.write(ch, b);
    assert rc == false;
    ch.bytesToWrite(10);
    rc = bufs.write(ch);
    assert rc;
    ch.bytesToWrite(10);
    // mimic a new buffer
    b = buffer();
    rc = bufs.write(ch, b);
    assert rc == false;
    ch.bytesToWrite(30);
    // mimic a new buffer
    b = buffer();
    rc = bufs.write(ch, b);
    assert rc;
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) Buffers(org.jgroups.nio.Buffers) ByteBuffer(java.nio.ByteBuffer)

Example 20 with Buffers

use of org.jgroups.nio.Buffers in project JGroups by belaban.

the class BuffersTest method testWrite.

public void testWrite() throws Exception {
    ByteBuffer b = buf1.duplicate();
    Buffers bufs = new Buffers(2);
    MockSocketChannel ch = new MockSocketChannel().bytesToWrite(15);
    boolean rc = bufs.write(ch, b);
    assert rc;
    check(bufs, 1, 1, 0, 0);
    // write only a portion of the data
    ch.bytesToWrite(10);
    b.clear();
    rc = bufs.write(ch, b);
    assert !rc;
    check(bufs, 1, 2, 1, b.remaining());
    ch.bytesToWrite(10);
    rc = bufs.write(ch);
    assert rc;
    check(bufs, 0, 0, 0, 0);
    ch.bytesToWrite(10);
    // mimic a new buffer
    b = buf1.duplicate();
    rc = bufs.write(ch, b);
    assert rc == false;
    check(bufs, 0, 1, 1, b.remaining());
    ch.bytesToWrite(30);
    // mimic a new buffer
    b = buf1.duplicate();
    rc = bufs.write(ch, b);
    assert rc;
    check(bufs, 0, 0, 0, 0);
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) Buffers(org.jgroups.nio.Buffers) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Buffers (org.jgroups.nio.Buffers)23 MockSocketChannel (org.jgroups.nio.MockSocketChannel)19 ByteBuffer (java.nio.ByteBuffer)14 IpAddress (org.jgroups.stack.IpAddress)2 ByteArrayDataOutputStream (org.jgroups.util.ByteArrayDataOutputStream)2 EOFException (java.io.EOFException)1