Search in sources :

Example 21 with TestContext

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

the class BaseHandlerTest method testFilterFailedDeserialization.

@Test
public void testFilterFailedDeserialization() 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());
    doThrow(new DeserializationException("expected")).when(deserSpy).deserialize(anyString());
    proc.setDeserializer(deserSpy);
    handler.handler(events, context);
    assertEquals(0, BufferedTransporter.output.size());
}
Also used : Deserializer(com.nextdoor.bender.deserializer.Deserializer) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) DeserializerProcessor(com.nextdoor.bender.deserializer.DeserializerProcessor) DeserializationException(com.nextdoor.bender.deserializer.DeserializationException) Test(org.junit.Test)

Example 22 with TestContext

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

the class BaseHandlerTest method testSerializationException.

@Test
public void testSerializationException() throws HandlerException, SerializationException {
    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);
    Serializer serSpy = spy(handler.ser.getSerializer());
    doThrow(new DeserializationException("")).when(serSpy).serialize(any());
    handler.ser.setSerializer(serSpy);
    handler.handler(events, context);
    assertEquals(1, handler.ser.getErrorCountStat().getValue());
}
Also used : TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) DeserializationException(com.nextdoor.bender.deserializer.DeserializationException) Serializer(com.nextdoor.bender.serializer.Serializer) Test(org.junit.Test)

Example 23 with TestContext

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

the class BaseHandlerTest method testMultipleOperationsConfig.

@Test
public void testMultipleOperationsConfig() throws HandlerException {
    BaseHandler.CONFIG_FILE = "/config/handler_config_two_operations.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);
    List<OperationProcessor> operationProcessores = handler.sources.get(0).getOperationProcessors();
    for (int i = 0; i < operationProcessores.size(); i++) {
        OperationProcessor operationProcessor = spy(operationProcessores.get(i));
        operationProcessores.set(i, operationProcessor);
    }
    handler.handler(events, context);
    /*
     * 2 operations specified in the config file
     */
    verify(operationProcessores.get(0), times(1)).perform(any());
    verify(operationProcessores.get(1), times(1)).perform(any());
}
Also used : TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) Test(org.junit.Test)

Example 24 with TestContext

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

the class BaseHandlerTest method testContains.

@Test
public void testContains() throws HandlerException {
    BaseHandler.CONFIG_FILE = "/config/handler_config_contains.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));
}
Also used : TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 25 with TestContext

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

the class BaseHandlerTest method testLatestTagConfig.

@Test
public void testLatestTagConfig() throws HandlerException {
    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("/config/$LATEST.json", handler.config.getConfigFile());
}
Also used : TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) 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