AllChannelMapExtractor implements MapExtractor { @Override public Map<String, Value> extract(EvaluationContext context) { try { return context.get().getChannels().stream().collect(Collectors.toMap( channel -> channel, channel -> context.get().getValue(channel) )); } catch (Exception e) { logger.warn("could not extract all channel values", e); return Collections.emptyMap(); } } AllChannelMapExtractor(Set<String> channels); @Override Map<String, Value> extract(EvaluationContext context); @Override Set<String> getChannelIdentifiers();  }
@Test public void extract() { Map<String, Value> results = extractor.extract(context); assertEquals(3, results.size()); assertEquals(1L, (long)results.get("test1").getAsLong()); assertEquals(2L, (long)results.get("test2").getAsLong()); assertEquals(3L, (long)results.get("test3").getAsLong()); results = clone.extract(context); assertEquals(3, results.size()); assertEquals(1L, (long)results.get("test1").getAsLong()); assertEquals(2L, (long)results.get("test2").getAsLong()); assertEquals(3L, (long)results.get("test3").getAsLong()); }
@Test public void extractNoValues(){ MRecord record2 = UntypedValues.builder().source("source").timestamp(123L).values(Collections.emptyMap()).build(); EvaluationContext<MRecord> context2 = new SimpleEvaluationContext<>(record2); Map<String, Value> extract = extractor.extract(context2); assertEquals(0, extract.size()); }