Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spanner: Make 'session_count' optional for 'SpannerClient.batch_create_sessions' (via synth). #9280

Merged
merged 1 commit into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions spanner/google/cloud/spanner_v1/gapic/spanner_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ def create_session(
def batch_create_sessions(
self,
database,
session_count,
session_template=None,
session_count=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
Expand All @@ -329,18 +329,21 @@ def batch_create_sessions(
>>>
>>> database = client.database_path('[PROJECT]', '[INSTANCE]', '[DATABASE]')
>>>
>>> response = client.batch_create_sessions(database)
>>> # TODO: Initialize `session_count`:
>>> session_count = 0
>>>
>>> response = client.batch_create_sessions(database, session_count)

Args:
database (str): Required. The database in which the new sessions are created.
session_template (Union[dict, ~google.cloud.spanner_v1.types.Session]): Parameters to be applied to each created session.

If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.spanner_v1.types.Session`
session_count (int): Required. The number of sessions to be created in this batch call. The
API may return fewer than the requested number of sessions. If a
specific number of sessions are desired, the client can make additional
calls to BatchCreateSessions (adjusting ``session_count`` as necessary).
session_template (Union[dict, ~google.cloud.spanner_v1.types.Session]): Parameters to be applied to each created session.

If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.spanner_v1.types.Session`
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.
Expand Down Expand Up @@ -373,8 +376,8 @@ def batch_create_sessions(

request = spanner_pb2.BatchCreateSessionsRequest(
database=database,
session_template=session_template,
session_count=session_count,
session_template=session_template,
)
if metadata is None:
metadata = []
Expand Down
10 changes: 5 additions & 5 deletions spanner/synth.metadata
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"updateTime": "2019-08-23T12:37:16.324493Z",
"updateTime": "2019-09-24T12:30:40.124680Z",
"sources": [
{
"generator": {
"name": "artman",
"version": "0.34.0",
"dockerImage": "googleapis/artman@sha256:38a27ba6245f96c3e86df7acb2ebcc33b4f186d9e475efe2d64303aec3d4e0ea"
"version": "0.37.0",
"dockerImage": "googleapis/artman@sha256:0f66008f69061ea6d41499e2a34da3fc64fc7c9798077e3a37158653a135d801"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "9c9f778aedde02f9826d2ae5d0f9c96409ba0f25",
"internalRef": "264996596"
"sha": "fe6115fdfae318277426ec0e11b4b05e2b150723",
"internalRef": "270882829"
}
},
{
Expand Down
10 changes: 7 additions & 3 deletions spanner/tests/unit/gapic/v1/test_spanner_client_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@ def test_batch_create_sessions(self):

# Setup Request
database = client.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
session_count = 185691686

response = client.batch_create_sessions(database)
response = client.batch_create_sessions(database, session_count)
assert expected_response == response

assert len(channel.requests) == 1
expected_request = spanner_pb2.BatchCreateSessionsRequest(database=database)
expected_request = spanner_pb2.BatchCreateSessionsRequest(
database=database, session_count=session_count
)
actual_request = channel.requests[0][1]
assert expected_request == actual_request

Expand All @@ -138,9 +141,10 @@ def test_batch_create_sessions_exception(self):

# Setup request
database = client.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
session_count = 185691686

with pytest.raises(CustomException):
client.batch_create_sessions(database)
client.batch_create_sessions(database, session_count)

def test_get_session(self):
# Setup Expected Response
Expand Down