Search in sources :

Example 1 with IpcSenderService

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

Example 2 with IpcSenderService

use of com.nextdoor.bender.ipc.IpcSenderService in project bender by Nextdoor.

the class HandlerTest method testExceptionHandling.

@Test(expected = TransportException.class)
public void testExceptionHandling() throws Throwable {
    TestContext ctx = new TestContext();
    ctx.setFunctionName("unittest");
    ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");
    /*
     * Invoke handler
     */
    BaseHandler<T> fhandler = (BaseHandler<T>) getHandler();
    fhandler.init(ctx);
    IpcSenderService ipcSpy = spy(fhandler.getIpcService());
    doThrow(new TransportException("expected")).when(ipcSpy).shutdown();
    fhandler.setIpcService(ipcSpy);
    T event = getTestEvent();
    try {
        fhandler.handler(event, ctx);
    } catch (Exception e) {
        throw e.getCause().getCause();
    }
}
Also used : IpcSenderService(com.nextdoor.bender.ipc.IpcSenderService) TestContext(com.nextdoor.bender.aws.TestContext) TransportException(com.nextdoor.bender.ipc.TransportException) TransportException(com.nextdoor.bender.ipc.TransportException) Test(org.junit.Test)

Example 3 with IpcSenderService

use of com.nextdoor.bender.ipc.IpcSenderService in project bender by Nextdoor.

the class BaseHandlerTest method testGeneralTransportExceptionOnShutdown.

@Test(expected = TransportException.class)
public void testGeneralTransportExceptionOnShutdown() throws Throwable {
    BaseHandler.CONFIG_FILE = "/config/handler_config.json";
    List<DummyEvent> events = new ArrayList<DummyEvent>(1);
    events.add(new DummyEvent("foo", 0));
    TestContext context = new TestContext();
    context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag");
    handler.init(context);
    IpcSenderService spy = spy(handler.getIpcService());
    handler.setIpcService(spy);
    doThrow(new TransportException("expected")).when(spy).shutdown();
    try {
        handler.handler(events, context);
    } catch (Exception e) {
        throw e.getCause().getCause();
    }
}
Also used : IpcSenderService(com.nextdoor.bender.ipc.IpcSenderService) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) 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)

Example 4 with IpcSenderService

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

Example 5 with IpcSenderService

use of com.nextdoor.bender.ipc.IpcSenderService in project bender by Nextdoor.

the class BaseHandlerTest method testInterruptedExceptionOnShutdown.

@Test(expected = InterruptedException.class)
public void testInterruptedExceptionOnShutdown() throws Throwable {
    BaseHandler.CONFIG_FILE = "/config/handler_config.json";
    List<DummyEvent> events = new ArrayList<DummyEvent>(1);
    events.add(new DummyEvent("foo", 0));
    TestContext context = new TestContext();
    context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag");
    handler.init(context);
    IpcSenderService spy = spy(handler.getIpcService());
    handler.setIpcService(spy);
    doThrow(new InterruptedException("expected")).when(spy).shutdown();
    try {
        handler.handler(events, context);
    } catch (Exception e) {
        throw e.getCause().getCause();
    }
}
Also used : IpcSenderService(com.nextdoor.bender.ipc.IpcSenderService) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) 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

IpcSenderService (com.nextdoor.bender.ipc.IpcSenderService)7 TestContext (com.nextdoor.bender.aws.TestContext)6 Test (org.junit.Test)6 TransportException (com.nextdoor.bender.ipc.TransportException)5 ArrayList (java.util.ArrayList)4 DeserializationException (com.nextdoor.bender.deserializer.DeserializationException)3 OperationException (com.nextdoor.bender.operation.OperationException)3 SerializationException (com.nextdoor.bender.serializer.SerializationException)3 IOException (java.io.IOException)3 TransportFactory (com.nextdoor.bender.ipc.TransportFactory)2 SNSEvent (com.amazonaws.services.lambda.runtime.events.SNSEvent)1 AmazonS3URI (com.amazonaws.services.s3.AmazonS3URI)1 AmazonSNSClient (com.amazonaws.services.sns.AmazonSNSClient)1 AmazonSNSClientFactory (com.nextdoor.bender.aws.AmazonSNSClientFactory)1 ConfigurationException (com.nextdoor.bender.config.ConfigurationException)1 HandlerResources (com.nextdoor.bender.config.HandlerResources)1 Source (com.nextdoor.bender.config.Source)1 HandlerTest (com.nextdoor.bender.handler.HandlerTest)1 TransportBuffer (com.nextdoor.bender.ipc.TransportBuffer)1 ArrayTransportBuffer (com.nextdoor.bender.testutils.DummyTransportHelper.ArrayTransportBuffer)1