Search in sources :

Example 26 with TestContext

use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.

the class BaseHandlerTest method testDeserializationException.

@Test
public void testDeserializationException() throws HandlerException {
    BaseHandler.CONFIG_FILE = "/config/handler_config.json";
    handler.skipWriteStats = true;
    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);
    DeserializerProcessor proc = handler.sources.get(0).getDeserProcessor();
    Deserializer deserSpy = spy(proc.getDeserializer());
    doThrow(new DeserializationException("expected")).when(deserSpy).deserialize(anyString());
    proc.setDeserializer(deserSpy);
    handler.handler(events, context);
    assertEquals(1, proc.getErrorCountStat().getValue());
}
Also used : Deserializer(com.nextdoor.bender.deserializer.Deserializer) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) DeserializerProcessor(com.nextdoor.bender.deserializer.DeserializerProcessor) DeserializationException(com.nextdoor.bender.deserializer.DeserializationException) Test(org.junit.Test)

Example 27 with TestContext

use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.

the class BaseHandlerTest method testMissingConfig.

@Test(expected = HandlerException.class)
public void testMissingConfig() throws HandlerException {
    BaseHandler.CONFIG_FILE = "/config/missing.json";
    List<DummyEvent> events = new ArrayList<DummyEvent>(1);
    TestContext context = new TestContext();
    context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag");
    handler.handler(events, context);
}
Also used : TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 28 with TestContext

use of com.nextdoor.bender.aws.TestContext 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 29 with TestContext

use of com.nextdoor.bender.aws.TestContext 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)

Example 30 with TestContext

use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.

the class BaseHandlerTest method testBadConfig.

@Test(expected = HandlerException.class)
public void testBadConfig() throws HandlerException {
    BaseHandler.CONFIG_FILE = "/config/handler_config_bad.json";
    List<DummyEvent> events = new ArrayList<DummyEvent>(1);
    TestContext context = new TestContext();
    context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag");
    handler.handler(events, context);
}
Also used : TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

TestContext (com.nextdoor.bender.aws.TestContext)37 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)19 InternalEvent (com.nextdoor.bender.InternalEvent)10 HashMap (java.util.HashMap)10 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)9 UploadPartRequest (com.amazonaws.services.s3.model.UploadPartRequest)9 LinkedHashMap (java.util.LinkedHashMap)9 DeserializationException (com.nextdoor.bender.deserializer.DeserializationException)6 IpcSenderService (com.nextdoor.bender.ipc.IpcSenderService)6 TransportException (com.nextdoor.bender.ipc.TransportException)6 HandlerTest (com.nextdoor.bender.handler.HandlerTest)5 OperationException (com.nextdoor.bender.operation.OperationException)4 IOException (java.io.IOException)4 UploadPartResult (com.amazonaws.services.s3.model.UploadPartResult)3 Deserializer (com.nextdoor.bender.deserializer.Deserializer)3 DeserializerProcessor (com.nextdoor.bender.deserializer.DeserializerProcessor)3 SerializationException (com.nextdoor.bender.serializer.SerializationException)3 S3EventNotification (com.amazonaws.services.s3.event.S3EventNotification)2 BaseHandler (com.nextdoor.bender.handler.BaseHandler)2