Search in sources :

Example 46 with InternalEvent

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());
}
Also used : Stat(com.nextdoor.bender.monitoring.Stat) DummyDeserializerHelper(com.nextdoor.bender.testutils.DummyDeserializerHelper) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 47 with InternalEvent

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);
}
Also used : DummyDeserializedEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent) ArrayList(java.util.ArrayList) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 48 with InternalEvent

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());
}
Also used : JsonElement(com.google.gson.JsonElement) DropArraysOperation(com.nextdoor.bender.operation.json.value.DropArraysOperation) JsonParser(com.google.gson.JsonParser) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test) OperationTest(com.nextdoor.bender.operations.json.OperationTest)

Example 49 with InternalEvent

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);
}
Also used : KeyNameOperation(com.nextdoor.bender.operation.json.key.KeyNameOperation) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 50 with InternalEvent

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);
}
Also used : FlattenOperation(com.nextdoor.bender.operation.json.key.FlattenOperation) JsonElement(com.google.gson.JsonElement) JsonParser(com.google.gson.JsonParser) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test) OperationTest(com.nextdoor.bender.operations.json.OperationTest)

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)68 Test (org.junit.Test)67 LinkedHashMap (java.util.LinkedHashMap)17 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 TestContext (com.nextdoor.bender.aws.TestContext)10 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)9 UploadPartRequest (com.amazonaws.services.s3.model.UploadPartRequest)9 DummyDeserializedEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent)9 JsonElement (com.google.gson.JsonElement)7 JsonParser (com.google.gson.JsonParser)7 OperationTest (com.nextdoor.bender.operations.json.OperationTest)7 DummyOperationFactory (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory)6 GenericTransportBuffer (com.nextdoor.bender.ipc.generic.GenericTransportBuffer)5 GenericTransportSerializer (com.nextdoor.bender.ipc.generic.GenericTransportSerializer)5 DummyOperation (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation)4 UploadPartResult (com.amazonaws.services.s3.model.UploadPartResult)3 Stat (com.nextdoor.bender.monitoring.Stat)3 KeyNameOperation (com.nextdoor.bender.operation.json.key.KeyNameOperation)3 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)3