new InternalEvent(elm.toString(), ievent.getCtx(), ievent.getArrivalTime()); DeserializedEvent newDeserEvent = new GenericJsonEvent(elm.getAsJsonObject()); newEvent.setEventObj(newDeserEvent); newEvent.setEventTime(ievent.getEventTime());
new InternalEvent(elm.toString(), ievent.getCtx(), ievent.getArrivalTime()); DeserializedEvent newDeserEvent = new GenericJsonEvent(elm.getAsJsonObject()); newEvent.setEventObj(newDeserEvent); newEvent.setEventTime(ievent.getEventTime());
@Test(expected = OperationException.class) public void testInvalidTime() throws FieldNotFoundException { InternalEvent ievent = new InternalEvent("foo", null, 1); DummyStringEvent devent = spy(new DummyStringEvent("")); ievent.setEventObj(devent); doReturn("-1").when(devent).getFieldAsString("foo"); TimeOperation op = new TimeOperation("foo", TimeFieldType.SECONDS); op.perform(ievent); }
@Test(expected = OperationException.class) public void testNullField() throws FieldNotFoundException { InternalEvent ievent = new InternalEvent("foo", null, 1); DummyStringEvent devent = spy(new DummyStringEvent("")); ievent.setEventObj(devent); doThrow(FieldNotFoundException.class).when(devent).getFieldAsString("foo"); TimeOperation op = new TimeOperation("foo", TimeFieldType.SECONDS); op.perform(ievent); } }
@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); }
@Test public void testGetEvaluatedPartitionsString() 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"); op.perform(ievent); LinkedHashMap<String, String> actual = ievent.getPartitions(); LinkedHashMap<String, String> expected = new LinkedHashMap<String, String>(1); expected.put("foo", "baz"); assertEquals(expected, actual); }
@Test public void testGetEvaluatedPartitionsStatic() { List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1); PartitionSpec spec = new PartitionSpec("foo", Collections.emptyList(), PartitionSpec.Interpreter.STATIC, "123", 0); partitionSpecs.add(spec); PartitionOperation op = new PartitionOperation(partitionSpecs); InternalEvent ievent = new InternalEvent("foo", null, 1); DummyStringEvent devent = new DummyStringEvent(""); 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); }
@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); } }
@Test(expected = OperationException.class) public void testGetEvaluatedPartitionsFieldNotFoundException() throws FieldNotFoundException { List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1); List<String> sources = Arrays.asList("one"); 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).when(devent).getFieldAsString(any()); try { op.perform(ievent); } catch (OperationException e) { assertEquals("unable to find value for partition 'foo'", e.getMessage()); throw e; } }
@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; } }
@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()); }
@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()); }
ievent.setEventObj(data); return ievent; }).filter(Objects::nonNull);
@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.DummyStringEvent(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()); } }
@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.DummyStringEvent("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()); }
ievent.setEventObj(data); return ievent; }).filter(Objects::nonNull);