Search in sources :

Example 1 with GenericTransportBuffer

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

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

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

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

the class HttpTransport method sendBatch.

public void sendBatch(TransportBuffer buf) throws TransportException {
    GenericTransportBuffer buffer = (GenericTransportBuffer) buf;
    sendBatch(buffer.getInternalBuffer().toByteArray());
}
Also used : GenericTransportBuffer(com.nextdoor.bender.ipc.generic.GenericTransportBuffer)

Example 5 with GenericTransportBuffer

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

the class StdoutTransportTest method testStdout.

@Test
public void testStdout() throws IllegalStateException, IOException {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    System.setOut(new PrintStream(bo));
    StdoutTransport transport = new StdoutTransport();
    GenericTransportBuffer buf = new GenericTransportBuffer(1, false, new StdoutTransportSerializer());
    InternalEvent event = new InternalEvent("junk", new TestContext(), 123);
    event.setSerialized("junk");
    buf.add(event);
    transport.sendBatch(buf);
    bo.flush();
    String allWrittenLines = new String(bo.toByteArray());
    assertEquals("junk\n", allWrittenLines);
}
Also used : PrintStream(java.io.PrintStream) TestContext(com.nextdoor.bender.aws.TestContext) 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