def testRoundtrip(self): goodScope = Scope("/good") inconnector = self._getInPushConnector(goodScope) outconnector = self._getOutConnector(goodScope) receiver = SettingReceiver(goodScope) inconnector.setObserverAction(receiver) # first an event that we do not want event = Event(EventId(uuid.uuid4(), 0)) event.scope = Scope("/notGood") event.data = "dummy data" event.type = str event.metaData.senderId = uuid.uuid4() outconnector.handle(event) # and then a desired event event.scope = goodScope outconnector.handle(event) with receiver.resultCondition: while receiver.resultEvent is None: receiver.resultCondition.wait(10) self.assertTrue(receiver.resultEvent) # ignore meta data here event.setMetaData(None) receiver.resultEvent.setMetaData(None) self.assertEqual(receiver.resultEvent, event) inconnector.deactivate() outconnector.deactivate()
def test_sequencing(self): good_scope = Scope("/good") in_connector = get_connector(good_scope, clazz=spread_transport.InConnector) out_connector = get_connector(good_scope, clazz=spread_transport.OutConnector) try: receiver = SettingReceiver(good_scope) in_connector.set_observer_action(receiver) # first an event that we do not want event = Event(EventId(uuid.uuid4(), 0)) event.scope = Scope("/notGood") event.data = ''.join( random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(300502)) event.data_type = str event.meta_data.sender_id = uuid.uuid4() out_connector.handle(event) # and then a desired event event.scope = good_scope out_connector.handle(event) with receiver.result_condition: receiver.result_condition.wait(10) assert receiver.result_event is not None # self.assertEqual(receiver.result_event, event) finally: in_connector.deactivate() out_connector.deactivate()
def test_roundtrip(self): good_scope = Scope("/good") inconnector = self._get_in_connector(good_scope) outconnector = self._get_out_connector(good_scope) receiver = SettingReceiver(good_scope) inconnector.set_observer_action(receiver) # first an event that we do not want event = Event(EventId(uuid.uuid4(), 0)) event.scope = Scope("/notGood") event.data = "x" * 600000 event.data_type = str event.meta_data.sender_id = uuid.uuid4() outconnector.handle(event) # and then a desired event event.scope = good_scope outconnector.handle(event) with receiver.result_condition: while receiver.result_event is None: receiver.result_condition.wait(10) assert receiver.result_event # ignore meta data here event.meta_data = None receiver.result_event.meta_data = None assert receiver.result_event == event outconnector.deactivate() inconnector.deactivate()
def testPullRoundtrip(self): goodScope = Scope("/good") try: inconnector = self._getInPullConnector(goodScope) except NotImplementedError: return outconnector = self._getOutConnector(goodScope) # first an event that we do not want event = Event(EventId(uuid.uuid4(), 0)) event.scope = Scope("/notGood") event.data = "dummy data" event.type = str event.metaData.senderId = uuid.uuid4() outconnector.handle(event) # and then a desired event event.scope = goodScope outconnector.handle(event) received = inconnector.raiseEvent(True) # ignore meta data here event.setMetaData(None) received.setMetaData(None) self.assertEqual(received, event) inconnector.deactivate() outconnector.deactivate()
def testSequencing(self): goodScope = Scope("/good") inConnector = getConnector(goodScope, clazz=rsbspread.InPushConnector) outConnector = getConnector(goodScope, clazz=rsbspread.OutConnector) try: receiver = SettingReceiver(goodScope) inConnector.setObserverAction(receiver) # first an event that we do not want event = Event(EventId(uuid.uuid4(), 0)) event.scope = Scope("/notGood") event.data = "".join( random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(300502)) event.type = str event.metaData.senderId = uuid.uuid4() outConnector.handle(event) # and then a desired event event.scope = goodScope outConnector.handle(event) with receiver.resultCondition: receiver.resultCondition.wait(10) if receiver.resultEvent is None: self.fail("Did not receive an event") # self.assertEqual(receiver.resultEvent, event) finally: inConnector.deactivate() outConnector.deactivate()
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_send_time_adaption(self): scope = Scope("/notGood") connector = self._get_out_connector(scope) event = Event(EventId(uuid.uuid4(), 0)) event.scope = scope event.data = "".join( random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in list(range(300502))) event.data_type = str event.meta_data.sender_id = uuid.uuid4() before = time.time() connector.handle(event) after = time.time() assert event.meta_data.send_time >= before assert event.meta_data.send_time <= after connector.deactivate()
def testSendTimeAdaption(self): scope = Scope("/notGood") connector = self._getOutConnector(scope) event = Event(EventId(uuid.uuid4(), 0)) event.scope = scope event.data = "".join( random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(300502)) event.type = str event.metaData.senderId = uuid.uuid4() before = time.time() connector.handle(event) after = time.time() self.assertTrue(event.getMetaData().getSendTime() >= before) self.assertTrue(event.getMetaData().getSendTime() <= after) connector.deactivate()
def test_data(self): e = Event() data = 42 e.data = data assert data == e.data