use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class OperationProcessorTest method testStatsLogging.
@Test
public void testStatsLogging() throws JsonSyntaxException, UnsupportedEncodingException, IOException, OperationException {
DummyOperationFactory mutatorFactory = new DummyOperationFactory();
OperationProcessor processor = new OperationProcessor(mutatorFactory);
/*
* Mock the Stat object
*/
Stat runtimeStat = mock(Stat.class);
Stat successStat = mock(Stat.class);
Stat errorStat = mock(Stat.class);
processor.setRuntimeStat(runtimeStat);
processor.setSuccessCountStat(successStat);
processor.setErrorCountStat(errorStat);
InternalEvent ievent = new InternalEvent("foo", null, 1);
ievent.setEventObj(new DummyDeserializerHelper.DummyDeserializedEvent("test"));
Stream<InternalEvent> stream = processor.perform(Stream.of(ievent));
List<InternalEvent> output = stream.collect(Collectors.toList());
/*
* Verify start, stop, increment success count, and never increment error count.
*/
verify(runtimeStat, times(1)).start();
verify(runtimeStat, times(1)).stop();
verify(successStat, times(1)).increment();
verify(errorStat, never()).increment();
/*
* Verify contents of output stream
*/
assertEquals(1, output.size());
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class PartitionOperationTest method testOperationThroughProcessor.
@Test
public void testOperationThroughProcessor() {
List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
List<String> sources = Arrays.asList("foo");
PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING);
partitionSpecs.add(spec);
PartitionOperation op = new PartitionOperation(partitionSpecs);
InternalEvent ievent = new InternalEvent("foo", null, 1);
DummyDeserializedEvent devent = spy(new DummyDeserializedEvent(""));
ievent.setEventObj(devent);
doReturn("baz").when(devent).getField("foo");
DummyOperationFactory opFact = new DummyOperationFactory(op);
OperationProcessor opProc = new OperationProcessor(opFact);
opProc.perform(Stream.of(ievent)).count();
LinkedHashMap<String, String> actual = ievent.getPartitions();
LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1);
expected.put("foo", "baz");
assertEquals(expected, actual);
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class DropArraysMutatorTest method testMutatePayload.
@Test
public void testMutatePayload() throws JsonSyntaxException, IOException, OperationException {
JsonParser parser = new JsonParser();
JsonElement input = parser.parse(getResourceString("basic_input.json"));
String expectedOutput = getResourceString("basic_output_drop_arrays.json");
DummpyEvent devent = new DummpyEvent();
devent.payload = input.getAsJsonObject();
DropArraysOperation operation = new DropArraysOperation();
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
operation.perform(ievent);
assertEquals(expectedOutput, input.toString());
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class PayloadOperationTest method testNullPayload.
@Test
public void testNullPayload() {
KeyNameOperation operation = new KeyNameOperation();
DummpyEvent devent = new DummpyEvent();
devent.payload = null;
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
InternalEvent output = operation.perform(ievent);
assertEquals(null, output);
}
use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.
the class FlattenOperationTest method testMutatePayload.
@Test
public void testMutatePayload() throws JsonSyntaxException, IOException, OperationException {
JsonParser parser = new JsonParser();
JsonElement input = parser.parse(getResourceString("flatten_input.json"));
String expectedOutput = getResourceString("flatten_output.json");
DummpyEvent devent = new DummpyEvent();
devent.payload = input.getAsJsonObject();
FlattenOperation operation = new FlattenOperation(".");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
operation.perform(ievent);
assertEquals(parser.parse(expectedOutput), input);
}
Aggregations