示例#1
0
 async def test_oneway(self) -> None:
     async with server_in_event_loop() as addr:
         async with get_client(TestService, host=addr.ip,
                               port=addr.port) as client:
             res = await client.oneway()
             self.assertIsNone(res)
             await asyncio.sleep(1)  # wait for server to clear the queue
示例#2
0
 async def test_hostname(self) -> None:
     async with server_in_event_loop() as addr:
         async with get_client(TestService,
                               host="localhost",
                               port=addr.port) as client:
             sum = await client.add(1, 2)
             self.assertEqual(3, sum)
 async def test_exception(self) -> None:
     async with server_in_event_loop() as addr:
         async with get_client(TestService, host=addr.ip,
                               port=addr.port) as client:
             res = await client.divide(6, 3)
             self.assertAlmostEqual(2, res)
             with self.assertRaises(ArithmeticException):
                 await client.divide(1, 0)
示例#4
0
 async def test_derived_service(self) -> None:
     async with server_in_event_loop() as addr:
         async with get_client(EchoService, host=addr.ip,
                               port=addr.port) as client:
             out = await client.echo("hello")
             self.assertEqual("hello", out)
             sum = await client.add(1, 2)
             self.assertEqual(3, sum)
示例#5
0
 async def test_persistent_header(self) -> None:
     async with server_in_event_loop() as addr:
         async with get_client(TestService,
                               host="localhost",
                               port=addr.port) as client:
             client.set_persistent_header(TEST_HEADER_KEY,
                                          TEST_HEADER_VALUE)
             value = await client.readHeader(TEST_HEADER_KEY)
             self.assertEqual(TEST_HEADER_VALUE, value)
示例#6
0
 async def test_unexpected_exception(self) -> None:
     async with server_in_event_loop() as addr:
         async with get_client(TestService, host=addr.ip,
                               port=addr.port) as client:
             with self.assertRaises(ApplicationError) as ex:
                 await client.surprise()
             self.assertEqual(ex.exception.message,
                              "ValueError('Surprise!')")
             self.assertEqual(ex.exception.type,
                              ApplicationErrorType.UNKNOWN)
示例#7
0
 async def test_deriving_from_external_service(self) -> None:
     async with server_in_event_loop() as addr:
         async with get_client(LeafService, host=addr.ip,
                               port=addr.port) as client:
             rev = await client.reverse([1, 2, 3])
             self.assertEqual([3, 2, 1], list(rev))
             out = await client.echo("hello")
             self.assertEqual("hello", out)
             sum = await client.add(1, 2)
             self.assertEqual(3, sum)
 async def test_client_type_and_protocol(self) -> None:
     async with server_in_event_loop() as addr:
         async with get_client(
                 TestService,
                 host=addr.ip,
                 port=addr.port,
                 client_type=ClientType.THRIFT_ROCKET_CLIENT_TYPE,
                 protocol=Protocol.BINARY,
         ) as client:
             sum = await client.add(1, 2)
             self.assertEqual(3, sum)
 async def test_oneway(self) -> None:
     async with server_in_event_loop() as addr:
         async with get_client(TestService, host=addr.ip,
                               port=addr.port) as client:
             res = await client.oneway()
             self.assertIsNone(res)
 async def test_void_return_with_exception(self) -> None:
     async with server_in_event_loop() as addr:
         async with get_client(TestService, host=addr.ip,
                               port=addr.port) as client:
             with self.assertRaises(EmptyException):
                 await client.oops()