示例#1
0
    def test_correct_registration(self):
        obj = BusinessObject(
            {
                'event': 'services/request',
                'name': 'clients',
                'request': 'join',
                'client': str(uuid4()),
                'user': str(uuid4())
            }, None)
        obj.serialize(socket=self.sock)

        list_obj = BusinessObject(
            {
                'event': 'services/request',
                'name': 'clients',
                'request': 'list'
            }, None)
        list_obj.serialize(socket=self.sock)
        reply, time = reply_for_object(list_obj, self.sock, select=select)
        self.assertIsNotNone(reply, msg=u'No reply to service request')

        payload_text = reply.payload.decode('utf-8')
        payload = json.loads(payload_text)

        self.assertCorrectClientListReply(obj, payload)
示例#2
0
    def test_clients_on_other_server_receive(self):
        client, routing_id = self.clients[0]
        to_client, to_routing_id = self.clients[2]

        obj = BusinessObject({'to': to_routing_id}, None)
        obj.serialize(socket=client)

        self.assert_receives_object(to_client, obj.id)
示例#3
0
    def test_clients_on_other_server_receive(self):
        client, routing_id = self.clients[0]
        to_client, to_routing_id = self.clients[2]

        obj = BusinessObject({'to': to_routing_id}, None)
        obj.serialize(socket=client)

        self.assert_receives_object(to_client, obj.id)
示例#4
0
 def test_answers_to_service_call(self):
     list_obj = BusinessObject({'event': 'services/request',
                                'name': 'clients',
                                'request': 'list'}, None)
     list_obj.serialize(socket=self.sock)
     logger.info(self.server)
     logger.info(self.service)
     reply, time = reply_for_object(list_obj, self.sock, select=select)
     self.assertIsNotNone(reply)
示例#5
0
 def make_send_subscription(self):
     obj = BusinessObject(
         {
             'event': 'routing/subscribe',
             'receive-mode': 'all',
             'types': 'all'
         }, None)
     obj.serialize(socket=self.sock)
     return obj
示例#6
0
    def test_server_doesnt_deliver_when_no_echo(self):
        client, routing_id = self.make_subscribe_client(no_echo=True)

        obj = BusinessObject({}, None)
        obj.serialize(socket=client)

        reply = read_object_with_timeout(client, timeout_secs=0.1, select=select)
        self.assertIsNone(reply)
        client.close()
示例#7
0
    def test_server_doesnt_deliver_when_no_echo(self):
        client, routing_id = self.make_subscribe_client(no_echo=True)

        obj = BusinessObject({}, None)
        obj.serialize(socket=client)

        reply = read_object_with_timeout(client,
                                         timeout_secs=0.1,
                                         select=select)
        self.assertIsNone(reply)
        client.close()
示例#8
0
    def make_send_subscription(self, sock, no_echo=False):
        metadata = {'event': 'routing/subscribe',
                    'receive-mode': 'all',
                    'types': 'all'}

        if no_echo:
            metadata['receive-mode'] = 'no_echo'

        obj = BusinessObject(metadata, None)
        obj.serialize(socket=sock)
        return obj
示例#9
0
 def test_answers_to_service_call(self):
     list_obj = BusinessObject(
         {
             'event': 'services/request',
             'name': 'clients',
             'request': 'list'
         }, None)
     list_obj.serialize(socket=self.sock)
     logger.info(self.server)
     logger.info(self.service)
     reply, time = reply_for_object(list_obj, self.sock, select=select)
     self.assertIsNotNone(reply)
示例#10
0
    def make_send_subscription(self, sock, no_echo=False):
        metadata = {
            'event': 'routing/subscribe',
            'receive-mode': 'all',
            'types': 'all'
        }

        if no_echo:
            metadata['receive-mode'] = 'no_echo'

        obj = BusinessObject(metadata, None)
        obj.serialize(socket=sock)
        return obj
示例#11
0
    def setUp(self):
        super(ClientRegistryTestCase, self).setUp()

        self.start_client_registry(_host, _port) # TODO: multiple inheritance
        logger.info('Started client registry, connecting to %s:%s', _host, _port)

        global _host, _port
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.connect((_host, _port))
        obj = BusinessObject({'event': 'routing/subscribe',
                              'receive-mode': 'all',
                              'types': 'all'}, None)
        obj.serialize(socket=self.sock)
        resp, time = reply_for_object(obj, self.sock, select=select)
        self.routing_id = resp.metadata['routing-id']
示例#12
0
    def test_server_delivers_to_specified_recipient(self):
        client, routing_id = self.clients[0]
        to_client, to_routing_id = self.clients[1]

        obj = BusinessObject({'to': to_routing_id}, None)
        obj.serialize(socket=client)

        self.assert_receives_object(to_client, obj.id)

        for client, routing_id in self.clients[2:]:
            reply = read_object_with_timeout(client, timeout_secs=0.1, select=select)
            if reply is not None:
                self.assertIsNotNone(reply.event)
            while reply is not None and reply.event is not None:
                reply = read_object_with_timeout(client, timeout_secs=0.1, select=select)

            self.assertIsNone(reply)
示例#13
0
    def test_correct_registration(self):
        obj = BusinessObject({'event': 'services/request',
                              'name': 'clients',
                              'request': 'join',
                              'client': str(uuid4()),
                              'user': str(uuid4())}, None)
        obj.serialize(socket=self.sock)

        list_obj = BusinessObject({'event': 'services/request',
                                   'name': 'clients',
                                   'request': 'list'}, None)
        list_obj.serialize(socket=self.sock)
        reply, time = reply_for_object(list_obj, self.sock, select=select)
        self.assertIsNotNone(reply, msg=u'No reply to service request')

        payload_text = reply.payload.decode('utf-8')
        payload = json.loads(payload_text)

        self.assertCorrectClientListReply(obj, payload)
示例#14
0
    def setUp(self):
        super(ClientRegistryTestCase, self).setUp()

        self.start_client_registry(_host, _port)  # TODO: multiple inheritance
        logger.info('Started client registry, connecting to %s:%s', _host,
                    _port)

        global _host, _port
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.connect((_host, _port))
        obj = BusinessObject(
            {
                'event': 'routing/subscribe',
                'receive-mode': 'all',
                'types': 'all'
            }, None)
        obj.serialize(socket=self.sock)
        resp, time = reply_for_object(obj, self.sock, select=select)
        self.routing_id = resp.metadata['routing-id']
示例#15
0
    def test_server_delivers_to_specified_recipient(self):
        client, routing_id = self.clients[0]
        to_client, to_routing_id = self.clients[1]

        obj = BusinessObject({'to': to_routing_id}, None)
        obj.serialize(socket=client)

        self.assert_receives_object(to_client, obj.id)

        for client, routing_id in self.clients[2:]:
            reply = read_object_with_timeout(client,
                                             timeout_secs=0.1,
                                             select=select)
            if reply is not None:
                self.assertIsNotNone(reply.event)
            while reply is not None and reply.event is not None:
                reply = read_object_with_timeout(client,
                                                 timeout_secs=0.1,
                                                 select=select)

            self.assertIsNone(reply)
示例#16
0
 def make_send_subscription(self):
     obj = BusinessObject({'event': 'routing/subscribe',
                           'receive-mode': 'all',
                           'types': 'all'}, None)
     obj.serialize(socket=self.sock)
     return obj
示例#17
0
    def test_server_delivers_to_all(self):
        obj = BusinessObject({}, None)
        obj.serialize(socket=self.clients[0][0])

        for sock, routing_id in self.clients:
            self.assert_receives_object(sock, obj.id)
示例#18
0
 def test_server_delivers_to_sender(self):
     obj = BusinessObject({}, None)
     obj.serialize(socket=self.clients[0][0])
     self.assert_receives_object(self.clients[0][0], obj.id)
示例#19
0
    def test_server_delivers_to_all(self):
        obj = BusinessObject({}, None)
        obj.serialize(socket=self.clients[0][0])

        for sock, routing_id in self.clients:
            self.assert_receives_object(sock, obj.id)
示例#20
0
 def test_server_delivers_to_sender(self):
     obj = BusinessObject({}, None)
     obj.serialize(socket=self.clients[0][0])
     self.assert_receives_object(self.clients[0][0], obj.id)