@Test public void match_statement_with_where_clause() { final MatchTransformerImpl matchStmt = new MatchTransformerImpl( singletonMap(IDENT, wildcard_matcher), EMPTY_MAP, Optional.of(new MatchStatement.LookBackExposingPredicate() { @Override public ExpressionLookBack getLookBack() { return ExpressionLookBack.EMPTY; } @Override public boolean test(Context ctx) { return is_tag_group1.apply(ctx) .streamValues() .map(MetricValue::asBool) .flatMap((Optional<Boolean> m) -> m.map(Stream::of).orElseGet(Stream::empty)) .anyMatch((Boolean bool) -> bool != false); } }), Stream.of(group_rule)); matchStmt.transform(ctx); Mockito.verify(group1, Mockito.atLeastOnce()).getGroup(); Mockito.verify(group2, Mockito.atLeastOnce()).getGroup(); Mockito.verify(group3, Mockito.atLeastOnce()).getGroup(); Mockito.verify(group1, Mockito.times(1)).findMetric(METRIC); Mockito.verify(group2, Mockito.times(1)).findMetric(METRIC); Mockito.verify(group3, Mockito.times(0)).findMetric(METRIC); assertEquals(2, group_rule.getInvocations()); }
@Override public void transform(Context parent) { decorator_ .map(Stream.of( (MutableContext mctx) -> { }), parent) .map(application -> { final MutableContext ctx = new MutableContext(parent); application.accept(ctx); return ctx; }) .filter(where_clause_.orElse(CONTEXT_TAUTOLOGY)) .forEach(this::play_rules_); }
MatchTransformerImpl implements TimeSeriesTransformer { @Override public void transform(Context parent) { decorator_ .map(Stream.of( (MutableContext mctx) -> { }), parent) .map(application -> { final MutableContext ctx = new MutableContext(parent); application.accept(ctx); return ctx; }) .filter(where_clause_.orElse(CONTEXT_TAUTOLOGY)) .forEach(this::play_rules_); } }
MatchTransformerImpl implements TimeSeriesTransformer { @Override public void transform(Context parent) { decorator_ .map(Stream.of( (MutableContext mctx) -> { }), parent) .map(application -> { final MutableContext ctx = new MutableContext(parent); application.accept(ctx); return ctx; }) .filter(where_clause_.orElse(CONTEXT_TAUTOLOGY)) .forEach(this::play_rules_); } MatchTransformerImpl(Map<String, PathMatcher> groupNameMatchers,
                                Map<IdentifierPair, MetricMatcher> metricNameMatchers,
                                Optional<MatchStatement.LookBackExposingPredicate> where_clause,
                                Stream<TimeSeriesTransformer> rules); }
MatchTransformerImpl implements TimeSeriesTransformer { @Override public void transform(Context parent) { decorator_ .map(Stream.of( (MutableContext mctx) -> { }), parent) .map(application -> { final MutableContext ctx = new MutableContext(parent); application.accept(ctx); return ctx; }) .filter(where_clause_.orElse(CONTEXT_TAUTOLOGY)) .forEach(this::play_rules_); } MatchTransformerImpl(Map<String, PathMatcher> groupNameMatchers,
                                Map<IdentifierPair, MetricMatcher> metricNameMatchers,
                                Optional<MatchStatement.LookBackExposingPredicate> where_clause,
                                Stream<TimeSeriesTransformer> rules); @Override void transform(Context parent); @Override ExpressionLookBack getLookBack(); }
MatchTransformerImpl implements TimeSeriesTransformer { @Override public void transform(Context parent) { decorator_ .map(Stream.of( (MutableContext mctx) -> { }), parent) .map(application -> { final MutableContext ctx = new MutableContext(parent); application.accept(ctx); return ctx; }) .filter(where_clause_.orElse(CONTEXT_TAUTOLOGY)) .forEach(this::play_rules_); } MatchTransformerImpl(Map<String, PathMatcher> groupNameMatchers,
                                Map<IdentifierPair, MetricMatcher> metricNameMatchers,
                                Optional<MatchStatement.LookBackExposingPredicate> where_clause,
                                Stream<TimeSeriesTransformer> rules); @Override void transform(Context parent); @Override ExpressionLookBack getLookBack();  }