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());
}
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());
}
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);
}
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();
}
}
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));
}
Aggregations