Exemplo n.º 1
0
 def test_persistent_header(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(TestService, path=path) as client:
             client.set_persistent_header(TEST_HEADER_KEY,
                                          TEST_HEADER_VALUE)
             self.assertEqual(TEST_HEADER_VALUE,
                              client.readHeader(TEST_HEADER_KEY))
Exemplo n.º 2
0
 def test_unexpected_exception(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(TestService, path=path) as client:
             with self.assertRaisesRegex(ApplicationError,
                                         "Surprise!") as ex:
                 client.surprise()
             self.assertEqual(ApplicationErrorType.UNKNOWN,
                              ex.exception.type)
Exemplo n.º 3
0
 def test_oneway_with_rocket(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(TestService,
                              path=path,
                              client_type=ClientType.
                              THRIFT_ROCKET_CLIENT_TYPE) as client:
             self.assertIsNone(client.oneway())
             time.sleep(1)  # wait for server to clear the queue
Exemplo n.º 4
0
 def test_client_type_and_protocol(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(
                 TestService,
                 path=path,
                 client_type=ClientType.THRIFT_ROCKET_CLIENT_TYPE,
                 protocol=Protocol.BINARY,
         ) as client:
             sum = client.add(1, 2)
             self.assertEqual(3, sum)
Exemplo n.º 5
0
 def test_reuse_client(self) -> None:
     with server_in_another_process() as path:
         client = get_sync_client(TestService, path=path)
         with client:
             self.assertEqual(3, client.add(1, 2))
         with self.assertRaises(RuntimeError):
             with client:
                 pass
         with self.assertRaises(RuntimeError):
             client.add(1, 2)
Exemplo n.º 6
0
    def test_exit_callback(self) -> None:
        class Callback:
            def __init__(self):
                self.triggered = False

            def trigger(self):
                self.triggered = True

        cb1 = Callback()
        cb2 = Callback()

        with server_in_another_process() as path:
            with get_sync_client(TestService, path=path) as client:
                client._at_exit(cb1.trigger)
                client._at_exit(cb2.trigger)

        self.assertTrue(cb1.triggered)
        self.assertTrue(cb2.triggered)
Exemplo n.º 7
0
 def test_derived_service(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(EchoService, path=path) as client:
             self.assertEqual("hello", client.echo("hello"))
             self.assertEqual(3, client.add(1, 2))
Exemplo n.º 8
0
 def test_oneway(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(TestService, path=path) as client:
             self.assertIsNone(client.oneway())
             time.sleep(1)  # wait for server to clear the queue
Exemplo n.º 9
0
 def test_void_return_with_exception(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(TestService, path=path) as client:
             with self.assertRaises(EmptyException):
                 client.oops()
Exemplo n.º 10
0
 def test_exception(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(TestService, path=path) as client:
             self.assertAlmostEqual(2, client.divide(6, 3))
             with self.assertRaises(ArithmeticException):
                 client.divide(1, 0)
Exemplo n.º 11
0
 def test_void_return(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(TestService, path=path) as client:
             self.assertIsNone(client.noop())
Exemplo n.º 12
0
 def test_basic(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(TestService, path=path) as client:
             self.assertEqual(3, client.add(1, 2))
Exemplo n.º 13
0
 def test_add_test_handler_should_hijack_transport_error(self) -> None:
     with HijackTestHelper():
         with get_sync_client(TestService, path="/no/where") as client:
             with self.assertRaises(HijackTestException):
                 client.add(1, 2)
Exemplo n.º 14
0
 def test_transport_error(self) -> None:
     with get_sync_client(TestService, path="/no/where") as client:
         with self.assertRaises(TransportError) as ex:
             client.add(1, 2)
         self.assertEqual(TransportErrorType.UNKNOWN, ex.exception.type)
Exemplo n.º 15
0
 def test_deriving_from_external_service(self) -> None:
     with server_in_another_process() as path:
         with get_sync_client(LeafService, path=path) as client:
             self.assertEqual([3, 2, 1], list(client.reverse([1, 2, 3])))
             self.assertEqual("hello", client.echo("hello"))
             self.assertEqual(3, client.add(1, 2))