Example #1
0
    def test_shared_versioned_match_buffer(self):
        original = SharedVersionedMatchBuffer()
        original.put_event(nfa_name=NFA_NAME_A,
                           run_id=RUN_ID_A,
                           version=VERSION_A,
                           state_label=LABEL_LAYER_A,
                           event=event_a)

        # ensure event is found in original buffer
        event_orig = original.get_event(nfa_name=NFA_NAME_A,
                                        state_label=LABEL_LAYER_A,
                                        event_id=event_a.event_id,
                                        default=None)
        self.assertIsNotNone(event_orig)
        self.assertEqual(event_orig, event_a)

        # generate new buffer
        generated = BoboDeciderBuilder \
            .shared_versioned_match_buffer(original.to_dict())

        # ensure event is found in generated buffer
        event_gen = generated.get_event(nfa_name=NFA_NAME_A,
                                        state_label=LABEL_LAYER_A,
                                        event_id=event_a.event_id,
                                        default=None)
        self.assertIsNotNone(event_gen)

        # ensure events match between buffers
        self.assertDictEqual(event_orig.to_dict(), event_gen.to_dict())
    def test_put_and_get_event(self):
        buffer = SharedVersionedMatchBuffer()
        run_id = generate_unique_string()
        version = RunVersion()
        version.add_level(run_id)

        buffer.put_event(nfa_name=NFA_NAME_A,
                         run_id=run_id,
                         version=version.get_version_as_str(),
                         state_label=LABEL_LAYER_A,
                         event=event_a)

        self.assertEqual(
            event_a,
            buffer.get_event(nfa_name=NFA_NAME_A,
                             state_label=LABEL_LAYER_A,
                             event_id=event_a.event_id,
                             default=None))

        # incorrect nfa name
        self.assertIsNone(
            buffer.get_event(nfa_name=NFA_NAME_B,
                             state_label=LABEL_LAYER_A,
                             event_id=event_a.event_id,
                             default=None))

        # incorrect state label
        self.assertIsNone(
            buffer.get_event(nfa_name=NFA_NAME_A,
                             state_label=LABEL_LAYER_B,
                             event_id=event_a.event_id,
                             default=None))

        # incorrect event id
        self.assertIsNone(
            buffer.get_event(nfa_name=NFA_NAME_A,
                             state_label=LABEL_LAYER_A,
                             event_id=event_b.event_id,
                             default=None))