Ejemplo n.º 1
0
def notificationToEvent(notification, wireData, wireSchema, converter):
    """
    Build event from notification.
    """
    event = rsb.Event(
        rsb.EventId(uuid.UUID(bytes=notification.event_id.sender_id),
                    notification.event_id.sequence_number))
    event.scope = rsb.Scope(notification.scope)
    if notification.HasField("method"):
        event.method = notification.method
    event.type = converter.getDataType()
    event.data = converter.deserialize(wireData, wireSchema)

    # Meta data
    event.metaData.createTime = unixMicrosecondsToTime(
        notification.meta_data.create_time)
    event.metaData.sendTime = unixMicrosecondsToTime(
        notification.meta_data.send_time)
    event.metaData.setReceiveTime()
    for info in notification.meta_data.user_infos:
        event.metaData.setUserInfo(info.key, info.value)
    for time in notification.meta_data.user_times:
        event.metaData.setUserTime(time.key,
                                   unixMicrosecondsToTime(time.timestamp))

    # Causes
    for cause in notification.causes:
        id = rsb.EventId(uuid.UUID(bytes=cause.sender_id),
                         cause.sequence_number)
        event.addCause(id)

    return event
Ejemplo n.º 2
0
def notification_to_event(notification, wire_data, wire_schema, converter):
    """Build an event from a notification."""
    event = rsb.Event(
        rsb.EventId(uuid.UUID(bytes=notification.event_id.sender_id),
                    notification.event_id.sequence_number))
    event.scope = rsb.Scope(notification.scope.decode('ASCII'))
    if notification.HasField("method"):
        event.method = notification.method.decode('ASCII')
    event.data_type = converter.data_type
    event.data = converter.deserialize(wire_data, wire_schema)

    # Meta data
    event.meta_data.create_time = unix_microseconds_to_time(
        notification.meta_data.create_time)
    event.meta_data.send_time = unix_microseconds_to_time(
        notification.meta_data.send_time)
    event.meta_data.set_receive_time()
    for info in notification.meta_data.user_infos:
        event.meta_data.set_user_info(info.key.decode('ASCII'),
                                      info.value.decode('ASCII'))
    for time in notification.meta_data.user_times:
        event.meta_data.set_user_time(
            time.key.decode('ASCII'),
            unix_microseconds_to_time(time.timestamp))

    # Causes
    for cause in notification.causes:
        event_id = rsb.EventId(uuid.UUID(bytes=cause.sender_id),
                               cause.sequence_number)
        event.add_cause(event_id)

    return event
Ejemplo n.º 3
0
    def test_match(self):
        id1 = rsb.EventId(participant_id=uuid.uuid1(), sequence_number=0)
        e1 = rsb.Event(causes=[id1])
        id2 = rsb.EventId(participant_id=uuid.uuid1(), sequence_number=1)
        e2 = rsb.Event(causes=[id2])

        f = rsb.filter.CauseFilter(cause=id1)
        assert f.match(e1)
        assert not f.match(e2)

        f = rsb.filter.CauseFilter(cause=id1, invert=True)
        assert not f.match(e1)
        assert f.match(e2)
Ejemplo n.º 4
0
    def testMatch(self):
        id1 = rsb.EventId(participantId=uuid.uuid1(), sequenceNumber=0)
        e1 = rsb.Event(causes=[ id1 ])
        id2 = rsb.EventId(participantId=uuid.uuid1(), sequenceNumber=1)
        e2 = rsb.Event(causes=[ id2 ])

        f = rsb.filter.CauseFilter(cause=id1)
        self.assertTrue(f.match(e1))
        self.assertFalse(f.match(e2))

        f = rsb.filter.CauseFilter(cause=id1, invert=True)
        self.assertFalse(f.match(e1))
        self.assertTrue(f.match(e2))
Ejemplo n.º 5
0
    def test_match(self):
        sender_id1 = uuid.uuid1()
        e1 = rsb.Event(
            event_id=rsb.EventId(participant_id=sender_id1, sequence_number=0))
        sender_id2 = uuid.uuid1()
        e2 = rsb.Event(
            event_id=rsb.EventId(participant_id=sender_id2, sequence_number=1))

        f = rsb.filter.OriginFilter(origin=sender_id1)
        assert f.match(e1)
        assert not f.match(e2)

        f = rsb.filter.OriginFilter(origin=sender_id1, invert=True)
        assert not f.match(e1)
        assert f.match(e2)
Ejemplo n.º 6
0
    def testMatch(self):
        senderId1 = uuid.uuid1()
        e1 = rsb.Event(id=rsb.EventId(participantId=senderId1,
                                      sequenceNumber=0))
        senderId2 = uuid.uuid1()
        e2 = rsb.Event(id=rsb.EventId(participantId=senderId2,
                                      sequenceNumber=1))

        f = rsb.filter.OriginFilter(origin=senderId1)
        self.assertTrue(f.match(e1))
        self.assertFalse(f.match(e2))

        f = rsb.filter.OriginFilter(origin=senderId1, invert=True)
        self.assertFalse(f.match(e1))
        self.assertTrue(f.match(e2))
Ejemplo n.º 7
0
    receivers = []
    try:
        for size in [4, 256, 400000]:
            # Create listeners for all scopes below the /sizeSIZE scope:
            # * /size-SIZE
            # * /size-SIZE/sub_1
            # * /size-SIZE/sub_1/sub_2
            scope = rsb.Scope("/size-%d/sub_1/sub_2" % size)
            scopes = scope.super_scopes(True)
            for superscope in scopes[1:]:
                listener = rsb.create_listener(superscope)
                listeners.append(listener)

                receiver = Receiver(
                    scope, size,
                    rsb.EventId(
                        uuid.UUID('00000000-0000-0000-0000-000000000000'), 0),
                    120)
                receivers.append(receiver)
                listener.add_handler(receiver)

        open('ready', 'w').close()
        print("[Python Listener] Ready")

        for receiver in receivers:
            with receiver.condition:
                while not receiver.is_done():
                    print("[Python Listener] Waiting for receiver %s" %
                          receiver.expectedScope)
                    receiver.condition.wait(60)
                    assert (receiver.is_done())
    finally:
Ejemplo n.º 8
0
# Public License as published by the Free Software Foundation;
# either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# ============================================================

import logging
import uuid
import sys

import rsb

if __name__ == "__main__":
    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s %(name)-12s %(levelname)-8s\n%(message)s',
        stream=sys.stderr)
    with open('data/event-id-cases.txt') as input:
        for line in input.readlines():
            origin, seqnum, expected = list(map(str.strip, line.split(' ')))
            originId, seqnum, expectedId = \
                (uuid.UUID(hex=origin), int(seqnum, 16), uuid.UUID(hex=expected))
            event = rsb.Event(event_id=rsb.EventId(participant_id=originId,
                                                   sequence_number=seqnum))
            assert event.event_id.get_as_uuid() == expectedId