Esempio n. 1
0
    def _handle_final(self, data: str) -> None:
        json_data = json.loads(data)
        nfa_name = json_data[bdc.NFA_NAME]
        run_id = json_data[bdc.RUN_ID]
        event = BoboRuleBuilder.composite(json_data[bdc.EVENT])

        for subscriber in self._subs:
            subscriber.on_dist_run_final(
                nfa_name=nfa_name,
                run_id=run_id,
                event=event
            )
Esempio n. 2
0
    def test_composite_none(self):
        c_timestamp = EpochNSClock.generate_timestamp()
        c_name = NAME_A
        c_history = {}
        c_data = DATA_A
        c_id = EVENT_ID_A

        with self.assertRaises(RuntimeError):
            BoboRuleBuilder.composite({
                CompositeEvent.TIMESTAMP: None,
                CompositeEvent.NAME: c_name,
                CompositeEvent.HISTORY: c_history,
                CompositeEvent.DATA: c_data,
                CompositeEvent.EVENT_ID: c_id
            })

        with self.assertRaises(RuntimeError):
            BoboRuleBuilder.composite({
                CompositeEvent.TIMESTAMP: c_timestamp,
                CompositeEvent.NAME: None,
                CompositeEvent.HISTORY: c_history,
                CompositeEvent.DATA: c_data,
                CompositeEvent.EVENT_ID: c_id
            })

        with self.assertRaises(RuntimeError):
            BoboRuleBuilder.composite({
                CompositeEvent.TIMESTAMP: c_timestamp,
                CompositeEvent.NAME: c_name,
                CompositeEvent.HISTORY: None,
                CompositeEvent.DATA: c_data,
                CompositeEvent.EVENT_ID: c_id
            })

        with self.assertRaises(RuntimeError):
            BoboRuleBuilder.composite({
                CompositeEvent.TIMESTAMP: c_timestamp,
                CompositeEvent.NAME: c_name,
                CompositeEvent.HISTORY: c_history,
                CompositeEvent.DATA: c_data,
                CompositeEvent.EVENT_ID: None
            })
Esempio n. 3
0
    def test_composite(self):
        # composite event data
        c_timestamp = EpochNSClock.generate_timestamp()
        c_name = NAME_A
        c_data = DATA_A
        c_id = EVENT_ID_A

        # primitive event used in composite event's history
        p_timestamp = EpochNSClock.generate_timestamp()
        p_data = NAME_B
        p_label = LABEL_A
        p_id = EVENT_ID_B

        # create dict representation of composite event
        c_dict = {
            CompositeEvent.TIMESTAMP: c_timestamp,
            CompositeEvent.NAME: c_name,
            CompositeEvent.HISTORY: {
                p_label: [{
                    PrimitiveEvent.TIMESTAMP: p_timestamp,
                    PrimitiveEvent.DATA: p_data,
                    PrimitiveEvent.EVENT_ID: p_id
                }]
            },
            CompositeEvent.DATA: c_data,
            CompositeEvent.EVENT_ID: c_id
        }

        # check composite event
        c_event_1 = BoboRuleBuilder.composite(c_dict)
        c_event_2 = BoboRuleBuilder.event(c_dict)

        for c_event in [c_event_1, c_event_2]:
            self.assertEqual(c_event.timestamp, c_timestamp)
            self.assertEqual(c_event.name, c_name)
            self.assertEqual(c_event.data, c_data)
            self.assertEqual(c_event.event_id, c_id)

            # Check primitive event in history
            p_event = c_event.history.events[p_label][0]

            self.assertEqual(p_event.timestamp, p_timestamp)
            self.assertEqual(p_event.data, p_data)
            self.assertEqual(p_event.event_id, p_id)