Esempio n. 1
0
    def test_sliding_first_window_to_halt(self):
        predicate_a = BoboPredicateCallable(predicate_key_a_value_a)
        predicate_b = BoboPredicateCallable(predicate_key_a_value_b)
        predicate_c = BoboPredicateCallable(predicate_key_a_value_c)
        predicate_first_window = WindowSlidingFirst(
            interval_sec=range_sec)

        event_a = PrimitiveEvent(timestamp_low, {KEY: VAL_1})
        event_b = PrimitiveEvent(timestamp_mid, {KEY: VAL_2})
        event_c = PrimitiveEvent(timestamp_upp, {KEY: VAL_3})

        pattern_a = BoboPattern() \
            .followed_by(LABEL_LAYER_A, predicate_a) \
            .followed_by(LABEL_LAYER_B, predicate_b) \
            .followed_by(LABEL_LAYER_C, predicate_c) \
            .precondition(predicate_first_window)

        handler = BoboNFAHandler(
            BoboRuleBuilder.nfa(NFA_NAME_A, pattern_a),
            SharedVersionedMatchBuffer())
        handlersub = NFAHandlerSubscriber()
        handler.subscribe(handlersub)

        handler.process(event_a)
        handler.process(event_b)
        handler.process(event_c)

        self.assertEqual(len(handlersub.final), 1)
Esempio n. 2
0
    def test_sliding_last_window_to_halt(self):
        timestamp_lower = EpochNSClock.generate_timestamp()
        sleep(0.5)
        timestamp_upper = EpochNSClock.generate_timestamp()
        window_range_ns = timestamp_upper - timestamp_lower

        timestamp_a = timestamp_lower
        timestamp_b = timestamp_a + window_range_ns
        timestamp_c = timestamp_b + window_range_ns + 1

        predicate_a = BoboPredicateCallable(predicate_key_a_value_a)
        predicate_b = BoboPredicateCallable(predicate_key_a_value_b)
        predicate_c = BoboPredicateCallable(predicate_key_a_value_c)
        predicate_first_window = WindowSlidingLast(window_range_ns)

        event_a = PrimitiveEvent(timestamp_a, {KEY: VAL_1})
        event_b = PrimitiveEvent(timestamp_b, {KEY: VAL_2})
        event_c = PrimitiveEvent(timestamp_c, {KEY: VAL_3})

        pattern_a = BoboPattern() \
            .followed_by(LABEL_LAYER_A, predicate_a) \
            .followed_by(LABEL_LAYER_B, predicate_b) \
            .followed_by(LABEL_LAYER_C, predicate_c) \
            .precondition(predicate_first_window)

        handler = BoboNFAHandler(BoboRuleBuilder.nfa(NFA_NAME_A, pattern_a),
                                 SharedVersionedMatchBuffer())
        handlersub = NFAHandlerSubscriber()
        handler.subscribe(handlersub)

        handler.process(event_a)
        handler.process(event_b)
        handler.process(event_c)

        self.assertEqual(len(handlersub.final), 1)
Esempio n. 3
0
    def test_fixed_window_to_final(self):
        timestamp_lower = EpochNSClock.generate_timestamp()
        sleep(0.1)
        timestamp_a = EpochNSClock.generate_timestamp()
        sleep(0.1)
        timestamp_b = EpochNSClock.generate_timestamp()
        sleep(0.1)
        timestamp_c = EpochNSClock.generate_timestamp()
        sleep(0.1)
        timestamp_upper = EpochNSClock.generate_timestamp()
        sleep(0.1)

        predicate_a = BoboPredicateCallable(predicate_key_a_value_a)
        predicate_b = BoboPredicateCallable(predicate_key_a_value_b)
        predicate_c = BoboPredicateCallable(predicate_key_a_value_c)
        predicate_fixed_window = WindowFixed(timestamp_lower,
                                             timestamp_upper)

        event_a = PrimitiveEvent(timestamp_a, {KEY: VAL_1})
        event_b = PrimitiveEvent(timestamp_b, {KEY: VAL_2})
        event_c = PrimitiveEvent(timestamp_c, {KEY: VAL_3})

        pattern_a = BoboPattern() \
            .followed_by(LABEL_LAYER_A, predicate_a) \
            .followed_by(LABEL_LAYER_B, predicate_b) \
            .followed_by(LABEL_LAYER_C, predicate_c) \
            .precondition(predicate_fixed_window)

        handler = BoboNFAHandler(
            BoboRuleBuilder.nfa(NFA_NAME_A, pattern_a),
            SharedVersionedMatchBuffer())
        handlersub = NFAHandlerSubscriber()
        handler.subscribe(handlersub)

        handler.process(event_a)
        handler.process(event_b)
        handler.process(event_c)

        self.assertEqual(len(handlersub.final_history), 1)
        self.assertDictEqual(handlersub.final_history[0].events,
                             {LABEL_LAYER_A: [event_a],
                              LABEL_LAYER_B: [event_b],
                              LABEL_LAYER_C: [event_c]})