Search in sources :

Example 1 with ArrayTransportBuffer

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

the class BaseHandlerTest method testIpcOnAddFailure.

@Test
public void testIpcOnAddFailure() throws Throwable {
    BaseHandler.CONFIG_FILE = "/config/handler_config.json";
    handler.skipWriteStats = true;
    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);
    TransportBuffer tbSpy1 = spy(new ArrayTransportBuffer());
    TransportBuffer tbSpy2 = spy(new ArrayTransportBuffer());
    doCallRealMethod().doCallRealMethod().when(tbSpy1).add(any());
    doThrow(new IllegalStateException("expected")).when(tbSpy2).add(any());
    IpcSenderService spyIpc = spy(handler.getIpcService());
    TransportFactory tfSpy = spy(spyIpc.getTransportFactory());
    when(tfSpy.newTransportBuffer()).thenReturn(tbSpy1, tbSpy2);
    spyIpc.setTransportFactory(tfSpy);
    handler.setIpcService(spyIpc);
    handler.handler(events, context);
    assertEquals(1, spyIpc.getSuccessCountStat().getValue());
}
Also used : IpcSenderService(com.nextdoor.bender.ipc.IpcSenderService) TransportFactory(com.nextdoor.bender.ipc.TransportFactory) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) ArrayTransportBuffer(com.nextdoor.bender.testutils.DummyTransportHelper.ArrayTransportBuffer) TransportBuffer(com.nextdoor.bender.ipc.TransportBuffer) ArrayTransportBuffer(com.nextdoor.bender.testutils.DummyTransportHelper.ArrayTransportBuffer) Test(org.junit.Test)

Aggregations

TestContext (com.nextdoor.bender.aws.TestContext)1 IpcSenderService (com.nextdoor.bender.ipc.IpcSenderService)1 TransportBuffer (com.nextdoor.bender.ipc.TransportBuffer)1 TransportFactory (com.nextdoor.bender.ipc.TransportFactory)1 ArrayTransportBuffer (com.nextdoor.bender.testutils.DummyTransportHelper.ArrayTransportBuffer)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1