use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class BaseHandlerS3Test method testS3Config.
@Test
public void testS3Config() throws HandlerException {
BaseHandler handler = new DummyHandler();
handler.CONFIG_FILE = null;
handler.s3ClientFactory = this.clientFactory;
List<DummyEvent> events = new ArrayList<DummyEvent>(1);
TestContext context = new TestContext();
context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test");
handler.handler(events, context);
assertEquals("s3://" + S3_BUCKET + "/bender/config.json", handler.config.getConfigFile());
assertEquals("Test Events", handler.config.getSources().get(0).getName());
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class BaseHandlerTest method testRegex.
@Test
public void testRegex() throws HandlerException {
BaseHandler.CONFIG_FILE = "/config/handler_config_regex.json";
List<DummyEvent> events = new ArrayList<DummyEvent>(2);
events.add(new DummyEvent("foo", 0));
events.add(new DummyEvent("bar", 0));
events.add(new DummyEvent("loop", 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(1, BufferedTransporter.output.size());
assertEquals("bar", BufferedTransporter.output.get(0));
}
use of com.nextdoor.bender.aws.TestContext 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());
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class BaseHandlerTest method testFilterNullDeserialization.
@Test
public void testFilterNullDeserialization() 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());
when(deserSpy.deserialize(anyString())).thenReturn(null);
proc.setDeserializer(deserSpy);
handler.handler(events, context);
assertEquals(0, BufferedTransporter.output.size());
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class S3HandlerTest 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");
BaseHandler<S3EventNotification> handler = (BaseHandler) getHandler();
handler.init(ctx);
handler.handler(getTestEvent("foo", false), ctx);
assertEquals(0, DummyTransportHelper.BufferedTransporter.output.size());
}
Aggregations