use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class SNSS3HandlerTest method testExceptionHandlingd.
@Test
public void testExceptionHandlingd() throws Throwable {
BaseHandler.CONFIG_FILE = "/com/nextdoor/bender/handler/config_test_sns.json";
TestContext ctx = new TestContext();
ctx.setFunctionName("unittest");
ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");
/*
* Invoke handler
*/
SNSS3Handler fhandler = (SNSS3Handler) getHandler();
fhandler.init(ctx);
IpcSenderService ipcSpy = spy(fhandler.getIpcService());
doThrow(new TransportException("expected")).when(ipcSpy).shutdown();
fhandler.setIpcService(ipcSpy);
AmazonSNSClient mockClient = mock(AmazonSNSClient.class);
AmazonSNSClientFactory mockClientFactory = mock(AmazonSNSClientFactory.class);
doReturn(mockClient).when(mockClientFactory).newInstance();
fhandler.snsClientFactory = mockClientFactory;
SNSEvent event = getTestEvent();
try {
fhandler.handler(event, ctx);
} catch (Exception e) {
}
verify(mockClient, times(1)).publish("foo", "basic_input.log", "SNSS3Handler Failed");
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class SNSS3HandlerTest method testSourceRegex.
@Test
public void testSourceRegex() 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(), ctx);
assertEquals(1, DummyTransportHelper.BufferedTransporter.output.size());
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class S3HandlerTest method testSourceRegex.
@Test
public void testSourceRegex() 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(), ctx);
assertEquals(1, DummyTransportHelper.BufferedTransporter.output.size());
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class StdoutTransportTest method testStdout.
@Test
public void testStdout() throws IllegalStateException, IOException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
System.setOut(new PrintStream(bo));
StdoutTransport transport = new StdoutTransport();
GenericTransportBuffer buf = new GenericTransportBuffer(1, false, new StdoutTransportSerializer());
InternalEvent event = new InternalEvent("junk", new TestContext(), 123);
event.setSerialized("junk");
buf.add(event);
transport.sendBatch(buf);
bo.flush();
String allWrittenLines = new String(bo.toByteArray());
assertEquals("junk\n", allWrittenLines);
}
use of com.nextdoor.bender.aws.TestContext in project bender by Nextdoor.
the class S3TransporterTest method testGzFilename.
@Test
public void testGzFilename() throws TransportException, IllegalStateException, IOException {
/*
* Create mock client, requests, and replies
*/
AmazonS3Client mockClient = getMockClient();
/*
* Fill buffer with mock data
*/
S3TransportBuffer buffer = new S3TransportBuffer(1000, true, new S3TransportSerializer());
InternalEvent mockIevent = mock(InternalEvent.class);
doReturn("foo").when(mockIevent).getSerialized();
/*
* Create transport
*/
Map<String, MultiPartUpload> multiPartUploads = new HashMap<String, MultiPartUpload>(0);
S3Transport transport = new S3Transport(mockClient, "bucket", "basepath/", true, multiPartUploads);
/*
* Do actual test
*/
buffer.add(mockIevent);
LinkedHashMap<String, String> partitions = new LinkedHashMap<String, String>();
partitions.put(S3Transport.FILENAME_KEY, "a_filename.gz");
ArgumentCaptor<UploadPartRequest> argument = ArgumentCaptor.forClass(UploadPartRequest.class);
transport.sendBatch(buffer, partitions, new TestContext());
verify(mockClient).uploadPart(argument.capture());
/*
* Check results
*/
assertEquals("basepath/a_filename.bz2", argument.getValue().getKey());
}
Aggregations