コード例 #1
0
ファイル: test_jsonrpc.py プロジェクト: Ed-von-Schleck/gruvi
 def test_call_method_error(self):
     server = JsonRpcServer(echo_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     exc = self.assertRaises(JsonRpcError, client.call_method, 'echo2')
     self.assertIsInstance(exc, JsonRpcMethodCallError)
     self.assertIsInstance(exc.error, dict)
     self.assertEqual(exc.error['code'], jsonrpc.METHOD_NOT_FOUND)
     server.close()
     client.close()
コード例 #2
0
ファイル: test_jsonrpc.py プロジェクト: PlumpMath/gruvi
 def test_send_notification(self):
     server = JsonRpcServer(notification_app())
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     client.send_notification('notify_foo', 'foo')
     notifications = client.call_method('get_notifications')
     self.assertEqual(notifications, [['notify_foo', ['foo']]])
     server.close()
     client.close()
コード例 #3
0
ファイル: test_jsonrpc.py プロジェクト: geertj/gruvi
 def test_send_random(self):
     server = JsonRpcServer(echo_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     exc = None
     try:
         while True:
             chunk = os.urandom(1024)
             client.transport.write(chunk)
             gruvi.sleep(0)
     except Exception as e:
         exc = e
     self.assertIsInstance(exc, TransportError)
     server.close()
     client.close()
コード例 #4
0
ファイル: test_jsonrpc.py プロジェクト: Ed-von-Schleck/gruvi
 def test_send_notification(self):
     server = JsonRpcServer(notification_app())
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     client.send_notification('notify_foo', 'foo')
     notifications = client.call_method('get_notifications')
     self.assertEqual(notifications, [['notify_foo', ['foo']]])
     server.close()
     client.close()
コード例 #5
0
ファイル: test_jsonrpc.py プロジェクト: PlumpMath/gruvi
 def test_call_method_multiple_args(self):
     server = JsonRpcServer(echo_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     result = client.call_method('echo', 'foo', 'bar')
     self.assertEqual(result, ['foo', 'bar'])
     server.close()
     client.close()
コード例 #6
0
ファイル: test_jsonrpc.py プロジェクト: PlumpMath/gruvi
 def test_call_method_pipe(self):
     server = JsonRpcServer(echo_app)
     server.listen(self.pipename(abstract=True))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     result = client.call_method('echo', 'foo')
     self.assertEqual(result, ['foo'])
     server.close()
     client.close()
コード例 #7
0
ファイル: test_jsonrpc.py プロジェクト: PlumpMath/gruvi
 def test_call_method_tcp(self):
     server = JsonRpcServer(echo_app)
     server.listen(('localhost', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     result = client.call_method('echo', 'foo')
     self.assertEqual(result, ['foo'])
     server.close()
     client.close()
コード例 #8
0
ファイル: test_jsonrpc.py プロジェクト: PlumpMath/gruvi
 def test_call_method_ping_pong(self):
     server = JsonRpcServer(reflect_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient(echo_app)
     client.connect(addr)
     result = client.call_method('echo', 'foo')
     self.assertEqual(result, ['foo'])
     server.close()
     client.close()
コード例 #9
0
ファイル: test_jsonrpc.py プロジェクト: PlumpMath/gruvi
 def test_call_method_ssl(self):
     server = JsonRpcServer(echo_app)
     context = self.get_ssl_context()
     server.listen(('localhost', 0), ssl=context)
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr, ssl=context)
     result = client.call_method('echo', 'foo')
     self.assertEqual(result, ['foo'])
     server.close()
     client.close()
コード例 #10
0
ファイル: test_jsonrpc.py プロジェクト: Ed-von-Schleck/gruvi
 def test_call_method_tcp(self):
     server = JsonRpcServer(echo_app)
     server.listen(('localhost', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     result = client.call_method('echo', 'foo')
     self.assertEqual(result, ['foo'])
     server.close()
     client.close()
コード例 #11
0
ファイル: test_jsonrpc.py プロジェクト: Ed-von-Schleck/gruvi
 def test_call_method_ping_pong(self):
     server = JsonRpcServer(reflect_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient(echo_app)
     client.connect(addr)
     result = client.call_method('echo', 'foo')
     self.assertEqual(result, ['foo'])
     server.close()
     client.close()
コード例 #12
0
ファイル: test_jsonrpc.py プロジェクト: Ed-von-Schleck/gruvi
 def test_call_method_multiple_args(self):
     server = JsonRpcServer(echo_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     result = client.call_method('echo', 'foo', 'bar')
     self.assertEqual(result, ['foo', 'bar'])
     server.close()
     client.close()
コード例 #13
0
ファイル: test_jsonrpc.py プロジェクト: Ed-von-Schleck/gruvi
 def test_call_method_pipe(self):
     server = JsonRpcServer(echo_app)
     server.listen(self.pipename(abstract=True))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     result = client.call_method('echo', 'foo')
     self.assertEqual(result, ['foo'])
     server.close()
     client.close()
コード例 #14
0
ファイル: test_jsonrpc.py プロジェクト: Ed-von-Schleck/gruvi
 def test_call_method_ssl(self):
     server = JsonRpcServer(echo_app)
     context = self.get_ssl_context()
     server.listen(('localhost', 0), ssl=context)
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr, ssl=context)
     result = client.call_method('echo', 'foo')
     self.assertEqual(result, ['foo'])
     server.close()
     client.close()
コード例 #15
0
ファイル: test_jsonrpc.py プロジェクト: PlumpMath/gruvi
 def test_call_method_error(self):
     server = JsonRpcServer(echo_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     exc = self.assertRaises(JsonRpcError, client.call_method, 'echo2')
     self.assertIsInstance(exc, JsonRpcError)
     self.assertIsInstance(exc.error, dict)
     self.assertEqual(exc.error['code'], jsonrpc.METHOD_NOT_FOUND)
     server.close()
     client.close()
コード例 #16
0
ファイル: test_jsonrpc.py プロジェクト: PlumpMath/gruvi
 def test_connection_limit(self):
     server = JsonRpcServer(echo_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     server.max_connections = 2
     clients = []
     exc = None
     try:
         for i in range(3):
             client = JsonRpcClient(timeout=2)
             client.connect(addr)
             client.call_method('echo')
             clients.append(client)
     except Exception as e:
         exc = e
     self.assertIsInstance(exc, TransportError)
     self.assertEqual(len(server.connections), server.max_connections)
     for client in clients:
         client.close()
     server.close()
コード例 #17
0
 def perf_message_throughput(self):
     server = JsonRpcServer(echo_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     nrequests = 0
     t0 = t1 = time.time()
     while t1 - t0 < 1:
         result = client.call_method('echo', 'foo')
         self.assertEqual(result, ['foo'])
         nrequests += 1
         t1 = time.time()
     throughput = nrequests / (t1 - t0)
     self.add_result(throughput)
     server.close()
     client.close()
コード例 #18
0
ファイル: test_jsonrpc.py プロジェクト: Ed-von-Schleck/gruvi
 def test_connection_limit(self):
     server = JsonRpcServer(echo_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     server.max_connections = 10
     clients = []
     exc = None
     try:
         for i in range(15):
             client = JsonRpcClient(timeout=2)
             client.connect(addr)
             client.call_method('echo')
             clients.append(client)
     except Exception as e:
         exc = e
     self.assertIsInstance(exc, TransportError)
     self.assertLessEqual(len(server.connections), server.max_connections)
     for client in clients:
         client.close()
     server.close()
コード例 #19
0
ファイル: test_jsonrpc.py プロジェクト: PlumpMath/gruvi
 def test_send_random(self):
     server = JsonRpcServer(echo_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     exc = None
     try:
         while True:
             chunk = os.urandom(1024)
             client.transport.write(chunk)
             gruvi.sleep(0)
     except Exception as e:
         exc = e
     self.assertIsInstance(exc, TransportError)
     server.close()
     client.close()
コード例 #20
0
ファイル: perf_jsonrpc.py プロジェクト: geertj/gruvi
 def perf_message_throughput(self):
     server = JsonRpcServer(echo_app)
     server.listen(('127.0.0.1', 0))
     addr = server.addresses[0]
     client = JsonRpcClient()
     client.connect(addr)
     nrequests = 0
     t0 = t1 = time.time()
     while t1 - t0 < 1:
         result = client.call_method('echo', 'foo')
         self.assertEqual(result, ['foo'])
         nrequests += 1
         t1 = time.time()
     throughput = nrequests / (t1 - t0)
     self.add_result(throughput)
     server.close()
     client.close()
コード例 #21
0
# Ping-pong between JSON-RPC client and server.

from gruvi.jsonrpc import JsonRpcClient, JsonRpcServer


def handler(message, transport, protocol):
    method = message.get('method')
    if method == 'ping':
        protocol.send_response(message, 'pong')


server = JsonRpcServer(handler)
server.listen(('localhost', 0))
addr = server.addresses[0]

client = JsonRpcClient()
client.connect(addr)
result = client.call_method('ping')

print('result = {}'.format(result))