Search in sources :

Example 6 with DummyStringEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent in project bender by Nextdoor.

the class TimeOperationTest method testInvalidISO8601.

@Test(expected = OperationException.class)
public void testInvalidISO8601() throws FieldNotFoundException {
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyStringEvent devent = spy(new DummyStringEvent(""));
    ievent.setEventObj(devent);
    doReturn("note a date string").when(devent).getFieldAsString("foo");
    TimeOperation op = new TimeOperation("foo", TimeFieldType.ISO8601);
    op.perform(ievent);
}
Also used : DummyStringEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 7 with DummyStringEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent in project bender by Nextdoor.

the class TimeOperationTest method testValidTime.

@Test
public void testValidTime() throws FieldNotFoundException {
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyStringEvent devent = spy(new DummyStringEvent(""));
    ievent.setEventObj(devent);
    doReturn("1504728473").when(devent).getFieldAsString("foo");
    TimeOperation op = new TimeOperation("foo", TimeFieldType.SECONDS);
    op.perform(ievent);
    assertEquals(1504728473000l, ievent.getEventTime());
}
Also used : DummyStringEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 8 with DummyStringEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent in project bender by Nextdoor.

the class PartitionOperationTest method testGetEvaluatedPartitionsStringMultipleFieldsNull.

@Test(expected = OperationException.class)
public void testGetEvaluatedPartitionsStringMultipleFieldsNull() throws FieldNotFoundException {
    List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
    List<String> sources = Arrays.asList("one", "two");
    PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING);
    partitionSpecs.add(spec);
    PartitionOperation op = new PartitionOperation(partitionSpecs);
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyStringEvent devent = spy(new DummyStringEvent("baz"));
    ievent.setEventObj(devent);
    doThrow(FieldNotFoundException.class).doThrow(FieldNotFoundException.class).when(devent).getFieldAsString(any());
    try {
        op.perform(ievent);
    } catch (OperationException e) {
        assertEquals("unable to find value for partition 'foo'", e.getMessage());
        throw e;
    }
}
Also used : ArrayList(java.util.ArrayList) FieldNotFoundException(com.nextdoor.bender.deserializer.FieldNotFoundException) DummyStringEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent) OperationException(com.nextdoor.bender.operation.OperationException) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 9 with DummyStringEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent in project bender by Nextdoor.

the class PartitionOperationTest method testGetEvaluatedPartitionsStringMultipleFields.

@Test
public void testGetEvaluatedPartitionsStringMultipleFields() throws FieldNotFoundException {
    List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1);
    List<String> sources = Arrays.asList("one", "two");
    PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING);
    partitionSpecs.add(spec);
    PartitionOperation op = new PartitionOperation(partitionSpecs);
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    DummyStringEvent devent = spy(new DummyStringEvent(""));
    ievent.setEventObj(devent);
    doThrow(FieldNotFoundException.class).doReturn("5").when(devent).getFieldAsString(any());
    op.perform(ievent);
    LinkedHashMap<String, String> actual = ievent.getPartitions();
    LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1);
    expected.put("foo", "5");
    assertEquals(expected, actual);
}
Also used : ArrayList(java.util.ArrayList) FieldNotFoundException(com.nextdoor.bender.deserializer.FieldNotFoundException) DummyStringEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 10 with DummyStringEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent in project bender by Nextdoor.

the class PartitionOperationTest method testOperationThroughProcessor.

@Test
public void testOperationThroughProcessor() throws FieldNotFoundException {
    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);
    DummyStringEvent devent = spy(new DummyStringEvent(""));
    ievent.setEventObj(devent);
    doReturn("baz").when(devent).getFieldAsString("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 : ArrayList(java.util.ArrayList) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) DummyStringEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent) OperationProcessor(com.nextdoor.bender.operation.OperationProcessor) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)14 DummyStringEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyStringEvent)14 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)4 FieldNotFoundException (com.nextdoor.bender.deserializer.FieldNotFoundException)2 OperationException (com.nextdoor.bender.operation.OperationException)2 OperationProcessor (com.nextdoor.bender.operation.OperationProcessor)1 DummyOperationFactory (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory)1