def _do_rpcs(self):
        server_call_condition = threading.Condition()
        server_call_completion_queue = cygrpc.CompletionQueue()
        server_call_driver = _common.QueueDriver(server_call_condition,
                                                 server_call_completion_queue)

        server_request_call_tag = 'server_request_call_tag'
        server_send_initial_metadata_tag = 'server_send_initial_metadata_tag'
        server_complete_rpc_tag = 'server_complete_rpc_tag'

        with self.server_condition:
            server_request_call_start_batch_result = self.server.request_call(
                server_call_completion_queue, self.server_completion_queue,
                server_request_call_tag)
            self.server_driver.add_due({
                server_request_call_tag,
            })

        client_call = self.channel.create_call(
            None, _common.EMPTY_FLAGS, self.client_completion_queue,
            b'/twinkies', None, _common.INFINITE_FUTURE)
        client_receive_initial_metadata_tag = 'client_receive_initial_metadata_tag'
        client_complete_rpc_tag = 'client_complete_rpc_tag'
        with self.client_condition:
            client_receive_initial_metadata_start_batch_result = (
                client_call.start_client_batch([
                    cygrpc.operation_receive_initial_metadata(
                        _common.EMPTY_FLAGS),
                ], client_receive_initial_metadata_tag))
            client_complete_rpc_start_batch_result = client_call.start_client_batch(
                [
                    cygrpc.operation_send_initial_metadata(
                        _common.INVOCATION_METADATA, _common.EMPTY_FLAGS),
                    cygrpc.operation_send_close_from_client(
                        _common.EMPTY_FLAGS),
                    cygrpc.operation_receive_status_on_client(
                        _common.EMPTY_FLAGS),
                ], client_complete_rpc_tag)
            self.client_driver.add_due({
                client_receive_initial_metadata_tag,
                client_complete_rpc_tag,
            })

        server_request_call_event = self.server_driver.event_with_tag(
            server_request_call_tag)

        with server_call_condition:
            server_send_initial_metadata_start_batch_result = (
                server_request_call_event.operation_call.start_server_batch([
                    cygrpc.operation_send_initial_metadata(
                        _common.INITIAL_METADATA, _common.EMPTY_FLAGS),
                ], server_send_initial_metadata_tag))
            server_call_driver.add_due({
                server_send_initial_metadata_tag,
            })
        server_send_initial_metadata_event = server_call_driver.event_with_tag(
            server_send_initial_metadata_tag)

        with server_call_condition:
            server_complete_rpc_start_batch_result = (
                server_request_call_event.operation_call.start_server_batch([
                    cygrpc.operation_receive_close_on_server(
                        _common.EMPTY_FLAGS),
                    cygrpc.operation_send_status_from_server(
                        _common.TRAILING_METADATA, cygrpc.StatusCode.ok,
                        b'test details', _common.EMPTY_FLAGS),
                ], server_complete_rpc_tag))
            server_call_driver.add_due({
                server_complete_rpc_tag,
            })
        server_complete_rpc_event = server_call_driver.event_with_tag(
            server_complete_rpc_tag)

        client_receive_initial_metadata_event = self.client_driver.event_with_tag(
            client_receive_initial_metadata_tag)
        client_complete_rpc_event = self.client_driver.event_with_tag(
            client_complete_rpc_tag)

        return (_common.OperationResult(server_request_call_start_batch_result,
                                        server_request_call_event.type,
                                        server_request_call_event.success),
                _common.OperationResult(
                    client_receive_initial_metadata_start_batch_result,
                    client_receive_initial_metadata_event.type,
                    client_receive_initial_metadata_event.success),
                _common.OperationResult(client_complete_rpc_start_batch_result,
                                        client_complete_rpc_event.type,
                                        client_complete_rpc_event.success),
                _common.OperationResult(
                    server_send_initial_metadata_start_batch_result,
                    server_send_initial_metadata_event.type,
                    server_send_initial_metadata_event.success),
                _common.OperationResult(server_complete_rpc_start_batch_result,
                                        server_complete_rpc_event.type,
                                        server_complete_rpc_event.success),)
    def _do_rpcs(self):
        server_request_call_tag = 'server_request_call_tag'
        server_send_initial_metadata_tag = 'server_send_initial_metadata_tag'
        server_complete_rpc_tag = 'server_complete_rpc_tag'

        with self.server_condition:
            server_request_call_start_batch_result = self.server.request_call(
                self.server_completion_queue, self.server_completion_queue,
                server_request_call_tag)
            self.server_driver.add_due({
                server_request_call_tag,
            })

        client_call = self.channel.create_call(
            None, _common.EMPTY_FLAGS, self.client_completion_queue,
            b'/twinkies', None, _common.INFINITE_FUTURE)
        client_receive_initial_metadata_tag = 'client_receive_initial_metadata_tag'
        client_complete_rpc_tag = 'client_complete_rpc_tag'
        with self.client_condition:
            client_receive_initial_metadata_start_batch_result = (
                client_call.start_client_batch([
                    cygrpc.ReceiveInitialMetadataOperation(_common.EMPTY_FLAGS),
                ], client_receive_initial_metadata_tag))
            client_complete_rpc_start_batch_result = client_call.start_client_batch(
                [
                    cygrpc.SendInitialMetadataOperation(
                        _common.INVOCATION_METADATA, _common.EMPTY_FLAGS),
                    cygrpc.SendCloseFromClientOperation(_common.EMPTY_FLAGS),
                    cygrpc.ReceiveStatusOnClientOperation(_common.EMPTY_FLAGS),
                ], client_complete_rpc_tag)
            self.client_driver.add_due({
                client_receive_initial_metadata_tag,
                client_complete_rpc_tag,
            })

        server_request_call_event = self.server_driver.event_with_tag(
            server_request_call_tag)

        with self.server_condition:
            server_send_initial_metadata_start_batch_result = (
                server_request_call_event.operation_call.start_server_batch([
                    cygrpc.SendInitialMetadataOperation(
                        _common.INITIAL_METADATA, _common.EMPTY_FLAGS),
                ], server_send_initial_metadata_tag))
            self.server_driver.add_due({
                server_send_initial_metadata_tag,
            })
        server_send_initial_metadata_event = self.server_driver.event_with_tag(
            server_send_initial_metadata_tag)

        with self.server_condition:
            server_complete_rpc_start_batch_result = (
                server_request_call_event.operation_call.start_server_batch([
                    cygrpc.ReceiveCloseOnServerOperation(_common.EMPTY_FLAGS),
                    cygrpc.SendStatusFromServerOperation(
                        _common.TRAILING_METADATA, cygrpc.StatusCode.ok,
                        'test details', _common.EMPTY_FLAGS),
                ], server_complete_rpc_tag))
            self.server_driver.add_due({
                server_complete_rpc_tag,
            })
        server_complete_rpc_event = self.server_driver.event_with_tag(
            server_complete_rpc_tag)

        client_receive_initial_metadata_event = self.client_driver.event_with_tag(
            client_receive_initial_metadata_tag)
        client_complete_rpc_event = self.client_driver.event_with_tag(
            client_complete_rpc_tag)

        return (_common.OperationResult(server_request_call_start_batch_result,
                                        server_request_call_event.type,
                                        server_request_call_event.success),
                _common.OperationResult(
                    client_receive_initial_metadata_start_batch_result,
                    client_receive_initial_metadata_event.type,
                    client_receive_initial_metadata_event.success),
                _common.OperationResult(client_complete_rpc_start_batch_result,
                                        client_complete_rpc_event.type,
                                        client_complete_rpc_event.success),
                _common.OperationResult(
                    server_send_initial_metadata_start_batch_result,
                    server_send_initial_metadata_event.type,
                    server_send_initial_metadata_event.success),
                _common.OperationResult(server_complete_rpc_start_batch_result,
                                        server_complete_rpc_event.type,
                                        server_complete_rpc_event.success),)
示例#3
0
    def _do_rpcs(self):
        server_call_condition = threading.Condition()
        server_call_completion_queue = cygrpc.CompletionQueue()
        server_call_driver = _common.QueueDriver(server_call_condition,
                                                 server_call_completion_queue)

        server_request_call_tag = 'server_request_call_tag'
        server_send_initial_metadata_tag = 'server_send_initial_metadata_tag'
        server_complete_rpc_tag = 'server_complete_rpc_tag'

        with self.server_condition:
            server_request_call_start_batch_result = self.server.request_call(
                server_call_completion_queue, self.server_completion_queue,
                server_request_call_tag)
            self.server_driver.add_due({
                server_request_call_tag,
            })

        client_receive_initial_metadata_tag = 'client_receive_initial_metadata_tag'
        client_complete_rpc_tag = 'client_complete_rpc_tag'
        client_call = self.channel.integrated_call(
            _common.EMPTY_FLAGS, b'/twinkies', None, None,
            _common.INVOCATION_METADATA, None, [(
                [
                    cygrpc.ReceiveInitialMetadataOperation(_common.EMPTY_FLAGS),
                ],
                client_receive_initial_metadata_tag,
            )])
        client_call.operate([
            cygrpc.SendInitialMetadataOperation(_common.INVOCATION_METADATA,
                                                _common.EMPTY_FLAGS),
            cygrpc.SendCloseFromClientOperation(_common.EMPTY_FLAGS),
            cygrpc.ReceiveStatusOnClientOperation(_common.EMPTY_FLAGS),
        ], client_complete_rpc_tag)

        client_events_future = test_utilities.SimpleFuture(lambda: [
            self.channel.next_call_event(),
            self.channel.next_call_event(),
        ])

        server_request_call_event = self.server_driver.event_with_tag(
            server_request_call_tag)

        with server_call_condition:
            server_send_initial_metadata_start_batch_result = (
                server_request_call_event.call.start_server_batch([
                    cygrpc.SendInitialMetadataOperation(
                        _common.INITIAL_METADATA, _common.EMPTY_FLAGS),
                ], server_send_initial_metadata_tag))
            server_call_driver.add_due({
                server_send_initial_metadata_tag,
            })
        server_send_initial_metadata_event = server_call_driver.event_with_tag(
            server_send_initial_metadata_tag)

        with server_call_condition:
            server_complete_rpc_start_batch_result = (
                server_request_call_event.call.start_server_batch([
                    cygrpc.ReceiveCloseOnServerOperation(_common.EMPTY_FLAGS),
                    cygrpc.SendStatusFromServerOperation(
                        _common.TRAILING_METADATA, cygrpc.StatusCode.ok,
                        b'test details', _common.EMPTY_FLAGS),
                ], server_complete_rpc_tag))
            server_call_driver.add_due({
                server_complete_rpc_tag,
            })
        server_complete_rpc_event = server_call_driver.event_with_tag(
            server_complete_rpc_tag)

        client_events = client_events_future.result()
        if client_events[0].tag is client_receive_initial_metadata_tag:
            client_receive_initial_metadata_event = client_events[0]
            client_complete_rpc_event = client_events[1]
        else:
            client_complete_rpc_event = client_events[0]
            client_receive_initial_metadata_event = client_events[1]

        return (
            _common.OperationResult(server_request_call_start_batch_result,
                                    server_request_call_event.completion_type,
                                    server_request_call_event.success),
            _common.OperationResult(
                cygrpc.CallError.ok,
                client_receive_initial_metadata_event.completion_type,
                client_receive_initial_metadata_event.success),
            _common.OperationResult(cygrpc.CallError.ok,
                                    client_complete_rpc_event.completion_type,
                                    client_complete_rpc_event.success),
            _common.OperationResult(
                server_send_initial_metadata_start_batch_result,
                server_send_initial_metadata_event.completion_type,
                server_send_initial_metadata_event.success),
            _common.OperationResult(server_complete_rpc_start_batch_result,
                                    server_complete_rpc_event.completion_type,
                                    server_complete_rpc_event.success),
        )