Search in sources :

Example 1 with Deserializer

use of com.nextdoor.bender.deserializer.Deserializer 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());
}
Also used : Deserializer(com.nextdoor.bender.deserializer.Deserializer) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) DeserializerProcessor(com.nextdoor.bender.deserializer.DeserializerProcessor) Test(org.junit.Test)

Example 2 with Deserializer

use of com.nextdoor.bender.deserializer.Deserializer 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 3 with Deserializer

use of com.nextdoor.bender.deserializer.Deserializer in project bender by Nextdoor.

the class BaseHandlerTest method testDeserializationException.

@Test
public void testDeserializationException() 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(1, proc.getErrorCountStat().getValue());
}
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)

Aggregations

TestContext (com.nextdoor.bender.aws.TestContext)3 Deserializer (com.nextdoor.bender.deserializer.Deserializer)3 DeserializerProcessor (com.nextdoor.bender.deserializer.DeserializerProcessor)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 DeserializationException (com.nextdoor.bender.deserializer.DeserializationException)2