Search in sources :

Example 6 with TestContext

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

the class S3InternalEventTest method testAppendFilename.

@Test
public void testAppendFilename() {
    TestContext context = new TestContext();
    context.setAwsRequestId("req_id");
    S3InternalEvent ievent = new S3InternalEvent("foo", context, 0, "file", "bucket", "v1");
    ievent.setEventObj(null);
    Map<String, String> expected = new HashMap<String, String>(1);
    expected.put(S3InternalEvent.FILENAME_PARTITION, DigestUtils.sha1Hex("file"));
    assertEquals(expected, ievent.getPartitions());
}
Also used : HashMap(java.util.HashMap) TestContext(com.nextdoor.bender.aws.TestContext) Test(org.junit.Test)

Example 7 with TestContext

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

the class SNSS3HandlerTest method testSourceRegexFail.

@Test
public void testSourceRegexFail() throws Throwable {
    BaseHandler.CONFIG_FILE = "/com/nextdoor/bender/handler/config_s3_source.json";
    TestContext ctx = new TestContext();
    ctx.setFunctionName("unittest");
    ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");
    SNSS3Handler handler = (SNSS3Handler) getHandler();
    handler.init(ctx);
    handler.handler(getTestEvent("foo", false), ctx);
    assertEquals(0, DummyTransportHelper.BufferedTransporter.output.size());
}
Also used : TestContext(com.nextdoor.bender.aws.TestContext) HandlerTest(com.nextdoor.bender.handler.HandlerTest) Test(org.junit.Test)

Example 8 with TestContext

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

the class HandlerTest method testBasicEndtoEnd.

@Test
public void testBasicEndtoEnd() throws Exception {
    TestContext ctx = new TestContext();
    ctx.setFunctionName("unittest");
    ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");
    /*
     * Invoke handler
     */
    Handler<T> fhandler = getHandler();
    T event = getTestEvent();
    fhandler.handler(event, ctx);
    /*
     * Load output
     */
    assertEquals(1, DummyTransportHelper.BufferedTransporter.output.size());
    String actual = DummyTransportHelper.BufferedTransporter.output.get(0);
    /*
     * Load expected
     */
    String expected = IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream("basic_output.json"), "UTF-8"));
    assertEquals(expected, actual);
}
Also used : InputStreamReader(java.io.InputStreamReader) TestContext(com.nextdoor.bender.aws.TestContext) Test(org.junit.Test)

Example 9 with TestContext

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

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

the class BaseHandlerTest method testEndToEnd.

@Test
public void testEndToEnd() throws HandlerException {
    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.handler(events, context);
    /*
     * Verify Events made it all the way through
     */
    assertEquals(2, BufferedTransporter.output.size());
    assertEquals("foo", BufferedTransporter.output.get(0));
    assertEquals("bar", BufferedTransporter.output.get(1));
}
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