Search in sources :

Example 6 with GenericTransportBuffer

use of com.nextdoor.bender.ipc.generic.GenericTransportBuffer in project bender by Nextdoor.

the class GenericTransportBufferTest method testGzip.

@Test
public void testGzip() throws IOException {
    GenericTransportSerializer serializer = mock(GenericTransportSerializer.class);
    doReturn("foo".getBytes()).when(serializer).serialize(any(InternalEvent.class));
    GenericTransportBuffer buffer = new GenericTransportBuffer(1, true, serializer);
    InternalEvent mockEvent = mock(InternalEvent.class);
    buffer.add(mockEvent);
    buffer.close();
    byte[] actual = buffer.getInternalBuffer().toByteArray();
    byte[] expected = { 31, -117, 8, 0, 0, 0, 0, 0, 0, 0, 75, -53, -49, 7, 0, 33, 101, 115, -116, 3, 0, 0, 0 };
    assertArrayEquals(expected, actual);
}
Also used : GenericTransportSerializer(com.nextdoor.bender.ipc.generic.GenericTransportSerializer) GenericTransportBuffer(com.nextdoor.bender.ipc.generic.GenericTransportBuffer) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 7 with GenericTransportBuffer

use of com.nextdoor.bender.ipc.generic.GenericTransportBuffer in project bender by Nextdoor.

the class GenericTransportBufferTest method testEmptyBuffer.

@Test
public void testEmptyBuffer() throws IOException {
    GenericTransportSerializer serializer = mock(GenericTransportSerializer.class);
    doReturn("foo".getBytes()).when(serializer).serialize(any(InternalEvent.class));
    GenericTransportBuffer buffer = new GenericTransportBuffer(1, false, serializer);
    assertEquals(true, buffer.isEmpty());
}
Also used : GenericTransportSerializer(com.nextdoor.bender.ipc.generic.GenericTransportSerializer) GenericTransportBuffer(com.nextdoor.bender.ipc.generic.GenericTransportBuffer) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 8 with GenericTransportBuffer

use of com.nextdoor.bender.ipc.generic.GenericTransportBuffer in project bender by Nextdoor.

the class GenericTransportBufferTest method testAdd.

@Test
public void testAdd() throws IOException {
    GenericTransportSerializer serializer = mock(GenericTransportSerializer.class);
    doReturn("foo".getBytes()).when(serializer).serialize(any(InternalEvent.class));
    GenericTransportBuffer buffer = new GenericTransportBuffer(1, false, serializer);
    InternalEvent mockEvent = mock(InternalEvent.class);
    buffer.add(mockEvent);
    ByteArrayOutputStream baos = buffer.getInternalBuffer();
    baos.close();
    String actual = new String(baos.toByteArray());
    assertEquals("foo", actual);
    assertEquals(false, buffer.isEmpty());
}
Also used : GenericTransportSerializer(com.nextdoor.bender.ipc.generic.GenericTransportSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericTransportBuffer(com.nextdoor.bender.ipc.generic.GenericTransportBuffer) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Aggregations

GenericTransportBuffer (com.nextdoor.bender.ipc.generic.GenericTransportBuffer)8 Test (org.junit.Test)7 InternalEvent (com.nextdoor.bender.InternalEvent)6 GenericTransportSerializer (com.nextdoor.bender.ipc.generic.GenericTransportSerializer)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 TestContext (com.nextdoor.bender.aws.TestContext)1 PrintStream (java.io.PrintStream)1