def test_finalize_stream(self): channel = ChannelStub() 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 stream = {} client.finalize_stream(stream) assert len(channel.requests) == 1 expected_request = storage_pb2.FinalizeStreamRequest(stream=stream) actual_request = channel.requests[0][1] assert expected_request == actual_request
def finalize_stream( self, stream, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): """ Triggers the graceful termination of a single stream in a ReadSession. This API can be used to dynamically adjust the parallelism of a batch processing task downwards without losing data. This API does not delete the stream -- it remains visible in the ReadSession, and any data processed by the stream is not released to other streams. However, no additional data will be assigned to the stream once this call completes. Callers must continue reading data on the stream until the end of the stream is reached so that data which has already been assigned to the stream will be processed. This method will return an error if there are no other live streams in the Session, or if SplitReadStream() has been called on the given Stream. Example: >>> from google.cloud import bigquery_storage_v1beta1 >>> >>> client = bigquery_storage_v1beta1.BigQueryStorageClient() >>> >>> # TODO: Initialize `stream`: >>> stream = {} >>> >>> client.finalize_stream(stream) Args: stream (Union[dict, ~google.cloud.bigquery_storage_v1beta1.types.Stream]): Stream to finalize. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.bigquery_storage_v1beta1.types.Stream` 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. 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 "finalize_stream" not in self._inner_api_calls: self._inner_api_calls[ "finalize_stream" ] = google.api_core.gapic_v1.method.wrap_method( self.transport.finalize_stream, default_retry=self._method_configs["FinalizeStream"].retry, default_timeout=self._method_configs["FinalizeStream"].timeout, client_info=self._client_info, ) request = storage_pb2.FinalizeStreamRequest(stream=stream) if metadata is None: metadata = [] metadata = list(metadata) try: routing_header = [("stream.name", stream.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 self._inner_api_calls["finalize_stream"]( request, retry=retry, timeout=timeout, metadata=metadata )