Exemplo n.º 1
0
 async def testException(self):
     with self.assertRaises(aiogrpc.RpcError):
         await self.stub.ExceptionMethod(StandardRequest(name='test1'))
     fut = self.stub.ExceptionMethod.future(StandardRequest(name='test1'))
     self.assertEqual(await fut.code(),
                      aiogrpc.StatusCode.PERMISSION_DENIED)
     self.assertEqual(fut.done(), True)
     self.assertIsInstance(fut.exception(), aiogrpc.RpcError)
     with self.assertRaises(aiogrpc.RpcError):
         await fut
Exemplo n.º 2
0
 async def testUnaryUnary(self):
     result = await self.stub.NormalMethod(StandardRequest(name='test1'))
     self.assertEqual(result.message, 'test1')
     result, call = await self.stub.NormalMethod.with_call(
         StandardRequest(name='test2'))
     self.assertEqual(result.message, 'test2')
     self.assertEqual(await call.code(), aiogrpc.StatusCode.OK)
     self.assertEqual(await call.details(), 'OK detail')
     self.assertEqual(call.is_active(), False)
     fut = self.stub.NormalMethod.future(StandardRequest(name='test3'))
     self.assertEqual(fut.is_active(), True)
     self.assertEqual(fut.done(), False)
     self.assertEqual(await fut.code(), aiogrpc.StatusCode.OK)
     self.assertEqual((await fut).message, 'test3')
     self.assertEqual(fut.is_active(), False)
     self.assertEqual(fut.done(), True)
Exemplo n.º 3
0
 async def testBalancing(self):
     s1 = create_server(['127.0.0.1:9902'])
     s2 = create_server(['127.0.0.1:9903'])
     self.channel = aiogrpc.insecure_channel(
         'ipv4:///127.0.0.1:9902,127.0.0.1:9903', loop=self.loop)
     self.stub = TestServiceStub(self.channel)
     s1.start()
     try:
         result = await self.stub.NormalMethod(StandardRequest(name='test1')
                                               )
         self.assertEqual(result.message, 'test1')
     finally:
         s1.stop(None)
     s2.start()
     try:
         result = await self.stub.NormalMethod(StandardRequest(name='test1')
                                               )
         self.assertEqual(result.message, 'test1')
     finally:
         s1.stop(None)
Exemplo n.º 4
0
    async def testStreamStream(self):
        async def test_input(q):
            while True:
                r = await q.get()
                if r is None:
                    break
                else:
                    yield r

        q = asyncio.Queue()
        result = self.stub.StreamStreamMethod(test_input(q))
        await q.put(StandardRequest(name='test1'))
        self.assertEqual((await result.__anext__()).message, 'test1')
        await q.put(StandardRequest(name='test2'))
        self.assertEqual((await result.__anext__()).message, 'test2')
        await q.put(StandardRequest(name='test3'))
        self.assertEqual((await result.__anext__()).message, 'test3')
        await q.put(None)
        with self.assertRaises(StopAsyncIteration):
            await result.__anext__()
        self.assertEqual(result.is_active(), False)
        self.assertEqual(await result.code(), aiogrpc.StatusCode.OK)
        q = asyncio.Queue()
        async with self.stub.StreamStreamMethod.with_scope(
                test_input(q)) as result:
            await q.put(StandardRequest(name='test1'))
            self.assertEqual((await result.__anext__()).message, 'test1')
            await q.put(StandardRequest(name='test2'))
            self.assertEqual((await result.__anext__()).message, 'test2')
            await q.put(StandardRequest(name='test3'))
            self.assertEqual((await result.__anext__()).message, 'test3')
        with self.assertRaises(StopAsyncIteration):
            await result.__anext__()
        self.assertEqual(await result.code(), aiogrpc.StatusCode.CANCELLED)
        self.assertEqual(result.is_active(), False)
        q = asyncio.Queue()
        result = self.stub.StreamStreamMethod(test_input(q))
        await q.put(None)
        with self.assertRaises(StopAsyncIteration):
            await result.__anext__()
Exemplo n.º 5
0
 async def testCancel(self):
     fut = self.stub.DelayedMethod.future(StandardRequest(name='test1'))
     self.assertEqual(fut.is_active(), True)
     fut.cancel()
     self.assertEqual(await fut.code(), aiogrpc.StatusCode.CANCELLED)
     self.assertEqual(fut.is_active(), False)
Exemplo n.º 6
0
 async def test_input2():
     yield StandardRequest(name='test1')
     yield StandardRequest(name='test2')
     raise ValueError('testerror')
Exemplo n.º 7
0
 async def test_input():
     yield StandardRequest(name='test1')
     yield StandardRequest(name='test2')
     yield StandardRequest(name='test3')
Exemplo n.º 8
0
 async def test_input2():
     yield StandardRequest(name='test1')
     yield StandardRequest(name='test2')
     raise ValueError(
         'Testing raising exception from client side (A designed test case)'
     )