def test_successful_Buffer3Sum(self):
        rpc = self._real_time_server.invoke_stream_stream(
            target_service.methods_by_name['Buffer3Sum'], (), None)
        rpc.send_request(CalculationRequest(value=1))
        rpc.send_request(CalculationRequest(value=2))
        rpc.send_request(CalculationRequest(value=3))

        actual = rpc.take_response()
        expected = CalculationResponse(value=6)

        self.assertEqual(expected, actual)

        rpc.send_request(CalculationRequest(value=4))
        rpc.send_request(CalculationRequest(value=5))
        rpc.send_request(CalculationRequest(value=6))

        actual = rpc.take_response()
        expected = CalculationResponse(value=15)

        self.assertEqual(expected, actual)

        rpc.send_request(CalculationRequest(value=7))
        rpc.send_request(CalculationRequest(value=8))
        rpc.requests_closed()

        trailing_metadata, code, details = rpc.termination()
        actual = rpc.take_response()
        expected = CalculationResponse(value=15)

        self.assertEqual(expected, actual)
        self.assertIs(code, grpc.StatusCode.OK)
Пример #2
0
    def test_successful_natural_numbers_lq(self):
        arguments = 2

        def run(scenario, channel):
            connector = Connector(channel)
            return connector.natural_numbers_lq(scenario)

        application_future = self._client_execution_thread_pool.submit(
            run, arguments, self._fake_time_channel)
        invocation_metadata, actual_request, rpc = (
            self._fake_time_channel.take_unary_stream(
                target_service.methods_by_name['NaturalNumberGenerator']))

        expected_request = CalculationRequest(value=2)

        self.assertEqual(expected_request, actual_request)

        rpc.send_response(CalculationResponse(value=1))
        rpc.send_response(CalculationResponse(value=2))

        rpc.terminate((), grpc.StatusCode.OK, '')

        actual_result = application_future.result()
        expected_result = [1, 2]

        self.assertListEqual(expected_result, actual_result)
Пример #3
0
    def test_successful_buffer3_sum(self):
        arguments = [1, 2, 3, 4, 5, 6, 7, 8]

        def run(scenario, channel):
            connector = Connector(channel)
            return connector.buffer3_sum(scenario)

        application_future = self._client_execution_thread_pool.submit(
            run, arguments, self._fake_time_channel)
        invocation_metadata, rpc = self._fake_time_channel.take_stream_stream(
            target_service.methods_by_name['Buffer3Sum'])

        actual_request1 = rpc.take_request()
        actual_request2 = rpc.take_request()
        actual_request3 = rpc.take_request()
        actual_requests = [actual_request1, actual_request2, actual_request3]
        expected_requests = [
            CalculationRequest(value=1),
            CalculationRequest(value=2),
            CalculationRequest(value=3)
        ]

        self.assertListEqual(expected_requests, actual_requests)

        rpc.send_response(CalculationResponse(value=6))

        actual_request1 = rpc.take_request()
        actual_request2 = rpc.take_request()
        actual_request3 = rpc.take_request()
        actual_requests = [actual_request1, actual_request2, actual_request3]
        expected_requests = [
            CalculationRequest(value=4),
            CalculationRequest(value=5),
            CalculationRequest(value=6)
        ]

        self.assertListEqual(expected_requests, actual_requests)

        rpc.send_response(CalculationResponse(value=15))

        actual_request1 = rpc.take_request()
        actual_request2 = rpc.take_request()
        actual_requests = [actual_request1, actual_request2]
        expected_requests = [
            CalculationRequest(value=7),
            CalculationRequest(value=8)
        ]

        self.assertListEqual(expected_requests, actual_requests)

        rpc.requests_closed()
        rpc.send_response(CalculationResponse(value=15))
        rpc.terminate((), grpc.StatusCode.OK, '')

        actual_result = application_future.result()
        expected_result = [6, 15, 15]

        self.assertListEqual(expected_result, actual_result)
Пример #4
0
 def Buffer3Sum(self, request_iterator, context):
     buffer = []
     for req in request_iterator:
         buffer.append(req.value)
         if len(buffer) == 3:
             yield CalculationResponse(value=sum(buffer))
             buffer = []
     if len(buffer) > 0:
         yield CalculationResponse(value=sum(buffer))
Пример #5
0
    def test_successful_summation(self):
        arguments = [2, 3]

        def run(scenario, channel):
            connector = Connector(channel)
            return connector.summation(scenario)

        application_future = self._client_execution_thread_pool.submit(
            run, arguments, self._real_time_channel)
        invocation_metadata, rpc = self._real_time_channel.take_stream_unary(
            target_service.methods_by_name['Summation'])

        actual_request1 = rpc.take_request()
        actual_request2 = rpc.take_request()
        actual_requests = [actual_request1, actual_request2]
        expected_requests = [
            CalculationRequest(value=2),
            CalculationRequest(value=3)
        ]

        self.assertListEqual(expected_requests, actual_requests)

        rpc.requests_closed()
        rpc.terminate(CalculationResponse(value=5), (), grpc.StatusCode.OK, '')

        actual_result = application_future.result()
        expected_result = 5

        self.assertEqual(expected_result, actual_result)
    def test_successful_NaturalNumberGenerator(self):
        request = CalculationRequest(value=2)

        rpc = self._real_time_server.invoke_unary_stream(
            target_service.methods_by_name['NaturalNumberGenerator'], (),
            request, None)

        actual = [
            rpc.take_response(),
            rpc.take_response(),
        ]
        trailing_metadata, code, details = rpc.termination()
        expected = [CalculationResponse(value=1), CalculationResponse(value=2)]

        self.assertEqual(expected[0], actual[0])
        self.assertEqual(expected[1], actual[1])
        self.assertIs(code, grpc.StatusCode.OK)
    def test_successful_Square(self):
        request = CalculationRequest(value=2)

        rpc = self._real_time_server.invoke_unary_unary(
            target_service.methods_by_name['Square'], (), request, None)

        actual, trailing_metadata, code, details = rpc.termination()
        expected = CalculationResponse(value=4)

        self.assertEqual(expected, actual)
        self.assertIs(code, grpc.StatusCode.OK)
    def test_successful_Summation(self):
        rpc = self._real_time_server.invoke_stream_unary(
            target_service.methods_by_name['Summation'], (), None)
        rpc.send_request(CalculationRequest(value=2))
        rpc.send_request(CalculationRequest(value=3))
        rpc.requests_closed()

        actual, trailing_metadata, code, details = rpc.termination()
        expected = CalculationResponse(value=5)

        self.assertEqual(expected, actual)
        self.assertIs(code, grpc.StatusCode.OK)
Пример #9
0
    def test_successful_square(self):
        arguments = 2

        def run(scenario, channel):
            connector = Connector(channel)
            return connector.square(scenario)  # test target

        application_future = self._client_execution_thread_pool.submit(
            run, arguments, self._real_time_channel)
        invocation_metadata, actual_request, rpc = (
            self._real_time_channel.take_unary_unary(
                target_service.methods_by_name['Square']))

        expected_request = CalculationRequest(value=2)

        self.assertEqual(expected_request, actual_request)

        rpc.terminate(CalculationResponse(value=4), (), grpc.StatusCode.OK, '')

        actual_result = application_future.result()
        expected_result = 4

        self.assertEqual(expected_result, actual_result)
Пример #10
0
 def NaturalNumberGenerator(self, request, context):
     for i in range(request.value):
         yield CalculationResponse(value=i + 1)
Пример #11
0
 def Square(self, request, context):
     return CalculationResponse(value=request.value * request.value)
Пример #12
0
 def Summation(self, request_iterator, context):
     s = 0
     for req in request_iterator:
         s += req.value
     return CalculationResponse(value=s)