Exemple #1
0
    def testUserRoundtrip(self):
        scope = Scope("/test/it")
        inConnector = self._getInPushConnector(scope, activate=False)
        outConnector = self._getOutConnector(scope, activate=False)

        outConfigurator = rsb.eventprocessing.OutRouteConfigurator(
            connectors=[outConnector])
        inConfigurator = rsb.eventprocessing.InPushRouteConfigurator(
            connectors=[inConnector])

        publisher = createInformer(scope,
                                   dataType=str,
                                   configurator=outConfigurator)
        listener = createListener(scope, configurator=inConfigurator)

        receiver = SettingReceiver(scope)
        listener.addHandler(receiver)

        data1 = "a string to test"
        sentEvent = Event(EventId(uuid.uuid4(), 0))
        sentEvent.setData(data1)
        sentEvent.setType(str)
        sentEvent.setScope(scope)
        sentEvent.getMetaData().setUserInfo("test", "it")
        sentEvent.getMetaData().setUserInfo("test again", "it works?")
        sentEvent.getMetaData().setUserTime("blubb", 234234)
        sentEvent.getMetaData().setUserTime("bla", 3434343.45)
        sentEvent.addCause(EventId(uuid.uuid4(), 1323))
        sentEvent.addCause(EventId(uuid.uuid4(), 42))

        publisher.publishEvent(sentEvent)

        with receiver.resultCondition:
            while receiver.resultEvent is None:
                receiver.resultCondition.wait(10)
            if receiver.resultEvent is None:
                self.fail("Listener did not receive an event")
            self.assertTrue(
                receiver.resultEvent.metaData.createTime <= receiver.
                resultEvent.metaData.sendTime <= receiver.resultEvent.metaData.
                receiveTime <= receiver.resultEvent.metaData.deliverTime)
            sentEvent.metaData.receiveTime = \
                receiver.resultEvent.metaData.receiveTime
            sentEvent.metaData.deliverTime = \
                receiver.resultEvent.metaData.deliverTime
            self.assertEqual(sentEvent, receiver.resultEvent)

        listener.deactivate()
        publisher.deactivate()
Exemple #2
0
    def testUserPullRoundtrip(self):
        scope = Scope("/test/it/pull")
        try:
            inConnector = self._getInPullConnector(scope, activate=False)
        except NotImplementedError:
            return
        outConnector = self._getOutConnector(scope, activate=False)

        outConfigurator = rsb.eventprocessing.OutRouteConfigurator(
            connectors=[outConnector])
        inConfigurator = rsb.eventprocessing.InPullRouteConfigurator(
            connectors=[inConnector])

        publisher = createInformer(scope,
                                   dataType=str,
                                   configurator=outConfigurator)
        reader = createReader(scope, configurator=inConfigurator)

        data1 = "a string to test"
        sentEvent = Event(EventId(uuid.uuid4(), 0))
        sentEvent.setData(data1)
        sentEvent.setType(str)
        sentEvent.setScope(scope)
        sentEvent.getMetaData().setUserInfo("test", "it")
        sentEvent.getMetaData().setUserInfo("test again", "it works?")
        sentEvent.getMetaData().setUserTime("blubb", 234234)
        sentEvent.getMetaData().setUserTime("bla", 3434343.45)
        sentEvent.addCause(EventId(uuid.uuid4(), 1323))
        sentEvent.addCause(EventId(uuid.uuid4(), 42))

        publisher.publishEvent(sentEvent)

        resultEvent = reader.read(True)
        self.assertTrue(resultEvent.metaData.createTime <= resultEvent.
                        metaData.sendTime <= resultEvent.metaData.receiveTime
                        <= resultEvent.metaData.deliverTime)
        sentEvent.metaData.receiveTime = resultEvent.metaData.receiveTime
        sentEvent.metaData.deliverTime = resultEvent.metaData.deliverTime
        self.assertEqual(sentEvent, resultEvent)

        reader.deactivate()
        publisher.deactivate()
Exemple #3
0
    def publish_cache(self):
        self.__logger.debug("[{}] Publishing cache... ({} total)".format(
            self.__authority,
            len(self.__send_cache_dynamic.keys()) +
            len(self.__send_cache_static.keys())))
        for _, v in self.__send_cache_dynamic.iteritems():
            event = Event()
            event.setData(v[0])
            event.setType(type(v[0]))
            event.setScope(self.__rsb_informer_transform.getScope().concat(
                Scope(self.__scope_suffix_dynamic)))
            event.setMetaData(v[1])
            self.__rsb_informer_transform.publishEvent(event)

        for _, v in self.__send_cache_static.iteritems():
            event = Event()
            event.setData(v[0])
            event.setType(type(v[0]))
            event.setScope(self.__rsb_informer_transform.getScope().concat(
                Scope(self.__scope_suffix_static)))
            event.setMetaData(v[1])
            self.__rsb_informer_transform.publishEvent(event)
Exemple #4
0
    def send_transform(self, transform, transform_type):
        '''
        Add transform information to the rct data structure.
        :param transform:
        :param transform_type:
        :return: True unless an error occured
        '''

        if not self.__rsb_informer_transform:
            self.__logger.error(
                "[{}] RSB communicator was not initialized!".format(
                    self.__authority))

        # some small type checks for usability
        assert isinstance(
            transform, Transform
        ), "Input transformation has to be of type rct.Transform! (Input was: {})".format(
            type(transform))
        assert hasattr(
            TransformType, transform_type
        ), "Input transformation type has to be of type rct.TransformType! (Input was: {})".format(
            type(transform_type))

        cache_key = transform.get_frame_parent() + transform.get_frame_child()
        meta_data = MetaData()

        if transform.get_authority() is "":
            meta_data.setUserInfo(self.__user_key_authority, self.__authority)
        else:
            meta_data.setUserInfo(self.__user_key_authority,
                                  transform.get_authority())

        self.__logger.info("[{}] Publishing transform from {}".format(
            self.__authority, self.__rsb_informer_transform.getId()))

        # TODO: threaded?
        event = Event()
        event.setData(transform)
        event.setType(type(transform))
        event.setMetaData(meta_data)

        if transform_type is TransformType.STATIC:
            self.__send_cache_static[cache_key] = (transform, meta_data)
            event.setScope(self.__rsb_informer_transform.getScope().concat(
                Scope(self.__scope_suffix_static)))

        elif transform_type is TransformType.DYNAMIC:
            self.__send_cache_dynamic[cache_key] = (transform, meta_data)
            event.setScope(self.__rsb_informer_transform.getScope().concat(
                Scope(self.__scope_suffix_dynamic)))

        else:
            self.__logger.error(
                "[{}] Cannot send transform. Reason: Unknown TransformType: {}"
                .format(self.__authority, str(transform_type)))
            return False

        self.__logger.info("[{}] Sending {} to scope {}".format(
            self.__authority, transform.__str__(), event.getScope()))
        self.__rsb_informer_transform.publishEvent(event)
        self.__logger.debug("[{}] Sending successful!".format(
            self.__authority))

        return True