Search in sources :

Example 6 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class OperationProcessorTest method testNullPayloadFiltering.

@Test
public void testNullPayloadFiltering() throws JsonSyntaxException, UnsupportedEncodingException, IOException, OperationException {
    /*
     * Setup mocks for test
     */
    DummyOperation op = spy(new DummyOperation());
    InternalEvent retEvent = new InternalEvent("foo", null, 1);
    retEvent.setEventObj(new DummyDeserializerHelper.DummyDeserializedEvent(null));
    when(op.perform(any(InternalEvent.class))).thenReturn(retEvent);
    DummyOperationFactory operationFactory = new DummyOperationFactory(op);
    OperationProcessor processor = new OperationProcessor(operationFactory);
    /*
     * Do call
     */
    Stream<InternalEvent> stream = processor.perform(Stream.of(new InternalEvent("foo", null, 1)));
    List<InternalEvent> output = stream.collect(Collectors.toList());
    /*
     * Verify nothing came out
     */
    assertEquals(0, output.size());
}
Also used : DummyDeserializerHelper(com.nextdoor.bender.testutils.DummyDeserializerHelper) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) DummyOperation(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 7 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class OperationProcessorTest method testNullDeserializedEventFiltering.

@Test
public void testNullDeserializedEventFiltering() throws JsonSyntaxException, UnsupportedEncodingException, IOException, OperationException {
    /*
     * Setup mocks for test
     */
    DummyOperation op = spy(new DummyOperation());
    InternalEvent retEvent = new InternalEvent("foo", null, 1);
    retEvent.setEventObj(null);
    when(op.perform(any(InternalEvent.class))).thenReturn(retEvent);
    DummyOperationFactory operationFactory = new DummyOperationFactory(op);
    OperationProcessor processor = new OperationProcessor(operationFactory);
    /*
     * Do call
     */
    Stream<InternalEvent> stream = processor.perform(Stream.of(new InternalEvent("foo", null, 1)));
    List<InternalEvent> output = stream.collect(Collectors.toList());
    /*
     * Verify nothing came out
     */
    assertEquals(0, output.size());
}
Also used : DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) DummyOperation(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 8 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class OperationProcessorTest method testNullInternalEventFiltering.

@Test
public void testNullInternalEventFiltering() throws JsonSyntaxException, UnsupportedEncodingException, IOException, OperationException {
    /*
     * Setup mocks for test
     */
    DummyOperation op = spy(new DummyOperation());
    when(op.perform(any(InternalEvent.class))).thenReturn(null);
    DummyOperationFactory operationFactory = new DummyOperationFactory(op);
    OperationProcessor processor = new OperationProcessor(operationFactory);
    /*
     * Do call
     */
    Stream<InternalEvent> stream = processor.perform(Stream.of(new InternalEvent("foo", null, 1)));
    List<InternalEvent> output = stream.collect(Collectors.toList());
    /*
     * Verify nothing came out
     */
    assertEquals(0, output.size());
}
Also used : DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) DummyOperation(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 9 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class PartitionOperationTest method testGetEvaluatedPartitionsStatic.

@Test
public void testGetEvaluatedPartitionsStatic() {
    List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
    List<String> sources = Arrays.asList("foo");
    PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STATIC, "123", 0);
    partitionSpecs.add(spec);
    PartitionOperation op = new PartitionOperation(partitionSpecs);
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyDeserializedEvent devent = new DummyDeserializedEvent("");
    ievent.setEventObj(devent);
    op.perform(ievent);
    LinkedHashMap<String, String> actual = ievent.getPartitions();
    LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1);
    expected.put("foo", "123");
    assertEquals(expected, actual);
}
Also used : DummyDeserializedEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializedEvent) ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 10 with InternalEvent

use of com.nextdoor.bender.InternalEvent in project bender by Nextdoor.

the class OperationProcessorTest method testStatsLoggingOnError.

@Test
public void testStatsLoggingOnError() {
    DummyOperation operation = mock(DummyOperation.class);
    DummyOperationFactory mutatorFactory = new DummyOperationFactory(operation);
    OperationProcessor processor = new OperationProcessor(mutatorFactory);
    InternalEvent ievent = new InternalEvent("a", null, 1);
    doThrow(new OperationException("Expceted")).when(operation).perform(ievent);
    /*
     * 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);
    Stream<InternalEvent> stream = processor.perform(Stream.of(ievent));
    List<InternalEvent> output = stream.collect(Collectors.toList());
    /*
     * Verify start, stop are called, increment error count and never increment success count.
     */
    verify(runtimeStat, times(1)).start();
    verify(runtimeStat, times(1)).stop();
    verify(successStat, never()).increment();
    verify(errorStat, times(1)).increment();
    /*
     * Verify contents of output stream
     */
    assertEquals(0, output.size());
}
Also used : Stat(com.nextdoor.bender.monitoring.Stat) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) DummyOperation(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperation) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

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