Search in sources :

Example 1 with GenericTransportSerializer

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

the class GenericTransportBufferTest method testDoubleClose.

@Test
public void testDoubleClose() throws IOException, TransportException {
    GenericTransportSerializer serializer = mock(GenericTransportSerializer.class);
    GenericTransportBuffer buffer = new GenericTransportBuffer(1, true, serializer);
    buffer.close();
    buffer.close();
}
Also used : GenericTransportSerializer(com.nextdoor.bender.ipc.generic.GenericTransportSerializer) GenericTransportBuffer(com.nextdoor.bender.ipc.generic.GenericTransportBuffer) Test(org.junit.Test)

Example 2 with GenericTransportSerializer

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

the class GenericTransportBufferTest method testAddBufferFull.

@Test(expected = IllegalStateException.class)
public void testAddBufferFull() 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);
    buffer.add(mockEvent);
}
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 3 with GenericTransportSerializer

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

the class GenericTransportBufferTest method testClear.

@Test
public void testClear() 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);
    buffer.close();
    String actual = new String(buffer.getInternalBuffer().toByteArray());
    assertEquals("foo", actual);
    buffer.clear();
    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 4 with GenericTransportSerializer

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

the class GenericTansportSerializerTest method testSerialize.

@Test
public void testSerialize() throws UnsupportedEncodingException, IOException {
    GenericTransportSerializer serializer = new GenericTransportSerializer();
    InternalEvent record = new DummyEvent("foo", 0);
    record.setEventTime(1505927823123l);
    record.setSerialized("foo");
    String actual = new String(serializer.serialize(record));
    String expected = TestUtils.getResourceString(this.getClass(), "basic_output.txt");
    assertEquals(expected, actual);
}
Also used : GenericTransportSerializer(com.nextdoor.bender.ipc.generic.GenericTransportSerializer) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 5 with GenericTransportSerializer

use of com.nextdoor.bender.ipc.generic.GenericTransportSerializer 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)

Aggregations

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