Search in sources :

Example 21 with Buffers

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

the class BuffersTest method testRead3.

public void testRead3() throws Exception {
    byte[] cookie = { 'b', 'e', 'l', 'a' };
    IpAddress addr = new IpAddress(7500);
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream();
    addr.writeTo(out);
    MockSocketChannel ch = new MockSocketChannel().bytesToRead((ByteBuffer) ByteBuffer.allocate(cookie.length + Global.SHORT_SIZE + out.position()).put(cookie).putShort(Version.version).put(out.buffer(), 0, out.position()).flip());
    int remaining = ch.bytesToRead().remaining();
    ch.bytesToRead().limit(remaining - 10);
    Buffers bufs = new Buffers(ByteBuffer.allocate(cookie.length), ByteBuffer.allocate(Global.SHORT_SIZE), ByteBuffer.allocate(out.position()));
    boolean rc = bufs.read(ch);
    assert !rc;
    ch.bytesToRead().limit(remaining - 2);
    rc = bufs.read(ch);
    assert !rc;
    ch.bytesToRead().limit(remaining);
    rc = bufs.read(ch);
    assert rc;
    readCookieVersionAndAddress(bufs, cookie, addr);
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) IpAddress(org.jgroups.stack.IpAddress) Buffers(org.jgroups.nio.Buffers) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 22 with Buffers

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

the class BuffersTest method testNullData.

public void testNullData() throws Exception {
    MockSocketChannel ch = new MockSocketChannel().bytesToWrite(1000);
    Buffers buf = new Buffers(3);
    Arrays.asList(buf1, buf2, buf3).forEach(buf::add);
    check(buf, 0, 3, 3, remaining(buf1, buf2, buf3));
    boolean rc = buf.write(ch);
    assert rc;
    // makeSpace(buf);
    check(buf, 0, 0, 0, 0);
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) Buffers(org.jgroups.nio.Buffers)

Example 23 with Buffers

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

the class BuffersTest method testMakeSpaceMoveTwo.

public void testMakeSpaceMoveTwo() throws Exception {
    MockSocketChannel ch = new MockSocketChannel().bytesToWrite(1000);
    Buffers buf = new Buffers(6);
    buf.add(buf1);
    buf.add(buf2);
    buf.write(ch);
    buf.add(buf3);
    buf.add(ByteBuffer.wrap("bla".getBytes()));
    ch.bytesToWrite(2);
    boolean rc = buf.write(ch);
    assert !rc;
    buf.copy();
    rc = makeSpace(buf);
    assert rc;
    check(buf, 0, 2, 2, remaining(buf3) + 3);
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) Buffers(org.jgroups.nio.Buffers)

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