def test_fake_server(self): """Fake server test.""" channel = grpc.insecure_channel(BigqueryOpsTest.server.endpoint()) stub = storage_pb2_grpc.BigQueryStorageStub(channel) create_read_session_request = storage_pb2.CreateReadSessionRequest() create_read_session_request.table_reference.project_id = self.GCP_PROJECT_ID create_read_session_request.table_reference.dataset_id = self.DATASET_ID create_read_session_request.table_reference.table_id = self.TABLE_ID create_read_session_request.requested_streams = 2 read_session_response = stub.CreateReadSession(create_read_session_request) self.assertEqual(2, len(read_session_response.streams)) read_rows_request = storage_pb2.ReadRowsRequest() read_rows_request.read_position.stream.name = read_session_response.streams[ 0].name read_rows_response = stub.ReadRows(read_rows_request) row = read_rows_response.next() self.assertEqual( self._serialize_to_avro(self.STREAM_1_ROWS, self.AVRO_SCHEMA), row.avro_rows.serialized_binary_rows) self.assertEqual(len(self.STREAM_1_ROWS), row.avro_rows.row_count) read_rows_request = storage_pb2.ReadRowsRequest() read_rows_request.read_position.stream.name = read_session_response.streams[ 1].name read_rows_response = stub.ReadRows(read_rows_request) row = read_rows_response.next() self.assertEqual( self._serialize_to_avro(self.STREAM_2_ROWS, self.AVRO_SCHEMA), row.avro_rows.serialized_binary_rows) self.assertEqual(len(self.STREAM_2_ROWS), row.avro_rows.row_count)
def __init__( self, channel=None, credentials=None, address="bigquerystorage.googleapis.com:443", ): """Instantiate the transport class. Args: channel (grpc.Channel): A ``Channel`` instance through which to make calls. This argument is mutually exclusive with ``credentials``; providing both will raise an exception. credentials (google.auth.credentials.Credentials): The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. address (str): The address where the service is hosted. """ # If both `channel` and `credentials` are specified, raise an # exception (channels come with credentials baked in already). if channel is not None and credentials is not None: # pragma: no cover raise ValueError( "The `channel` and `credentials` arguments are mutually " "exclusive.") # Create the channel. if channel is None: # pragma: no cover channel = self.create_channel( address=address, credentials=credentials, options={ "grpc.max_send_message_length": -1, "grpc.max_receive_message_length": -1, }.items(), ) self._channel = channel # gRPC uses objects called "stubs" that are bound to the # channel and provide a basic method for each RPC. self._stubs = { "big_query_storage_stub": storage_pb2_grpc.BigQueryStorageStub(channel) }