def test_batch_create_read_session_streams(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = storage_pb2.BatchCreateReadSessionStreamsResponse(
            **expected_response
        )

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = big_query_storage_client.BigQueryStorageClient()

        # Setup Request
        session = {}
        requested_streams = 1017221410

        response = client.batch_create_read_session_streams(session, requested_streams)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = storage_pb2.BatchCreateReadSessionStreamsRequest(
            session=session, requested_streams=requested_streams
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Beispiel #2
0
    def batch_create_read_session_streams(
        self,
        session,
        requested_streams,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Creates additional streams for a ReadSession. This API can be used to
        dynamically adjust the parallelism of a batch processing task upwards by
        adding additional workers.

        Example:
            >>> from google.cloud import bigquery_storage_v1beta1
            >>>
            >>> client = bigquery_storage_v1beta1.BigQueryStorageClient()
            >>>
            >>> # TODO: Initialize `session`:
            >>> session = {}
            >>>
            >>> # TODO: Initialize `requested_streams`:
            >>> requested_streams = 0
            >>>
            >>> response = client.batch_create_read_session_streams(session, requested_streams)

        Args:
            session (Union[dict, ~google.cloud.bigquery_storage_v1beta1.types.ReadSession]): Required. Must be a non-expired session obtained from a call to
                CreateReadSession. Only the name field needs to be set.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.bigquery_storage_v1beta1.types.ReadSession`
            requested_streams (int): Required. Number of new streams requested. Must be positive.
                Number of added streams may be less than this, see CreateReadSessionRequest
                for more information.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will
                be retried using a default configuration.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.bigquery_storage_v1beta1.types.BatchCreateReadSessionStreamsResponse` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if "batch_create_read_session_streams" not in self._inner_api_calls:
            self._inner_api_calls[
                "batch_create_read_session_streams"
            ] = google.api_core.gapic_v1.method.wrap_method(
                self.transport.batch_create_read_session_streams,
                default_retry=self._method_configs[
                    "BatchCreateReadSessionStreams"
                ].retry,
                default_timeout=self._method_configs[
                    "BatchCreateReadSessionStreams"
                ].timeout,
                client_info=self._client_info,
            )

        request = storage_pb2.BatchCreateReadSessionStreamsRequest(
            session=session, requested_streams=requested_streams
        )
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("session.name", session.name)]
        except AttributeError:
            pass
        else:
            routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
                routing_header
            )
            metadata.append(routing_metadata)  # pragma: no cover

        return self._inner_api_calls["batch_create_read_session_streams"](
            request, retry=retry, timeout=timeout, metadata=metadata
        )