use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.
the class ArraySplitOperationTest method testNonArray.
@Test(expected = OperationException.class)
public void testNonArray() throws JsonSyntaxException, UnsupportedEncodingException, IOException {
JsonParser parser = new JsonParser();
TestContext t = new TestContext();
t.setFunctionName("foo");
LambdaContext lctx = new LambdaContext(t);
JsonElement input = parser.parse(getResourceString("array_input.json"));
GenericJsonEvent devent = new GenericJsonEvent(input.getAsJsonObject());
ArraySplitOperation operation = new ArraySplitOperation("$.arr[0]");
InternalEvent ievent = new InternalEvent("", lctx, 123);
ievent.setEventObj(devent);
ievent.setEventTime(124);
List<InternalEvent> events = operation.perform(ievent);
}
use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.
the class ArraySplitOperationTest method testArraySplitWithFieldsToKeep.
@Test
public void testArraySplitWithFieldsToKeep() throws IOException {
TestContext t = new TestContext();
t.setFunctionName("foo");
LambdaContext lctx = new LambdaContext(t);
JsonElement input = JsonParser.parseString(getResourceString("array_input_kinesis_format.json"));
GenericJsonEvent devent = new GenericJsonEvent(input.getAsJsonObject());
List<String> fieldsToKeep = Arrays.asList("owner", "logGroup", "logStream");
ArraySplitOperation operation = new ArraySplitOperation("$.logEvents", fieldsToKeep);
InternalEvent ievent = new InternalEvent("", lctx, 123);
ievent.setEventObj(devent);
ievent.setEventTime(124);
List<InternalEvent> events = operation.perform(ievent);
assertEquals(4, events.size());
JsonElement actual = JsonParser.parseString(events.get(0).getEventString());
assertTrue(actual.getAsJsonObject().has("owner"));
assertTrue(actual.getAsJsonObject().has("logGroup"));
assertTrue(actual.getAsJsonObject().has("logStream"));
assertTrue(actual.getAsJsonObject().has("id"));
assertTrue(actual.getAsJsonObject().has("message"));
assertTrue(actual.getAsJsonObject().has("timestamp"));
actual = JsonParser.parseString(events.get(1).getEventString());
assertTrue(actual.getAsJsonObject().has("owner"));
assertTrue(actual.getAsJsonObject().has("logGroup"));
assertTrue(actual.getAsJsonObject().has("logStream"));
assertTrue(actual.getAsJsonObject().has("id"));
assertTrue(actual.getAsJsonObject().has("message"));
assertTrue(actual.getAsJsonObject().has("timestamp"));
actual = JsonParser.parseString(events.get(2).getEventString());
assertTrue(actual.getAsJsonObject().has("owner"));
assertTrue(actual.getAsJsonObject().has("logGroup"));
assertTrue(actual.getAsJsonObject().has("logStream"));
assertTrue(actual.getAsJsonObject().has("id"));
assertTrue(actual.getAsJsonObject().has("message"));
assertTrue(actual.getAsJsonObject().has("timestamp"));
actual = JsonParser.parseString(events.get(3).getEventString());
assertTrue(actual.getAsJsonObject().has("owner"));
assertTrue(actual.getAsJsonObject().has("logGroup"));
assertTrue(actual.getAsJsonObject().has("logStream"));
assertTrue(actual.getAsJsonObject().has("id"));
assertTrue(actual.getAsJsonObject().has("message"));
assertTrue(actual.getAsJsonObject().has("timestamp"));
}
use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.
the class ArraySplitOperationTest method testContextMatch.
@Test
public void testContextMatch() throws JsonSyntaxException, UnsupportedEncodingException, IOException {
JsonParser parser = new JsonParser();
TestContext t = new TestContext();
t.setFunctionName("foo");
LambdaContext lctx = new LambdaContext(t);
JsonElement input = parser.parse(getResourceString("array_input.json"));
GenericJsonEvent devent = new GenericJsonEvent(input.getAsJsonObject());
ArraySplitOperation operation = new ArraySplitOperation("$.arr");
InternalEvent ievent = new InternalEvent("", lctx, 1);
ievent.setEventObj(devent);
List<InternalEvent> actual = operation.perform(ievent);
assertEquals(lctx, actual.get(0).getCtx());
assertEquals(lctx, actual.get(1).getCtx());
assertEquals(lctx, actual.get(2).getCtx());
}
use of com.nextdoor.bender.LambdaContext 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 LambdaContext(new TestContext()), 123);
event.setSerialized("junk");
buf.add(event);
transport.sendBatch(buf);
bo.flush();
String allWrittenLines = new String(bo.toByteArray());
assertEquals("junk\n", allWrittenLines);
}
Aggregations