Search in sources :

Example 1 with TransportSerializer

use of com.nextdoor.bender.ipc.TransportSerializer in project bender by Nextdoor.

the class TcpTransportBufferTest method shouldThrowIfBufferSizeOverflow.

@Test
public void shouldThrowIfBufferSizeOverflow() {
    TransportSerializer serializer = mock(TransportSerializer.class);
    TcpTransportBuffer buffer = new TcpTransportBuffer(10L, serializer);
    InternalEvent event = new InternalEvent("", null, 0);
    byte[] bytes = "123456789".getBytes();
    when(serializer.serialize(eq(event))).thenReturn(bytes);
    assertTrue(buffer.add(event));
    assertEquals(bytes.length, buffer.getInternalBuffer().size());
    try {
        buffer.add(event);
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException ex) {
    }
}
Also used : TransportSerializer(com.nextdoor.bender.ipc.TransportSerializer) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 2 with TransportSerializer

use of com.nextdoor.bender.ipc.TransportSerializer in project bender by Nextdoor.

the class TcpTransportBufferTest method clearShouldEmptyBuffer.

@Test
public void clearShouldEmptyBuffer() {
    TransportSerializer serializer = mock(TransportSerializer.class);
    TcpTransportBuffer buffer = new TcpTransportBuffer(10L, serializer);
    InternalEvent event = new InternalEvent("", null, 0);
    byte[] bytes = "foo".getBytes();
    when(serializer.serialize(eq(event))).thenReturn(bytes);
    assertTrue(buffer.add(event));
    assertEquals(bytes.length, buffer.getInternalBuffer().size());
    assertFalse(buffer.isEmpty());
    buffer.clear();
    assertEquals(0L, buffer.getInternalBuffer().size());
    assertTrue(buffer.isEmpty());
    assertTrue(buffer.add(event));
    assertEquals(bytes.length, buffer.getInternalBuffer().size());
    assertFalse(buffer.isEmpty());
}
Also used : TransportSerializer(com.nextdoor.bender.ipc.TransportSerializer) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)2 TransportSerializer (com.nextdoor.bender.ipc.TransportSerializer)2 Test (org.junit.Test)2