Exemple #1
0
 def test_error_state(self):
     from stpclient import Client
     from stpclient.exceptions import STPNetworkError
     client = Client('localhost', 0, timeout=1)
     assert not client.closed
     try:
         client.call('ping')
     except STPNetworkError:
         pass
     assert client.closed
Exemple #2
0
 def test_timeout_state(self):
     from stpclient import Client
     from stpclient.exceptions import STPTimeoutError
     import time
     client = Client('localhost', 9999, timeout=1)
     assert not client.closed
     try:
         client.call('long')
     except STPTimeoutError:
         time.sleep(2)
     assert client.closed
     client.call('ping')
Exemple #3
0
def main():
    host = sys.argv[1]
    port = int(sys.argv[2])
    if len(sys.argv) > 3:
        count = int(sys.argv[3])
    else:
        count = 1
    client = Client(host, port, timeout=1)
    for i in range(count):
        try:
            print client.call('ping').argv
        except:
            logging.exception('')
            client.close()
        time.sleep(0.5)
Exemple #4
0
class MagicClient(local):
    def __init__(self, *args, **kwargs):
        self.client = Client(*args, **kwargs)

    def __getattr__(self, name):
        def stpcall(*args):
            resp = self.client.call((name,) + args).argv
            if resp[0] == 'ERR':
                raise Exception(resp[1])
            else:
                return resp[1:]
        return stpcall
Exemple #5
0
def test_sync():
    client = Client('localhost', 9999, timeout=1)
    try:
        print client.call('long')
    except Exception as e:
        print e
        time.sleep(1)
    print client.call('ping').argv
    print 'sleep 10s'
    time.sleep(10)
    print 'ping again'
    try:
        print client.call('ping').argv
    except Exception as e:
        print e
    time.sleep(10)
    print 'ping again'
    print client.call('ping').argv
Exemple #6
0
 def __init__(self, *args, **kwargs):
     self.client = Client(*args, **kwargs)
Exemple #7
0
 def test_not_timeout(self):
     from stpclient import Client
     client = Client('localhost', 9999, timeout=1)
     assert not client.closed
     client.call('ping')
Exemple #8
0
 def test_connect(self):
     from stpclient import Client
     client = Client('localhost', 9999, timeout=1)
     assert not client.closed
     client.close()
     assert client.closed
Exemple #9
0
 def test_ping(self):
     from stpclient import Client
     client = Client('localhost', 9999, timeout=1)
     resp = client.call('ping')
     eq_(resp[0], 'OK')
     eq_(resp[1], 'PONG')