Search in sources :

Example 1 with BufferedTransporter

use of com.nextdoor.bender.testutils.DummyTransportHelper.BufferedTransporter in project bender by Nextdoor.

the class BaseHandlerTest method testTransportOnSendFailure.

@Test(expected = TransportException.class)
public void testTransportOnSendFailure() throws Throwable {
    BaseHandler.CONFIG_FILE = "/config/handler_config.json";
    List<DummyEvent> events = new ArrayList<DummyEvent>(2);
    events.add(new DummyEvent("foo", 0));
    events.add(new DummyEvent("bar", 0));
    TestContext context = new TestContext();
    context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag");
    handler.init(context);
    IpcSenderService spyIpc = spy(handler.getIpcService());
    TransportFactory tf = spy(handler.getIpcService().getTransportFactory());
    BufferedTransporter mockTransport = mock(BufferedTransporter.class);
    doThrow(new TransportException("expected")).when(mockTransport).sendBatch(any());
    when(tf.newInstance()).thenReturn(mockTransport);
    spyIpc.setTransportFactory(tf);
    handler.setIpcService(spyIpc);
    try {
        handler.handler(events, context);
    } catch (Exception e) {
        throw e.getCause().getCause();
    }
}
Also used : IpcSenderService(com.nextdoor.bender.ipc.IpcSenderService) TransportFactory(com.nextdoor.bender.ipc.TransportFactory) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) BufferedTransporter(com.nextdoor.bender.testutils.DummyTransportHelper.BufferedTransporter) TransportException(com.nextdoor.bender.ipc.TransportException) TransportException(com.nextdoor.bender.ipc.TransportException) IOException(java.io.IOException) DeserializationException(com.nextdoor.bender.deserializer.DeserializationException) SerializationException(com.nextdoor.bender.serializer.SerializationException) OperationException(com.nextdoor.bender.operation.OperationException) Test(org.junit.Test)

Aggregations

TestContext (com.nextdoor.bender.aws.TestContext)1 DeserializationException (com.nextdoor.bender.deserializer.DeserializationException)1 IpcSenderService (com.nextdoor.bender.ipc.IpcSenderService)1 TransportException (com.nextdoor.bender.ipc.TransportException)1 TransportFactory (com.nextdoor.bender.ipc.TransportFactory)1 OperationException (com.nextdoor.bender.operation.OperationException)1 SerializationException (com.nextdoor.bender.serializer.SerializationException)1 BufferedTransporter (com.nextdoor.bender.testutils.DummyTransportHelper.BufferedTransporter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1