Exemplo n.º 1
0
def start_service(endpoint):
    control = DefaultChannel(endpoint)
    control.connect()

    global keep_going
    while keep_going:
        command = input('> ')
        command_ftn = commands.get(command, unkown_command)
        command_ftn(control)
        print()
Exemplo n.º 2
0
    def dispatch_events_test(self):
        # """ Test dispatch events. """
        handlers = ReactorDispatcherTestCase._handlers
        # msg = "{\"source\": \"%d\", \"payload\": \"False\"}"
        header1 = {'source': '1', 'payload': 'False'}

        header2 = {'source': '2', 'payload': 'True'}
        payload2 = bytes([1, 2])

        header3 = {'source': '3', 'payload': 'True'}
        payload3 = bytes([1, 2, 3])
        try:
            client1 = ReactorDispatcherTestCase._clients[1]
            client2 = ReactorDispatcherTestCase._clients[2]
            client3 = ReactorDispatcherTestCase._clients[3]
        except KeyError as k:
            self.fail("Could not get clients: {0}".format(k))

        client1.send([header1])
        resp1 = client1.recv()
        self.assertEquals(1, resp1[0].get('sink'), 'Sink value wrong.')
        self.assertEquals(header1['source'], handlers[1]._header['source'])
        self.assertEquals(header1['payload'], handlers[1]._header['payload'])

        client2.send([header2, payload2])
        resp2 = client2.recv()

        self.assertEquals('2', handlers[2]._header['source'])
        self.assertEquals('True', handlers[2]._header['payload'])
        self.assertEquals(payload2[0], handlers[2]._payload[0])
        self.assertEquals(payload2[1]**2, handlers[2]._payload[1])
        self.assertEquals(2, resp2[0].get('sink'), 'Sink value wrong.')

        client3.send([header3, payload3])
        resp3 = client3.recv()

        # Checking handling of third client
        self.assertEquals('3', handlers[3]._header['source'])
        self.assertEquals('True', handlers[3]._header['payload'])
        self.assertEquals(payload3[0], handlers[3]._payload[0])
        self.assertEquals(payload3[1]**3, handlers[3]._payload[1])
        self.assertEquals(payload3[2]**3, handlers[3]._payload[2])
        # Receing response from handler3
        self.assertEquals(3, resp3[0].get('sink'), 'Sink value wrong.')

        control = DefaultChannel('ipc:///tmp/control.ipc')
        control.connect()
        control.send([{'action': 'terminate'}])
        control.close()