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) {
}
}
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());
}
Aggregations