@Override public void setConf(AbstractConfig config) { this.config = (ForkOperationConfig) config; List<List<OperationProcessor>> processors = new ArrayList<List<OperationProcessor>>(); OperationFactoryFactory off = new OperationFactoryFactory(); for (Fork fork : this.config.getForks()) { List<OperationProcessor> processorsInFork = new ArrayList<OperationProcessor>(); for (OperationConfig opConfig : fork.getOperations()) { try { processorsInFork.add(new OperationProcessor(off.getFactory(opConfig))); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } processors.add(processorsInFork); } this.processors = processors; }
@Override public void setConf(AbstractConfig config) { this.config = (ForkOperationConfig) config; List<List<OperationProcessor>> processors = new ArrayList<List<OperationProcessor>>(); OperationFactoryFactory off = new OperationFactoryFactory(); for (Fork fork : this.config.getForks()) { List<OperationProcessor> processorsInFork = new ArrayList<OperationProcessor>(); for (OperationConfig opConfig : fork.getOperations()) { try { processorsInFork.add(new OperationProcessor(off.getFactory(opConfig))); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } processors.add(processorsInFork); } this.processors = processors; }
@Override public void setConf(AbstractConfig config) { this.config = (ConditionalOperationConfig) config; List<Pair<FilterOperation, List<OperationProcessor>>> cases = new ArrayList<Pair<FilterOperation, List<OperationProcessor>>>(); OperationFactoryFactory off = new OperationFactoryFactory(); for (Condition caze : this.config.getConditions()) { List<OperationProcessor> processorsInCase = new ArrayList<OperationProcessor>(); /* * Create {@OperationProcessor}s from configs */ for (OperationConfig opConfig : caze.getOperations()) { try { processorsInCase.add(new OperationProcessor(off.getFactory(opConfig))); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } FilterOperation filter; try { filter = (FilterOperation) off.getFactory(caze.getCondition()).newInstance(); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } cases.add( new ImmutablePair<FilterOperation, List<OperationProcessor>>(filter, processorsInCase)); } this.cases = cases; }
@Override public void setConf(AbstractConfig config) { this.config = (ConditionalOperationConfig) config; List<Pair<FilterOperation, List<OperationProcessor>>> cases = new ArrayList<Pair<FilterOperation, List<OperationProcessor>>>(); OperationFactoryFactory off = new OperationFactoryFactory(); for (Condition caze : this.config.getConditions()) { List<OperationProcessor> processorsInCase = new ArrayList<OperationProcessor>(); /* * Create {@OperationProcessor}s from configs */ for (OperationConfig opConfig : caze.getOperations()) { try { processorsInCase.add(new OperationProcessor(off.getFactory(opConfig))); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } FilterOperation filter; try { filter = (FilterOperation) off.getFactory(caze.getCondition()).newInstance(); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } cases.add( new ImmutablePair<FilterOperation, List<OperationProcessor>>(filter, processorsInCase)); } this.cases = cases; }
public Source(SourceConfig config) throws ClassNotFoundException { this.sourceRegex = Pattern.compile(config.getSourceRegex()); this.sourceName = config.getName(); DeserializerFactory dFactory = dff.getFactory(config.getDeserializerConfig()); this.deserProcessor = new DeserializerProcessor(dFactory.newInstance()); List<OperationConfig> operationConfigs = config.getOperationConfigs(); if (operationConfigs.size() > 0) { OperationFactoryFactory off = new OperationFactoryFactory(); for (OperationConfig operationConfig : operationConfigs) { this.operationProcessors.add(new OperationProcessor(off.getFactory(operationConfig))); } } this.containsStrings.addAll(config.getContainsStrings()); for (String strRegex : config.getRegexPatterns()) { this.regexPatterns.add(Pattern.compile(strRegex)); } }
public Source(SourceConfig config) throws ClassNotFoundException { this.sourceRegex = Pattern.compile(config.getSourceRegex()); this.sourceName = config.getName(); DeserializerFactory dFactory = dff.getFactory(config.getDeserializerConfig()); this.deserProcessor = new DeserializerProcessor(dFactory.newInstance()); List<OperationConfig> operationConfigs = config.getOperationConfigs(); if (operationConfigs.size() > 0) { OperationFactoryFactory off = new OperationFactoryFactory(); for (OperationConfig operationConfig : operationConfigs) { this.operationProcessors.add(new OperationProcessor(off.getFactory(operationConfig))); } } this.containsStrings.addAll(config.getContainsStrings()); for (String strRegex : config.getRegexPatterns()) { this.regexPatterns.add(Pattern.compile(strRegex)); } }
@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()); }
@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 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()); }
@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()); }
@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()); }