Search in sources :

Example 11 with TestContext

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

the class BaseHandlerTest method testOperationException.

@Test
public void testOperationException() 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);
    List<OperationProcessor> operationProcessors = handler.sources.get(0).getOperationProcessors();
    for (OperationProcessor operationProcessor : operationProcessors) {
        BaseOperation operation = spy(operationProcessor.getOperation());
        doThrow(new OperationException("expected")).when(operation).perform(any());
        operationProcessor.setOperation(operation);
    }
    handler.handler(events, context);
    assertEquals(1, operationProcessors.get(0).getErrorCountStat().getValue());
}
Also used : TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) BaseOperation(com.nextdoor.bender.operation.BaseOperation) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) OperationException(com.nextdoor.bender.operation.OperationException) Test(org.junit.Test)

Example 12 with TestContext

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

the class BaseHandlerTest method testTagConfig.

@Test
public void testTagConfig() throws HandlerException {
    List<DummyEvent> events = new ArrayList<DummyEvent>(1);
    TestContext context = new TestContext();
    context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:staging");
    handler.handler(events, context);
    assertEquals("/config/staging.json", handler.config.getConfigFile());
}
Also used : TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with TestContext

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

the class BaseHandlerTest method testGeneralTransportExceptionOnShutdown.

@Test(expected = TransportException.class)
public void testGeneralTransportExceptionOnShutdown() throws Throwable {
    BaseHandler.CONFIG_FILE = "/config/handler_config.json";
    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);
    IpcSenderService spy = spy(handler.getIpcService());
    handler.setIpcService(spy);
    doThrow(new TransportException("expected")).when(spy).shutdown();
    try {
        handler.handler(events, context);
    } catch (Exception e) {
        throw e.getCause().getCause();
    }
}
Also used : IpcSenderService(com.nextdoor.bender.ipc.IpcSenderService) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) TransportException(com.nextdoor.bender.ipc.TransportException) TransportException(com.nextdoor.bender.ipc.TransportException) IOException(java.io.IOException) DeserializationException(com.nextdoor.bender.deserializer.DeserializationException) SerializationException(com.nextdoor.bender.serializer.SerializationException) OperationException(com.nextdoor.bender.operation.OperationException) Test(org.junit.Test)

Example 14 with TestContext

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

the class BaseHandlerTest method testEndToEndWithNoOperations.

@Test
public void testEndToEndWithNoOperations() throws HandlerException {
    BaseHandler.CONFIG_FILE = "/config/handler_config_no_operations.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)

Example 15 with TestContext

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

the class S3TransporterTest method testUnpartitioned.

@Test
public void testUnpartitioned() throws TransportException, IllegalStateException, IOException {
    /*
     * Create mock client, requets, and replies
     */
    AmazonS3Client mockClient = getMockClient();
    /*
     * Fill buffer with mock data
     */
    S3TransportBuffer buffer = new S3TransportBuffer(1000, false, 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", false, multiPartUploads);
    /*
     * Do actual test
     */
    buffer.add(mockIevent);
    LinkedHashMap<String, String> partitions = new LinkedHashMap<String, String>();
    partitions.put(S3Transport.FILENAME_KEY, "a_filename");
    ArgumentCaptor<UploadPartRequest> argument = ArgumentCaptor.forClass(UploadPartRequest.class);
    transport.sendBatch(buffer, partitions, new TestContext());
    verify(mockClient).uploadPart(argument.capture());
    /*
     * Check results
     */
    assertEquals("bucket", argument.getValue().getBucketName());
    assertEquals("basepath/a_filename", argument.getValue().getKey());
    assertEquals(1, argument.getValue().getPartNumber());
    // foo\n
    assertEquals(4, argument.getValue().getPartSize());
    assertEquals("123", argument.getValue().getUploadId());
}
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