Пример #1
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        # pylint: disable=bare-except
        try:
            self.__api.subscribe('text/post', self.__text)

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

    def __text(self, request_type, name, pattern, request_info, request,
               timeout, priority, trans_id, pid):
        # pylint: disable=unused-argument
        # pylint: disable=too-many-arguments
        print(b'(' + request + b')')
        assert request == b'Test Text'
        self.__api.return_(request_type, name, pattern, b'', b'Test Response',
                           timeout, trans_id, pid)
Пример #2
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)
Пример #3
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, 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)
Пример #4
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)
Пример #5
0
def _main():
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [Task(API(thread_index), 'python', TerminateException)
               for thread_index in range(thread_count)]
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
Пример #6
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.flood)

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

    def flood(self, command, name, pattern, request_info, request,
              timeout, priority, trans_id, pid):
        self.__api.return_(command, name, pattern,
                           '', 'python', timeout, trans_id, pid)
Пример #7
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.flood)

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

    def flood(self, command, name, pattern, request_info, request,
              timeout, priority, transId, pid):
        self.__api.return_(command, name, pattern,
                           '', 'python', timeout, transId, pid)
Пример #8
0
def _main():
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [_Task(thread_index) for thread_index in range(thread_count)]
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
Пример #9
0
def _main():
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [Task(API(thread_index), 'python', TerminateException)
               for thread_index in range(thread_count)]
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
Пример #10
0
class _Task(threading.Thread):
    def __init__(self, index, protocol, size):
        threading.Thread.__init__(self)
        self.__api = API(index, protocol, size)

    def flood(self, command, name, request, timeout, transId, pid):
        self.__api.return_(command, name, "python", timeout, transId, pid)

    def run(self):
        self.__api.subscribe("python", self.flood)

        running = True
        while running:
            result = self.__api.poll()
            if result is None:
                running = False
            else:
                print "(python) received:",result
        print "exited thread"
Пример #11
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('text/post', self.text)

            result = self.__api.poll()
            assert result == None
        except:
            traceback.print_exc(file=sys.stderr)

    def text(self, command, name, pattern, request_info, request,
             timeout, priority, trans_id, pid):
        print(b'(' + request + b')')
        assert b'Test Text' == request
        self.__api.return_(command, name, pattern, b'', b'Test Response',
                           timeout, trans_id, pid)
Пример #12
0
    def __request(self, request_type, name, pattern, request_info, request,
                  timeout, priority, trans_id, pid):
        # pylint: disable=unused-argument
        # pylint: disable=too-many-arguments
        http_qs = API.info_key_value_parse(request)
        value = http_qs.get(b'value', None)
        if value is None:
            response = """\
<http_test><error>no value specified</error></http_test>"""
        else:
            if isinstance(value, list):
                value = value[0]
            response = """\
<http_test><value>%d</value></http_test>""" % (int(value), )
        response_info = API.info_key_value_new({
            b'content-type':
            b'text/xml; charset=utf-8',
        })
        self.__api.return_(request_type, name, pattern, response_info,
                           response.encode('utf-8'), timeout, trans_id, pid)
Пример #13
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        try:
            #print '> 32 characters to test stdout<'
            self.__api.subscribe('text/post', self.text)

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

    def text(self, command, name, pattern, request_info, request, timeout,
             priority, trans_id, pid):
        print '(' + request + ')'
        assert 'Test Text' == request
        self.__api.return_(command, name, pattern, '', 'Test Response',
                           timeout, trans_id, pid)
Пример #14
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def run(self):
        try:
            #print '> 32 characters to test stdout<'
            self.__api.subscribe('text/post', self.text)

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

    def text(self, command, name, pattern, requestInfo, request,
             timeout, priority, transId, pid):
        print '(' + request + ')'
        assert 'Test Text' == request
        self.__api.return_(command, name, pattern, '', 'Test Response',
                           timeout, transId, pid)
Пример #15
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("text/post", self.text)

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

    def text(self, command, name, pattern, request_info, request, timeout, priority, trans_id, pid):
        print(b"(" + request + b")")
        assert b"Test Text" == request
        self.__api.return_(command, name, pattern, b"", b"Test Response", timeout, trans_id, pid)
Пример #16
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def request(self, command, name, requestInfo, request,
                timeout, priority, transId, pid):
        http_qs = self.__api.request_http_qs_parse(request)
        value = http_qs.get('value', None)
        if value is None:
            response = """\
<http_test><error>no value specified</error></http_test>"""
        else:
            if type(value) == types.ListType:
                value = value[0]
            response = """\
<http_test><value>%d</value></http_test>""" % (int(value),)
        self.__api.return_(command, name, '', response, timeout, transId, pid)

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

        running = True
        while running:
            result = self.__api.poll()
            if result is None:
                running = False
            else:
                print '(python) received:',result
        print 'exited thread'
Пример #17
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.xml/get', self.request)

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

    def request(self, command, name, pattern, requestInfo, request,
                timeout, priority, transId, pid):
        http_qs = self.__api.request_http_qs_parse(request)
        value = http_qs.get('value', None)
        if value is None:
            response = """\
<http_test><error>no value specified</error></http_test>"""
        else:
            if type(value) == types.ListType:
                value = value[0]
            response = """\
<http_test><value>%d</value></http_test>""" % (int(value),)
        self.__api.return_(command, name, pattern,
                           '', response, timeout, transId, pid)
Пример #18
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.xml/get', self.request)

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

    def request(self, command, name, pattern, requestInfo, request, timeout,
                priority, transId, pid):
        http_qs = self.__api.request_http_qs_parse(request)
        value = http_qs.get('value', None)
        if value is None:
            response = """\
<http_test><error>no value specified</error></http_test>"""
        else:
            if type(value) == types.ListType:
                value = value[0]
            response = """\
<http_test><value>%d</value></http_test>""" % (int(value), )
        self.__api.return_(command, name, pattern, '', response, timeout,
                           transId, pid)
Пример #19
0
 def __request(self, request_type, name, pattern, request_info, request,
               timeout, priority, trans_id, pid):
     # pylint: disable=unused-argument
     # pylint: disable=too-many-arguments
     if self.__count == 4294967295:
         self.__count = 0
     else:
         self.__count += 1
     print('count == %d %s' % (self.__count, self.__name))
     response = b'%d' % self.__count
     response_info = API.info_key_value_new({})
     self.__api.return_(request_type, name, pattern, response_info,
                        response, timeout, trans_id, pid)
Пример #20
0
class _Task(threading.Thread):
    def __init__(self, index, protocol, size):
        threading.Thread.__init__(self)
        self.__api = API(index, protocol, size)

    def text(self, command, name, request, timeout, transId, pid):
        print "(" + request + ")"
        assert "Test Text" == request
        self.__api.return_(command, name, "Test Response",
                           timeout, transId, pid)

    def run(self):
        #print "> 32 characters to test stdout<"
        self.__api.subscribe("text", self.text)

        running = True
        while running:
            result = self.__api.poll()
            if result is None:
                running = False
            else:
                print "(python) received:",result
        print "exited thread"
Пример #21
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('text/post', self.text)

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

    def text(self, request_type, name, pattern, request_info, request, timeout,
             priority, trans_id, pid):
        print(b'(' + request + b')')
        assert b'Test Text' == request
        self.__api.return_(request_type, name, pattern, b'', b'Test Response',
                           timeout, trans_id, pid)
Пример #22
0
class _Task(threading.Thread):
    def __init__(self, index, protocol, size):
        threading.Thread.__init__(self)
        self.__api = API(index, protocol, size)

    def text(self, command, name, request, timeout, transId, pid):
        print "(" + request + ")"
        assert "Test Text" == request
        self.__api.return_(command, name, "Test Response", timeout, transId,
                           pid)

    def run(self):
        #print "> 32 characters to test stdout<"
        self.__api.subscribe("text", self.text)

        running = True
        while running:
            result = self.__api.poll()
            if result is None:
                running = False
            else:
                print "(python) received:", result
        print "exited thread"
Пример #23
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)
Пример #24
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)

    def text(self, command, name, requestInfo, request,
             timeout, priority, transId, pid):
        print '(' + request + ')'
        assert 'Test Text' == request
        self.__api.return_(command, name, '', 'Test Response',
                           timeout, transId, pid)

    def run(self):
        #print '> 32 characters to test stdout<'
        self.__api.subscribe('text/post', self.text)

        running = True
        while running:
            result = self.__api.poll()
            if result is None:
                running = False
            else:
                print '(python) received:',result
        print 'exited thread'
Пример #25
0
        print 'messaging sequence3 start ' + self.__name
        assert request == 'start'
        test1_id = self.__api.send_async(self.__api.prefix() + 'f1', '0')
        (tmp, test1_check,
         test1_id_check) = self.__api.recv_async(trans_id=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 ' + self.__name
        # loop to find any infrequent problems, restart sequence1
        self.__api.send_async(
            self.__api.prefix() + 'sequence1',
            'start',
        )
        self.__api.return_(command, name, pattern, '', 'end', timeout,
                           trans_id, pid)


if __name__ == '__main__':
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [Task(API(i), i, 'python') for i in range(thread_count)]
    for t in threads:
        t.start()
    for t in threads:
        t.join()
Пример #26
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)
Пример #27
0
class _Task(threading.Thread):
    def __init__(self, index, protocol, size):
        threading.Thread.__init__(self)
        self.__api = API(index, protocol, size)
        self.__index = index

    def zigzag_finish(self, command, name, request, timeout, transId, pid):
        print "Got to CloudI finish from ZeroMQ zig-zag:", request
        self.__api.return_(command, name, "done", timeout, transId, pid)

    def chain_inproc_finish(self, command, name, request, timeout, transId,
                            pid):
        print "chain_inproc_finish"
        self.__api.return_(command, name, "done", timeout, transId, pid)

    def chain_ipc_finish(self, command, name, request, timeout, transId, pid):
        print "chain_ipc_finish"
        self.__api.return_(command, name, "done", timeout, transId, pid)

    def run(self):
        # sends outside of a callback must occur before the subscriptions
        # so that the sends going out do not conflict with the
        # sends coming in to call local callbacks
        if self.__index == 0:
            self.__api.send_async_("/tests/zeromq/zigzag_start", "magic")
            self.__api.send_async_("/tests/zeromq/chain_inproc_start",
                                   "inproc")
            self.__api.send_async_("/tests/zeromq/chain_ipc_start", "ipc")
        self.__api.subscribe("zigzag_finish", self.zigzag_finish)
        self.__api.subscribe("chain_inproc_finish", self.chain_inproc_finish)
        self.__api.subscribe("chain_ipc_finish", self.chain_ipc_finish)
        running = True
        while running:
            result = self.__api.poll()
            if result is None:
                running = False
            else:
                print "(python) received:", result
        print "exited thread"
Пример #28
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):
        # Unable to receive messages in the 1st thread, because ZeroMQ usage
        # removes the association between Erlang pids and CloudI API requests
        # (i.e., otherwise the sending thread could receive the sent
        #  message, with this test ZeroMQ configuration)
        if self.__index == 0:
            print 'zeromq zigzag start'
            self.__api.send_async('/tests/zeromq/zigzag_start', 'magic')
            print 'zeromq chain_inproc start'
            self.__api.send_async('/tests/zeromq/chain_inproc_start', 'inproc')
            print 'zeromq chain_ipc start'
            self.__api.send_async('/tests/zeromq/chain_ipc_start', 'ipc')
        else:
            self.__api.subscribe('zigzag_finish', self.zigzag_finish)
            self.__api.subscribe('chain_inproc_finish',
                                 self.chain_inproc_finish)
            self.__api.subscribe('chain_ipc_finish', self.chain_ipc_finish)
        result = self.__api.poll()
        print 'exited thread:', result

    def zigzag_finish(self, command, name, pattern, request_info, request,
                      timeout, priority, trans_id, pid):
        assert request == 'magic'
        print 'zeromq zigzag end'
        self.__api.return_(command, name, pattern, '', 'done', timeout,
                           trans_id, pid)

    def chain_inproc_finish(self, command, name, pattern, request_info,
                            request, timeout, priority, trans_id, pid):
        print 'zeromq chain_inproc end'
        self.__api.return_(command, name, pattern, '', 'done', timeout,
                           trans_id, pid)

    def chain_ipc_finish(self, command, name, pattern, request_info, request,
                         timeout, priority, trans_id, pid):
        print 'zeromq chain_ipc end'
        self.__api.return_(command, name, pattern, '', 'done', timeout,
                           trans_id, pid)
Пример #29
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)
Пример #30
0
 def __init__(self, thread_index):
     threading.Thread.__init__(self)
     self.__api = API(thread_index)
Пример #31
0
    def run(self):
        try:
            self.__api.subscribe('text/post', self.text)

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

    def text(self, request_type, name, pattern, request_info, request, timeout,
             priority, trans_id, pid):
        print(b'(' + request + b')')
        assert b'Test Text' == request
        self.__api.return_(request_type, name, pattern, b'', b'Test Response',
                           timeout, trans_id, pid)


if __name__ == '__main__':
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [_Task(i) for i in range(thread_count)]
    for t in threads:
        t.start()
    for t in threads:
        t.join()
Пример #32
0
 def __init__(self, index, protocol, size):
     threading.Thread.__init__(self)
     self.__api = API(index, protocol, size)
Пример #33
0
class _Task(threading.Thread):
    def __init__(self, index, protocol, size):
        threading.Thread.__init__(self)
        self.__api = API(index, protocol, size)
        self.__index = index

    def zigzag_finish(self, command, name, request, timeout, transId, pid):
        print "Got to CloudI finish from ZeroMQ zig-zag:",request
        self.__api.return_(command, name, "done", timeout, transId, pid)

    def chain_inproc_finish(self, command, name, request,
                            timeout, transId, pid):
        print "chain_inproc_finish"
        self.__api.return_(command, name, "done", timeout, transId, pid)

    def chain_ipc_finish(self, command, name, request,
                         timeout, transId, pid):
        print "chain_ipc_finish"
        self.__api.return_(command, name, "done", timeout, transId, pid)

    def run(self):
        # sends outside of a callback must occur before the subscriptions
        # so that the sends going out do not conflict with the
        # sends coming in to call local callbacks
        if self.__index == 0:
            self.__api.send_async_("/tests/zeromq/zigzag_start", "magic")
            self.__api.send_async_("/tests/zeromq/chain_inproc_start", "inproc")
            self.__api.send_async_("/tests/zeromq/chain_ipc_start", "ipc")
        self.__api.subscribe("zigzag_finish", self.zigzag_finish)
        self.__api.subscribe("chain_inproc_finish", self.chain_inproc_finish)
        self.__api.subscribe("chain_ipc_finish", self.chain_ipc_finish)
        running = True
        while running:
            result = self.__api.poll()
            if result is None:
                running = False
            else:
                print "(python) received:",result
        print "exited thread"
Пример #34
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):
        # Unable to receive messages in the 1st thread, because ZeroMQ usage
        # removes the association between Erlang pids and CloudI API requests
        # (i.e., otherwise the sending thread could receive the sent
        #  message, with this test ZeroMQ configuration)
        if self.__index == 0:
            print('zeromq zigzag start')
            self.__api.send_async('/tests/zeromq/zigzag_start',
                                  b'magic', request_info=b'amazing')
            print('zeromq chain_inproc start')
            self.__api.send_async('/tests/zeromq/chain_inproc_start',
                                  b'inproc', request_info=b'process')
            print('zeromq chain_ipc start')
            self.__api.send_async('/tests/zeromq/chain_ipc_start',
                                  b'ipc', request_info=b'pipes')
        else:
            self.__api.subscribe('zigzag_finish',
                                 self.zigzag_finish)
            self.__api.subscribe('chain_inproc_finish',
                                 self.chain_inproc_finish)
            self.__api.subscribe('chain_ipc_finish',
                                 self.chain_ipc_finish)
        result = self.__api.poll()
        assert result == None

    def zigzag_finish(self, command, name, pattern,
                      request_info, request,
                      timeout, priority, trans_id, pid):
        assert request_info == b'amazing'
        assert request == b'magic'
        print('zeromq zigzag end')
        self.__api.return_(command, name, pattern,
                           b'', b'done', timeout, trans_id, pid)

    def chain_inproc_finish(self, command, name, pattern,
                            request_info, request,
                            timeout, priority, trans_id, pid):
        assert request_info == b'process'
        assert request == b'inproc'
        print('zeromq chain_inproc end')
        self.__api.return_(command, name, pattern,
                           b'', b'done', timeout, trans_id, pid)

    def chain_ipc_finish(self, command, name, pattern,
                         request_info, request,
                         timeout, priority, trans_id, pid):
        assert request_info == b'pipes'
        assert request == b'ipc'
        print('zeromq chain_ipc end')
        self.__api.return_(command, name, pattern,
                           b'', b'done', timeout, trans_id, pid)
Пример #35
0
        print('terminate http_req %s' % self.__name)

    def request(self, request_type, name, pattern, request_info, request,
                timeout, priority, trans_id, pid):
        http_qs = self.__api.info_key_value_parse(request)
        value = http_qs.get(b'value', None)
        if value is None:
            response = """\
<http_test><error>no value specified</error></http_test>"""
        else:
            if type(value) == list:
                value = value[0]
            response = """\
<http_test><value>%d</value></http_test>""" % (int(value), )
        self.__api.return_(request_type, name, pattern, b'',
                           response.encode('utf-8'), timeout, trans_id, pid)


if __name__ == '__main__':
    thread_count = API.thread_count()
    assert thread_count >= 1

    threads = [
        Task(API(i), 'python', terminate_exception)
        for i in range(thread_count)
    ]
    for t in threads:
        t.start()
    for t in threads:
        t.join()
Пример #36
0
class _Task(threading.Thread):
    def __init__(self, thread_index):
        threading.Thread.__init__(self)
        self.__api = API(thread_index)
        self.__index = thread_index

    def zigzag_finish(self, command, name, requestInfo, request,
                      timeout, priority, transId, pid):
        print 'Got to CloudI finish from ZeroMQ zig-zag:',request
        self.__api.return_(command, name, '', 'done', timeout, transId, pid)

    def chain_inproc_finish(self, command, name, requestInfo, request,
                            timeout, priority, transId, pid):
        print 'chain_inproc_finish'
        self.__api.return_(command, name, '', 'done', timeout, transId, pid)

    def chain_ipc_finish(self, command, name, requestInfo, request,
                         timeout, priority, transId, pid):
        print 'chain_ipc_finish'
        self.__api.return_(command, name, '', 'done', timeout, transId, pid)

    def run(self):
        # sends outside of a callback must occur before the subscriptions
        # so that the sends going out do not conflict with the
        # sends coming in to call local callbacks
        if self.__index == 0:
            self.__api.send_async('/tests/zeromq/zigzag_start', 'magic')
            self.__api.send_async('/tests/zeromq/chain_inproc_start', 'inproc')
            self.__api.send_async('/tests/zeromq/chain_ipc_start', 'ipc')
        self.__api.subscribe('zigzag_finish', self.zigzag_finish)
        self.__api.subscribe('chain_inproc_finish', self.chain_inproc_finish)
        self.__api.subscribe('chain_ipc_finish', self.chain_ipc_finish)
        running = True
        while running:
            result = self.__api.poll()
            if result is None:
                running = False
            else:
                print '(python) received:',result
        print 'exited thread'
Пример #37
0
                           b'', b'done', timeout, trans_id, pid)

    def chain_inproc_finish(self, command, name, pattern,
                            request_info, request,
                            timeout, priority, trans_id, pid):
        assert request_info == b'process'
        assert request == b'inproc'
        print('zeromq chain_inproc end')
        self.__api.return_(command, name, pattern,
                           b'', b'done', timeout, trans_id, pid)

    def chain_ipc_finish(self, command, name, pattern,
                         request_info, request,
                         timeout, priority, trans_id, pid):
        assert request_info == b'pipes'
        assert request == b'ipc'
        print('zeromq chain_ipc end')
        self.__api.return_(command, name, pattern,
                           b'', b'done', timeout, trans_id, pid)

if __name__ == '__main__':
    thread_count = API.thread_count()
    assert thread_count >= 1
    
    threads = [_Task(i) for i in range(thread_count)]
    for t in threads:
        t.start()
    for t in threads:
        t.join()

Пример #38
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:
            # Unable to receive messages in the 1st thread,
            # because ZeroMQ usage removes the association between
            # Erlang pids and CloudI API requests
            # (i.e., otherwise the sending thread could receive the sent
            #  message, with this test ZeroMQ configuration)
            if self.__index == 0:
                print('zeromq zigzag start')
                self.__api.send_async('/tests/zeromq/zigzag_start',
                                      b'magic',
                                      request_info=b'amazing')
                print('zeromq chain_inproc start')
                self.__api.send_async('/tests/zeromq/chain_inproc_start',
                                      b'inproc',
                                      request_info=b'process')
                print('zeromq chain_ipc start')
                self.__api.send_async('/tests/zeromq/chain_ipc_start',
                                      b'ipc',
                                      request_info=b'pipes')
            else:
                self.__api.subscribe('zigzag_finish', self.zigzag_finish)
                self.__api.subscribe('chain_inproc_finish',
                                     self.chain_inproc_finish)
                self.__api.subscribe('chain_ipc_finish', self.chain_ipc_finish)
            result = self.__api.poll()
            assert result == False
        except terminate_exception:
            pass
        except:
            traceback.print_exc(file=sys.stderr)
        print('terminate zeromq python')

    def zigzag_finish(self, command, name, pattern, request_info, request,
                      timeout, priority, trans_id, pid):
        assert request_info == b'amazing'
        assert request == b'magic'
        print('zeromq zigzag end')
        self.__api.return_(command, name, pattern, b'', b'done', timeout,
                           trans_id, pid)

    def chain_inproc_finish(self, command, name, pattern, request_info,
                            request, timeout, priority, trans_id, pid):
        assert request_info == b'process'
        assert request == b'inproc'
        print('zeromq chain_inproc end')
        self.__api.return_(command, name, pattern, b'', b'done', timeout,
                           trans_id, pid)

    def chain_ipc_finish(self, command, name, pattern, request_info, request,
                         timeout, priority, trans_id, pid):
        assert request_info == b'pipes'
        assert request == b'ipc'
        print('zeromq chain_ipc end')
        self.__api.return_(command, name, pattern, b'', b'done', timeout,
                           trans_id, pid)
Пример #39
0
 def __init__(self, thread_index):
     threading.Thread.__init__(self)
     self.__api = API(thread_index)
     self.__index = thread_index
Пример #40
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):
        # 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:
            print 'zeromq zigzag start'
            self.__api.send_async('/tests/zeromq/zigzag_start', 'magic')
            print 'zeromq chain_inproc start'
            self.__api.send_async('/tests/zeromq/chain_inproc_start', 'inproc')
            print 'zeromq chain_ipc start'
            self.__api.send_async('/tests/zeromq/chain_ipc_start', 'ipc')
        self.__api.subscribe('zigzag_finish', self.zigzag_finish)
        self.__api.subscribe('chain_inproc_finish', self.chain_inproc_finish)
        self.__api.subscribe('chain_ipc_finish', self.chain_ipc_finish)

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

    def zigzag_finish(self, command, name, pattern,
                      requestInfo, request,
                      timeout, priority, transId, pid):
        assert request == 'magic'
        print 'zeromq zigzag end'
        self.__api.return_(command, name, pattern,
                           '', 'done', timeout, transId, pid)

    def chain_inproc_finish(self, command, name, pattern,
                            requestInfo, request,
                            timeout, priority, transId, pid):
        print 'zeromq chain_inproc end'
        self.__api.return_(command, name, pattern,
                           '', 'done', timeout, transId, pid)

    def chain_ipc_finish(self, command, name, pattern,
                         requestInfo, request,
                         timeout, priority, transId, pid):
        print 'zeromq chain_ipc end'
        self.__api.return_(command, name, pattern,
                           '', 'done', timeout, transId, pid)