def test_on_sync(self): setup = BoboSetup() setup.add_complex_event(event_def=BoboComplexEvent( name=NAME_NFA_A, pattern=stub_pattern_4, action=NoAction())) setup.config_null_data(delay_sec=NULL_DATA_DELAY, null_data=BoboNullDataStatic(DATA_DICT_A)) setup.config_distributed(exchange_name=EXCHANGE_NAME, user_name=USER_NAME, parameters=parameters) setup.configure() self.assertFalse(setup.get_receiver().is_active()) self.assertFalse(setup.get_decider().is_active()) self.assertFalse(setup.get_producer().is_active()) self.assertFalse(setup.get_forwarder().is_active()) self.assertFalse(setup.get_null_data_generator().is_active()) setup.on_sync() self.assertTrue(setup.get_receiver().is_active()) self.assertTrue(setup.get_decider().is_active()) self.assertTrue(setup.get_producer().is_active()) self.assertTrue(setup.get_forwarder().is_active()) self.assertTrue(setup.get_null_data_generator().is_active())
def test_setup_after_cancel(self): setup = BoboSetup() setup.add_complex_event(event_def=BoboComplexEvent( name=NAME_NFA_A, pattern=stub_pattern_1, action=NoAction())) setup.config_null_data(delay_sec=NULL_DATA_DELAY, null_data=BoboNullDataStatic(DATA_DICT_A)) setup.configure() setup.start() sleep(SLEEP_WAIT) setup.cancel() self.assertFalse(setup.is_ready()) self.assertFalse(setup.is_active()) self.assertFalse(setup.is_inactive()) self.assertTrue(setup.is_cancelled()) self.assertTrue(setup.is_configured()) self.assertFalse(setup.get_receiver().is_active()) self.assertFalse(setup.get_decider().is_active()) self.assertFalse(setup.get_producer().is_active()) self.assertFalse(setup.get_forwarder().is_active()) self.assertFalse(setup.get_null_data_generator().is_active())
def test_access_before_configuration(self): setup = BoboSetup() with self.assertRaises(RuntimeError): setup.get_receiver() with self.assertRaises(RuntimeError): setup.get_decider() with self.assertRaises(RuntimeError): setup.get_producer() with self.assertRaises(RuntimeError): setup.get_forwarder() with self.assertRaises(RuntimeError): setup.get_distributed() with self.assertRaises(RuntimeError): setup.get_null_data_generator()
def test_subscribe_receiver_invalid_data(self): setup = BoboSetup() sub = StubSubscriberSetup() setup.add_complex_event(event_def=BoboComplexEvent( name=NAME_NFA_A, pattern=stub_pattern_1, action=NoAction())) setup.config_receiver(StrDictValidator()) setup.subscribe_receiver(sub) setup.configure() receiver = setup.get_receiver() receiver.setup() receiver.add_data(VALUE_A) receiver.loop() self.assertEqual(VALUE_A, sub.invalid_data[0])
def test_subscribe_receiver_valid_data(self): setup = BoboSetup() sub = StubSubscriberSetup() setup.add_complex_event(event_def=BoboComplexEvent( name=NAME_NFA_A, pattern=stub_pattern_1, action=NoAction())) setup.config_receiver(StrDictValidator()) setup.subscribe_receiver(sub) setup.configure() receiver = setup.get_receiver() receiver.setup() receiver.add_data(DATA_DICT_A) receiver.loop() self.assertIsInstance(sub.receiver_event[0], PrimitiveEvent)
def test_primitive_from_receiver_to_decider(self): setup = BoboSetup() setup.add_complex_event(event_def=BoboComplexEvent( name=NAME_NFA_A, pattern=stub_pattern_4)) setup.config_receiver(StrDictValidator()) setup.configure() receiver = setup.get_receiver() receiver.setup() decider = setup.get_decider() decider.setup() receiver.add_data(DATA_DICT_A) receiver.loop() decider.loop() handlers = decider.get_all_handlers() self.assertEqual(NAME_NFA_A, handlers[0].nfa.name)
def test_config_arguments(self): setup = BoboSetup() event_def = BoboComplexEvent(NAME_NFA_A, stub_pattern_1) validator = StrDictValidator() action_producer = RateLimitAction() action_forwarder = NoAction() null_data = BoboNullDataStatic(DATA_DICT_A) setup.add_complex_event(event_def) setup.config_receiver(validator) setup.config_producer(action_producer) setup.config_forwarder(action_forwarder) setup.config_null_data(NULL_DATA_DELAY, null_data) setup.config_distributed(EXCHANGE_NAME, USER_NAME, parameters) setup.configure() receiver = setup.get_receiver() decider = setup.get_decider() producer = setup.get_producer() forwarder = setup.get_forwarder() nullgen = setup.get_null_data_generator() manager = setup.get_distributed() self.assertEqual(validator, receiver.get_validator()) self.assertEqual(NAME_NFA_A, decider.get_all_handlers()[0].nfa.name) self.assertEqual(action_producer, producer._action) self.assertEqual(action_forwarder, forwarder._action) self.assertEqual(null_data, nullgen.null_data) self.assertEqual(receiver, nullgen.receiver) self.assertEqual(manager.outgoing.decider, decider) self.assertEqual(manager.outgoing.exchange_name, EXCHANGE_NAME) self.assertTrue(manager.outgoing.user_id.find(USER_NAME) != -1) self.assertEqual(manager.outgoing.parameters, parameters) self.assertEqual(manager.incoming.decider, decider) self.assertEqual(manager.incoming.exchange_name, EXCHANGE_NAME) self.assertTrue(manager.incoming.user_id.find(USER_NAME) != -1) self.assertEqual(manager.incoming.parameters, parameters)