def test_user_roundtrip(self): scope = Scope("/test/it") in_connector = self._get_in_connector(scope, activate=False) out_connector = self._get_out_connector(scope, activate=False) in_configurator = rsb.eventprocessing.InRouteConfigurator( connectors=[in_connector]) out_configurator = rsb.eventprocessing.OutRouteConfigurator( connectors=[out_connector]) listener = create_listener(scope, configurator=in_configurator) publisher = create_informer(scope, data_type=str, configurator=out_configurator) receiver = SettingReceiver(scope) listener.add_handler(receiver) data1 = "a string to test" sent_event = Event(EventId(uuid.uuid4(), 0)) sent_event.data = data1 sent_event.data_type = str sent_event.scope = scope sent_event.meta_data.set_user_info("test", "it") sent_event.meta_data.set_user_info("test again", "it works?") sent_event.meta_data.set_user_time("blubb", 234234.0) sent_event.meta_data.set_user_time("bla", 3434343.45) sent_event.add_cause(EventId(uuid.uuid4(), 1323)) sent_event.add_cause(EventId(uuid.uuid4(), 42)) publisher.publish_event(sent_event) with receiver.result_condition: while receiver.result_event is None: receiver.result_condition.wait(10) if receiver.result_event is None: self.fail("Listener did not receive an event") assert receiver.result_event.meta_data.create_time <= \ receiver.result_event.meta_data.send_time assert receiver.result_event.meta_data.send_time <= \ receiver.result_event.meta_data.receive_time assert receiver.result_event.meta_data.receive_time <= \ receiver.result_event.meta_data.deliver_time sent_event.meta_data.receive_time = \ receiver.result_event.meta_data.receive_time sent_event.meta_data.deliver_time = \ receiver.result_event.meta_data.deliver_time # HACK: floating point precision leads to an imprecision here, # avoid this. sent_event.meta_data.send_time = \ receiver.result_event.meta_data.send_time sent_event.meta_data.create_time = \ receiver.result_event.meta_data.create_time assert sent_event == receiver.result_event publisher.deactivate() listener.deactivate()
def test_causes(self): sid = uuid.uuid4() e = Event(EventId(sid, 32)) assert len(e.causes) == 0 cause = EventId(uuid4(), 546345) e.add_cause(cause) assert len(e.causes) == 1 assert e.is_cause(cause) assert cause in e.causes e.remove_cause(cause) assert not e.is_cause(cause) assert len(e.causes) == 0
def test_comparison(self): sid = uuid.uuid4() e1 = Event(EventId(sid, 0)) e2 = Event(EventId(sid, 0)) e2.meta_data.set_create_time(e1.meta_data.create_time) e1.meta_data.set_user_time("foo") assert e1 != e2 e2.meta_data.set_user_time("foo", e1.meta_data.user_times["foo"]) assert e1 == e2 cause = EventId(uuid4(), 42) e1.add_cause(cause) assert e1 != e2 e2.add_cause(cause) assert e1 == e2