Search in sources :

Example 31 with TestContext

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");
}
Also used : IpcSenderService(com.nextdoor.bender.ipc.IpcSenderService) AmazonSNSClientFactory(com.nextdoor.bender.aws.AmazonSNSClientFactory) TestContext(com.nextdoor.bender.aws.TestContext) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) TransportException(com.nextdoor.bender.ipc.TransportException) TransportException(com.nextdoor.bender.ipc.TransportException) SNSEvent(com.amazonaws.services.lambda.runtime.events.SNSEvent) HandlerTest(com.nextdoor.bender.handler.HandlerTest) Test(org.junit.Test)

Example 32 with TestContext

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());
}
Also used : TestContext(com.nextdoor.bender.aws.TestContext) HandlerTest(com.nextdoor.bender.handler.HandlerTest) Test(org.junit.Test)

Example 33 with TestContext

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());
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) TestContext(com.nextdoor.bender.aws.TestContext) BaseHandler(com.nextdoor.bender.handler.BaseHandler) HandlerTest(com.nextdoor.bender.handler.HandlerTest) Test(org.junit.Test)

Example 34 with TestContext

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);
}
Also used : PrintStream(java.io.PrintStream) TestContext(com.nextdoor.bender.aws.TestContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericTransportBuffer(com.nextdoor.bender.ipc.generic.GenericTransportBuffer) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 35 with TestContext

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());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestContext(com.nextdoor.bender.aws.TestContext) UploadPartRequest(com.amazonaws.services.s3.model.UploadPartRequest) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) 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