예제 #1
0
파일: msg_size.py 프로젝트: outro56/CloudI
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        try:
            self.__api.subscribe('python', self.request)

            result = self.__api.poll()
            assert result == False
        except terminate_exception:
            pass
        except:
            traceback.print_exc(file=sys.stderr)
        print('terminate msg_size python')

    def request(self, command, name, pattern, request_info, request,
                timeout, priority, trans_id, pid):
        i = struct.unpack('=I', request[:4])[0]
        if i == 4294967295:
            i = 0
        else:
            i += 1
        request = struct.pack('=I', i) + request[4:]
        print('forward #%d python to %s (with timeout %d ms)' % (
            i, _DESTINATION, timeout,
        ))
        self.__api.forward_(command, _DESTINATION, request_info, request,
                            timeout, priority, trans_id, pid)
예제 #2
0
파일: msg_size.py 프로젝트: mihawk/CloudI
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        self.__api.subscribe('python', self.request)

        result = self.__api.poll()
        print 'exited thread:', result

    def request(self, command, name, pattern, requestInfo, request, timeout,
                priority, transId, pid):
        i = struct.unpack('=I', request[:4])[0]
        if i == 4294967295:
            i = 0
        else:
            i += 1
        request = struct.pack('=I', i) + request[4:]
        print 'forward #%d python to %s (with timeout %d ms)' % (
            i,
            _DESTINATION,
            timeout,
        )
        self.__api.forward_(command, _DESTINATION, requestInfo, request,
                            timeout, priority, transId, pid)
예제 #3
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        try:
            self.__api.subscribe('python', self.request)

            result = self.__api.poll()
            assert result == False
        except terminate_exception:
            pass
        except:
            traceback.print_exc(file=sys.stderr)
        print('terminate msg_size python')

    def request(self, command, name, pattern, request_info, request, timeout,
                priority, trans_id, pid):
        i = struct.unpack('=I', request[:4])[0]
        if i == 4294967295:
            i = 0
        else:
            i += 1
        request = struct.pack('=I', i) + request[4:]
        print('forward #%d python to %s (with timeout %d ms)' % (
            i,
            _DESTINATION,
            timeout,
        ))
        self.__api.forward_(command, _DESTINATION, request_info, request,
                            timeout, priority, trans_id, pid)
예제 #4
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        self.__api.subscribe('python', self.request)

        result = self.__api.poll()
        print 'exited thread:', result

    def request(self, command, name, pattern, request_info, request,
                timeout, priority, trans_id, pid):
        i = struct.unpack('=I', request[:4])[0]
        if i == 4294967295:
            i = 0
        else:
            i += 1
        request = struct.pack('=I', i) + request[4:]
        print 'forward #%d python to %s (with timeout %d ms)' % (
            i, _DESTINATION, timeout,
        )
        self.__api.forward_(command, _DESTINATION, request_info, request,
                            timeout, priority, trans_id, pid)
예제 #5
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)
        self.__index = thread_index

    def run(self):
        try:
            # sends outside of a callback function must occur before the
            # subscriptions so that the incoming requests do not interfere with
            # the outgoing sends (i.e., without subscriptions there will be no
            # incoming requests)
            if self.__index == 0:
                # start sequence1
                self.__api.send_async(
                    self.__api.prefix() + 'sequence1', 'start',
                )
            self.__api.subscribe('a/b/c/d', self.__sequence1_abcd)
            self.__api.subscribe('a/b/c/*', self.__sequence1_abc_)
            self.__api.subscribe('a/b/*/d', self.__sequence1_ab_d)
            self.__api.subscribe('a/*/c/d', self.__sequence1_a_cd)
            self.__api.subscribe('*/b/c/d', self.__sequence1__bcd)
            self.__api.subscribe('a/b/*',   self.__sequence1_ab__)
            self.__api.subscribe('a/*/d',   self.__sequence1_a__d)
            self.__api.subscribe('*/c/d',   self.__sequence1___cd)
            self.__api.subscribe('a/*',     self.__sequence1_a___)
            self.__api.subscribe('*/d',     self.__sequence1____d)
            self.__api.subscribe('*',       self.__sequence1_____)
            self.__api.subscribe('sequence1', self.__sequence1)
            self.__api.subscribe('e', self.__sequence2_e1)
            self.__api.subscribe('e', self.__sequence2_e2)
            self.__api.subscribe('e', self.__sequence2_e3)
            self.__api.subscribe('e', self.__sequence2_e4)
            self.__api.subscribe('e', self.__sequence2_e5)
            self.__api.subscribe('e', self.__sequence2_e6)
            self.__api.subscribe('e', self.__sequence2_e7)
            self.__api.subscribe('e', self.__sequence2_e8)
            self.__api.subscribe('sequence2', self.__sequence2)
            self.__api.subscribe('f1', self.__sequence3_f1)
            self.__api.subscribe('f2', self.__sequence3_f2)
            self.__api.subscribe('g1', self.__sequence3_g1)
            self.__api.subscribe('sequence3', self.__sequence3)
    
            result = self.__api.poll()
            print 'exited thread:', result
        except:
            traceback.print_exc(file=sys.stdout)

    def __sequence1_abcd(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/b/c/d')
        assert request == 'test1'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1_abc_(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/b/c/*')
        assert request == 'test2' or request == 'test3'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1_ab_d(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/b/*/d')
        assert request == 'test4' or request == 'test5'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1_a_cd(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/*/c/d')
        assert request == 'test6' or request == 'test7'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1__bcd(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + '*/b/c/d')
        assert request == 'test8' or request == 'test9'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1_ab__(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/b/*')
        assert request == 'test10'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1_a__d(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/*/d')
        assert request == 'test11'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1___cd(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + '*/c/d')
        assert request == 'test12'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1_a___(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/*')
        assert request == 'test13'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1____d(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + '*/d')
        assert request == 'test14'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1_____(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + '*')
        assert request == 'test15'
        self.__api.return_(command, name, pattern,
                           '', request, timeout, transId, pid)

    def __sequence1(self, command, name, pattern, requestInfo, request,
                    timeout, priority, transId, pid):
        print 'messaging sequence1 start python'
        assert request == 'start'
        # n.b., depends on cloudi_constants.hrl having
        # SERVICE_NAME_PATTERN_MATCHING defined
        test1_id = self.__api.send_async(
            self.__api.prefix() + 'a/b/c/d',  'test1'
        )
        test2_id = self.__api.send_async(
            self.__api.prefix() + 'a/b/c/z',  'test2'
        )
        test3_id = self.__api.send_async(
            self.__api.prefix() + 'a/b/c/dd', 'test3'
        )
        test4_id = self.__api.send_async(
            self.__api.prefix() + 'a/b/z/d',  'test4'
        )
        test5_id = self.__api.send_async(
            self.__api.prefix() + 'a/b/cc/d', 'test5'
        )
        test6_id = self.__api.send_async(
            self.__api.prefix() + 'a/z/c/d',  'test6'
        )
        test7_id = self.__api.send_async(
            self.__api.prefix() + 'a/bb/c/d', 'test7'
        )
        test8_id = self.__api.send_async(
            self.__api.prefix() + 'z/b/c/d',  'test8'
        )
        test9_id = self.__api.send_async(
            self.__api.prefix() + 'aa/b/c/d', 'test9'
        )
        test10_id = self.__api.send_async(
            self.__api.prefix() + 'a/b/czd',  'test10'
        )
        test11_id = self.__api.send_async(
            self.__api.prefix() + 'a/bzc/d',  'test11'
        )
        test12_id = self.__api.send_async(
            self.__api.prefix() + 'azb/c/d',  'test12'
        )
        test13_id = self.__api.send_async(
            self.__api.prefix() + 'a/bzczd',  'test13'
        )
        test14_id = self.__api.send_async(
            self.__api.prefix() + 'azbzc/d',  'test14'
        )
        test15_id = self.__api.send_async(
            self.__api.prefix() + 'azbzczd',  'test15'
        )
        # n.b., depends on cloudi_constants.hrl having
        # RECV_ASYNC_STRATEGY == recv_async_select_oldest
        (tmp, test1_check, test1_id_check) = self.__api.recv_async()
        assert test1_check == 'test1'
        assert test1_id_check == test1_id
        (tmp, test2_check, test2_id_check) = self.__api.recv_async()
        assert test2_check == 'test2'
        assert test2_id_check == test2_id
        (tmp, test3_check, test3_id_check) = self.__api.recv_async()
        assert test3_check == 'test3'
        assert test3_id_check == test3_id
        (tmp, test4_check, test4_id_check) = self.__api.recv_async()
        assert test4_check == 'test4'
        assert test4_id_check == test4_id
        (tmp, test5_check, test5_id_check) = self.__api.recv_async()
        assert test5_check == 'test5'
        assert test5_id_check == test5_id
        (tmp, test6_check, test6_id_check) = self.__api.recv_async()
        assert test6_check == 'test6'
        assert test6_id_check == test6_id
        (tmp, test7_check, test7_id_check) = self.__api.recv_async()
        assert test7_check == 'test7'
        assert test7_id_check == test7_id
        (tmp, test8_check, test8_id_check) = self.__api.recv_async()
        assert test8_check == 'test8'
        assert test8_id_check == test8_id
        (tmp, test9_check, test9_id_check) = self.__api.recv_async()
        assert test9_check == 'test9'
        assert test9_id_check == test9_id
        (tmp, test10_check, test10_id_check) = self.__api.recv_async()
        assert test10_check == 'test10'
        assert test10_id_check == test10_id
        (tmp, test11_check, test11_id_check) = self.__api.recv_async()
        assert test11_check == 'test11'
        assert test11_id_check == test11_id
        (tmp, test12_check, test12_id_check) = self.__api.recv_async()
        assert test12_check == 'test12'
        assert test12_id_check == test12_id
        (tmp, test13_check, test13_id_check) = self.__api.recv_async()
        assert test13_check == 'test13'
        assert test13_id_check == test13_id
        (tmp, test14_check, test14_id_check) = self.__api.recv_async()
        assert test14_check == 'test14'
        assert test14_id_check == test14_id
        (tmp, test15_check, test15_id_check) = self.__api.recv_async()
        assert test15_check == 'test15'
        assert test15_id_check == test15_id
        print 'messaging sequence1 end python'
        # start sequence2
        self.__api.send_async(self.__api.prefix() + 'sequence2', 'start')
        self.__api.return_(command, name, pattern,
                           '', 'end', timeout, transId, pid)

    def __sequence2_e1(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern,
                           '', '1', timeout, transId, pid)

    def __sequence2_e2(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern,
                           '', '2', timeout, transId, pid)

    def __sequence2_e3(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern,
                           '', '3', timeout, transId, pid)

    def __sequence2_e4(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern,
                           '', '4', timeout, transId, pid)

    def __sequence2_e5(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern,
                           '', '5', timeout, transId, pid)

    def __sequence2_e6(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern,
                           '', '6', timeout, transId, pid)

    def __sequence2_e7(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern,
                           '', '7', timeout, transId, pid)

    def __sequence2_e8(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern,
                           '', '8', timeout, transId, pid)

    def __sequence2(self, command, name, pattern, requestInfo, request,
                    timeout, priority, transId, pid):
        print 'messaging sequence2 start python'
        assert request == 'start'
        time.sleep(0.5)
        # the sending process is excluded from the services that receive
        # the asynchronous message, so in this case, the receiving thread
        # will not be called, despite the fact it has subscribed to 'e',
        # to prevent a process (in this case thread) from deadlocking
        # with itself.
        e_ids = self.__api.mcast_async(self.__api.prefix() + 'e', ' ')
        # 4 * 8 == 32, but only 3 out of 4 threads can receive messages,
        # since 1 thread is sending the mcast_async, so 3 * 8 == 24
        assert len(e_ids) == 24
        e_check_list = []
        for e_id in e_ids:
            (tmp, e_check, e_id_check) = self.__api.recv_async(transId=e_id)
            assert e_id == e_id_check
            e_check_list.append(e_check)
        e_check_list.sort()
        assert ''.join(e_check_list) == '111222333444555666777888'
        print 'messaging sequence2 end python'
        # start sequence3
        self.__api.send_async(self.__api.prefix() + 'sequence3', 'start')
        self.__api.return_(command, name, pattern,
                           '', 'end', timeout, transId, pid)

    def __sequence3_f1(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        request_i = int(request)
        if request_i == 4:
            return 'done'
        request_new = request_i + 2 # two steps forward
        self.__api.forward_(command, self.__api.prefix() + 'f2',
                            requestInfo, str(request_new),
                            timeout, priority, transId, pid)
                           
    def __sequence3_f2(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        request_i = int(request)
        request_new = request_i - 1 # one step back
        self.__api.forward_(command, self.__api.prefix() + 'f1',
                            requestInfo, str(request_new),
                            timeout, priority, transId, pid)

    def __sequence3_g1(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern,
                           '', request + 'suffix', timeout, transId, pid)

    def __sequence3(self, command, name, pattern, requestInfo, request,
                    timeout, priority, transId, pid):
        print 'messaging sequence3 start python'
        assert request == 'start'
        test1_id = self.__api.send_async(
            self.__api.prefix() + 'f1',  '0'
        )
        (tmp, test1_check, test1_id_check) = self.__api.recv_async(
            transId=test1_id
        )
        assert test1_id_check == test1_id
        assert test1_check == 'done'
        (tmp, test2_check, test2_id_check) = self.__api.send_sync(
            self.__api.prefix() + 'g1',  'prefix_'
        )
        assert test2_check == 'prefix_suffix'
        print 'messaging sequence3 end python'
        self.__api.return_(command, name, pattern,
                           '', 'end', timeout, transId, pid)
예제 #6
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)
        self.__index = thread_index

    def run(self):
        try:
            # sends outside of a callback function must occur before the
            # subscriptions so that the incoming requests do not interfere with
            # the outgoing sends (i.e., without subscriptions there will be no
            # incoming requests)
            if self.__index == 0:
                # start sequence1
                self.__api.send_async(
                    self.__api.prefix() + 'sequence1',
                    'start',
                )
            self.__api.subscribe('a/b/c/d', self.__sequence1_abcd)
            self.__api.subscribe('a/b/c/*', self.__sequence1_abc_)
            self.__api.subscribe('a/b/*/d', self.__sequence1_ab_d)
            self.__api.subscribe('a/*/c/d', self.__sequence1_a_cd)
            self.__api.subscribe('*/b/c/d', self.__sequence1__bcd)
            self.__api.subscribe('a/b/*', self.__sequence1_ab__)
            self.__api.subscribe('a/*/d', self.__sequence1_a__d)
            self.__api.subscribe('*/c/d', self.__sequence1___cd)
            self.__api.subscribe('a/*', self.__sequence1_a___)
            self.__api.subscribe('*/d', self.__sequence1____d)
            self.__api.subscribe('*', self.__sequence1_____)
            self.__api.subscribe('sequence1', self.__sequence1)
            self.__api.subscribe('e', self.__sequence2_e1)
            self.__api.subscribe('e', self.__sequence2_e2)
            self.__api.subscribe('e', self.__sequence2_e3)
            self.__api.subscribe('e', self.__sequence2_e4)
            self.__api.subscribe('e', self.__sequence2_e5)
            self.__api.subscribe('e', self.__sequence2_e6)
            self.__api.subscribe('e', self.__sequence2_e7)
            self.__api.subscribe('e', self.__sequence2_e8)
            self.__api.subscribe('sequence2', self.__sequence2)
            self.__api.subscribe('f1', self.__sequence3_f1)
            self.__api.subscribe('f2', self.__sequence3_f2)
            self.__api.subscribe('g1', self.__sequence3_g1)
            self.__api.subscribe('sequence3', self.__sequence3)

            result = self.__api.poll()
            print 'exited thread:', result
        except:
            traceback.print_exc(file=sys.stdout)

    def __sequence1_abcd(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/b/c/d')
        assert request == 'test1'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1_abc_(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/b/c/*')
        assert request == 'test2' or request == 'test3'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1_ab_d(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/b/*/d')
        assert request == 'test4' or request == 'test5'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1_a_cd(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/*/c/d')
        assert request == 'test6' or request == 'test7'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1__bcd(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + '*/b/c/d')
        assert request == 'test8' or request == 'test9'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1_ab__(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/b/*')
        assert request == 'test10'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1_a__d(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/*/d')
        assert request == 'test11'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1___cd(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + '*/c/d')
        assert request == 'test12'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1_a___(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + 'a/*')
        assert request == 'test13'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1____d(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + '*/d')
        assert request == 'test14'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1_____(self, command, name, pattern, requestInfo, request,
                         timeout, priority, transId, pid):
        assert pattern == (self.__api.prefix() + '*')
        assert request == 'test15'
        self.__api.return_(command, name, pattern, '', request, timeout,
                           transId, pid)

    def __sequence1(self, command, name, pattern, requestInfo, request,
                    timeout, priority, transId, pid):
        print 'messaging sequence1 start python'
        assert request == 'start'
        # n.b., depends on cloudi_constants.hrl having
        # SERVICE_NAME_PATTERN_MATCHING defined
        test1_id = self.__api.send_async(self.__api.prefix() + 'a/b/c/d',
                                         'test1')
        test2_id = self.__api.send_async(self.__api.prefix() + 'a/b/c/z',
                                         'test2')
        test3_id = self.__api.send_async(self.__api.prefix() + 'a/b/c/dd',
                                         'test3')
        test4_id = self.__api.send_async(self.__api.prefix() + 'a/b/z/d',
                                         'test4')
        test5_id = self.__api.send_async(self.__api.prefix() + 'a/b/cc/d',
                                         'test5')
        test6_id = self.__api.send_async(self.__api.prefix() + 'a/z/c/d',
                                         'test6')
        test7_id = self.__api.send_async(self.__api.prefix() + 'a/bb/c/d',
                                         'test7')
        test8_id = self.__api.send_async(self.__api.prefix() + 'z/b/c/d',
                                         'test8')
        test9_id = self.__api.send_async(self.__api.prefix() + 'aa/b/c/d',
                                         'test9')
        test10_id = self.__api.send_async(self.__api.prefix() + 'a/b/czd',
                                          'test10')
        test11_id = self.__api.send_async(self.__api.prefix() + 'a/bzc/d',
                                          'test11')
        test12_id = self.__api.send_async(self.__api.prefix() + 'azb/c/d',
                                          'test12')
        test13_id = self.__api.send_async(self.__api.prefix() + 'a/bzczd',
                                          'test13')
        test14_id = self.__api.send_async(self.__api.prefix() + 'azbzc/d',
                                          'test14')
        test15_id = self.__api.send_async(self.__api.prefix() + 'azbzczd',
                                          'test15')
        # n.b., depends on cloudi_constants.hrl having
        # RECV_ASYNC_STRATEGY == recv_async_select_oldest
        (tmp, test1_check, test1_id_check) = self.__api.recv_async()
        assert test1_check == 'test1'
        assert test1_id_check == test1_id
        (tmp, test2_check, test2_id_check) = self.__api.recv_async()
        assert test2_check == 'test2'
        assert test2_id_check == test2_id
        (tmp, test3_check, test3_id_check) = self.__api.recv_async()
        assert test3_check == 'test3'
        assert test3_id_check == test3_id
        (tmp, test4_check, test4_id_check) = self.__api.recv_async()
        assert test4_check == 'test4'
        assert test4_id_check == test4_id
        (tmp, test5_check, test5_id_check) = self.__api.recv_async()
        assert test5_check == 'test5'
        assert test5_id_check == test5_id
        (tmp, test6_check, test6_id_check) = self.__api.recv_async()
        assert test6_check == 'test6'
        assert test6_id_check == test6_id
        (tmp, test7_check, test7_id_check) = self.__api.recv_async()
        assert test7_check == 'test7'
        assert test7_id_check == test7_id
        (tmp, test8_check, test8_id_check) = self.__api.recv_async()
        assert test8_check == 'test8'
        assert test8_id_check == test8_id
        (tmp, test9_check, test9_id_check) = self.__api.recv_async()
        assert test9_check == 'test9'
        assert test9_id_check == test9_id
        (tmp, test10_check, test10_id_check) = self.__api.recv_async()
        assert test10_check == 'test10'
        assert test10_id_check == test10_id
        (tmp, test11_check, test11_id_check) = self.__api.recv_async()
        assert test11_check == 'test11'
        assert test11_id_check == test11_id
        (tmp, test12_check, test12_id_check) = self.__api.recv_async()
        assert test12_check == 'test12'
        assert test12_id_check == test12_id
        (tmp, test13_check, test13_id_check) = self.__api.recv_async()
        assert test13_check == 'test13'
        assert test13_id_check == test13_id
        (tmp, test14_check, test14_id_check) = self.__api.recv_async()
        assert test14_check == 'test14'
        assert test14_id_check == test14_id
        (tmp, test15_check, test15_id_check) = self.__api.recv_async()
        assert test15_check == 'test15'
        assert test15_id_check == test15_id
        print 'messaging sequence1 end python'
        # start sequence2
        self.__api.send_async(self.__api.prefix() + 'sequence2', 'start')
        self.__api.return_(command, name, pattern, '', 'end', timeout, transId,
                           pid)

    def __sequence2_e1(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern, '', '1', timeout, transId,
                           pid)

    def __sequence2_e2(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern, '', '2', timeout, transId,
                           pid)

    def __sequence2_e3(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern, '', '3', timeout, transId,
                           pid)

    def __sequence2_e4(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern, '', '4', timeout, transId,
                           pid)

    def __sequence2_e5(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern, '', '5', timeout, transId,
                           pid)

    def __sequence2_e6(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern, '', '6', timeout, transId,
                           pid)

    def __sequence2_e7(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern, '', '7', timeout, transId,
                           pid)

    def __sequence2_e8(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern, '', '8', timeout, transId,
                           pid)

    def __sequence2(self, command, name, pattern, requestInfo, request,
                    timeout, priority, transId, pid):
        print 'messaging sequence2 start python'
        assert request == 'start'
        time.sleep(0.5)
        # the sending process is excluded from the services that receive
        # the asynchronous message, so in this case, the receiving thread
        # will not be called, despite the fact it has subscribed to 'e',
        # to prevent a process (in this case thread) from deadlocking
        # with itself.
        e_ids = self.__api.mcast_async(self.__api.prefix() + 'e', ' ')
        # 4 * 8 == 32, but only 3 out of 4 threads can receive messages,
        # since 1 thread is sending the mcast_async, so 3 * 8 == 24
        assert len(e_ids) == 24
        e_check_list = []
        for e_id in e_ids:
            (tmp, e_check, e_id_check) = self.__api.recv_async(transId=e_id)
            assert e_id == e_id_check
            e_check_list.append(e_check)
        e_check_list.sort()
        assert ''.join(e_check_list) == '111222333444555666777888'
        print 'messaging sequence2 end python'
        # start sequence3
        self.__api.send_async(self.__api.prefix() + 'sequence3', 'start')
        self.__api.return_(command, name, pattern, '', 'end', timeout, transId,
                           pid)

    def __sequence3_f1(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        request_i = int(request)
        if request_i == 4:
            return 'done'
        request_new = request_i + 2  # two steps forward
        self.__api.forward_(command,
                            self.__api.prefix() + 'f2', requestInfo,
                            str(request_new), timeout, priority, transId, pid)

    def __sequence3_f2(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        request_i = int(request)
        request_new = request_i - 1  # one step back
        self.__api.forward_(command,
                            self.__api.prefix() + 'f1', requestInfo,
                            str(request_new), timeout, priority, transId, pid)

    def __sequence3_g1(self, command, name, pattern, requestInfo, request,
                       timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern, '', request + 'suffix',
                           timeout, transId, pid)

    def __sequence3(self, command, name, pattern, requestInfo, request,
                    timeout, priority, transId, pid):
        print 'messaging sequence3 start python'
        assert request == 'start'
        test1_id = self.__api.send_async(self.__api.prefix() + 'f1', '0')
        (tmp, test1_check,
         test1_id_check) = self.__api.recv_async(transId=test1_id)
        assert test1_id_check == test1_id
        assert test1_check == 'done'
        (tmp, test2_check,
         test2_id_check) = self.__api.send_sync(self.__api.prefix() + 'g1',
                                                'prefix_')
        assert test2_check == 'prefix_suffix'
        print 'messaging sequence3 end python'
        self.__api.return_(command, name, pattern, '', 'end', timeout, transId,
                           pid)