Ejemplo n.º 1
0
    def testCauses(self):

        sid = uuid.uuid4()
        e = Event(EventId(sid, 32))
        self.assertEqual(0, len(e.causes))
        cause = EventId(uuid4(), 546345)
        e.addCause(cause)
        self.assertEqual(1, len(e.causes))
        self.assertTrue(e.isCause(cause))
        self.assertTrue(cause in e.causes)
        e.removeCause(cause)
        self.assertFalse(e.isCause(cause))
        self.assertEqual(0, len(e.causes))
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
    def testComparison(self):

        sid = uuid.uuid4()
        e1 = Event(EventId(sid, 0))
        e2 = Event(EventId(sid, 0))
        e2.getMetaData().setCreateTime(e1.getMetaData().getCreateTime())

        e1.metaData.setUserTime("foo")
        self.assertNotEquals(e1, e2)
        e2.metaData.setUserTime("foo", e1.getMetaData().getUserTimes()["foo"])
        self.assertEquals(e1, e2)

        cause = EventId(uuid4(), 42)
        e1.addCause(cause)
        self.assertNotEqual(e1, e2)
        e2.addCause(cause)
        self.assertEqual(e1, e2)
Ejemplo n.º 4
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()