Search in sources :

Example 1 with BufferState

use of io.fabric8.dosgi.io.ProtocolCodec.BufferState in project fabric8 by jboss-fuse.

the class LengthPrefixedCodecTest method testWrite$Twice.

@Test
public void testWrite$Twice() throws Exception {
    final Buffer value1 = Buffer.ascii("TESTDATA");
    final Buffer value2 = Buffer.ascii("TESTDATA");
    codec.write(value1);
    final BufferState state = codec.write(value2);
    assertEquals(BufferState.NOT_EMPTY, state);
    assertEquals(false, codec.full());
    assertEquals(false, codec.empty());
    assertEquals(0l, codec.getWriteCounter());
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer) BufferState(io.fabric8.dosgi.io.ProtocolCodec.BufferState) Test(org.junit.Test)

Example 2 with BufferState

use of io.fabric8.dosgi.io.ProtocolCodec.BufferState in project fabric8 by jboss-fuse.

the class LengthPrefixedCodecTest method testWrite.

@Test
public void testWrite() throws Exception {
    final Buffer value = Buffer.ascii("TESTDATA");
    final BufferState state = codec.write(value);
    assertEquals(BufferState.WAS_EMPTY, state);
    assertEquals(false, codec.full());
    assertEquals(false, codec.empty());
    assertEquals(0l, codec.getWriteCounter());
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer) BufferState(io.fabric8.dosgi.io.ProtocolCodec.BufferState) Test(org.junit.Test)

Example 3 with BufferState

use of io.fabric8.dosgi.io.ProtocolCodec.BufferState in project fabric8 by jboss-fuse.

the class LengthPrefixedCodecTest method testFlush$Partially.

@Test
public void testFlush$Partially() throws Exception {
    final Buffer value = Buffer.ascii("TESTDATA");
    codec.write(value);
    final int bytesThatWillBeWritten = value.length() / 2;
    expect(writableByteChannel.write((ByteBuffer) anyObject())).andAnswer(createWriteAnswer(bytesThatWillBeWritten));
    replay(writableByteChannel);
    final BufferState state = codec.flush();
    assertEquals(BufferState.NOT_EMPTY, state);
    assertEquals(false, codec.full());
    assertEquals(false, codec.empty());
    assertEquals(bytesThatWillBeWritten, codec.getWriteCounter());
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer) BufferState(io.fabric8.dosgi.io.ProtocolCodec.BufferState) Test(org.junit.Test)

Example 4 with BufferState

use of io.fabric8.dosgi.io.ProtocolCodec.BufferState in project fabric8 by jboss-fuse.

the class LengthPrefixedCodecTest method testFlush.

@Test
public void testFlush() throws Exception {
    final Buffer value = Buffer.ascii("TESTDATA");
    codec.write(value);
    final int bytesThatWillBeWritten = value.length();
    expect(writableByteChannel.write((ByteBuffer) anyObject())).andAnswer(createWriteAnswer(bytesThatWillBeWritten));
    replay(writableByteChannel);
    final BufferState state = codec.flush();
    assertEquals(BufferState.EMPTY, state);
    assertEquals(false, codec.full());
    assertEquals(true, codec.empty());
    assertEquals(bytesThatWillBeWritten, codec.getWriteCounter());
    assertEquals(BufferState.WAS_EMPTY, codec.flush());
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer) BufferState(io.fabric8.dosgi.io.ProtocolCodec.BufferState) Test(org.junit.Test)

Aggregations

BufferState (io.fabric8.dosgi.io.ProtocolCodec.BufferState)4 ByteBuffer (java.nio.ByteBuffer)4 Buffer (org.fusesource.hawtbuf.Buffer)4 Test (org.junit.Test)4