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

fix: Make sessionCount required for batchCreateSessions. #2348

Merged
merged 1 commit into from
Sep 30, 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
22 changes: 10 additions & 12 deletions Spanner/src/V1/Gapic/SpannerGapicClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,25 +407,25 @@ public function createSession($database, array $optionalArgs = [])
* $spannerClient = new SpannerClient();
* try {
* $formattedDatabase = $spannerClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
* $response = $spannerClient->batchCreateSessions($formattedDatabase);
* $sessionCount = 0;
* $response = $spannerClient->batchCreateSessions($formattedDatabase, $sessionCount);
* } finally {
* $spannerClient->close();
* }
* ```
*
* @param string $database Required. The database in which the new sessions are created.
* @param int $sessionCount 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][google.spanner.v1.BatchCreateSessionsRequest.session_count]
* as necessary).
* @param array $optionalArgs {
* Optional.
*
* @type Session $sessionTemplate
* Parameters to be applied to each created session.
* @type int $sessionCount
* 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][google.spanner.v1.BatchCreateSessionsRequest.session_count]
* as necessary).
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a
* {@see Google\ApiCore\RetrySettings} object, or an associative array
Expand All @@ -438,16 +438,14 @@ public function createSession($database, array $optionalArgs = [])
* @throws ApiException if the remote call fails
* @experimental
*/
public function batchCreateSessions($database, array $optionalArgs = [])
public function batchCreateSessions($database, $sessionCount, array $optionalArgs = [])
{
$request = new BatchCreateSessionsRequest();
$request->setDatabase($database);
$request->setSessionCount($sessionCount);
if (isset($optionalArgs['sessionTemplate'])) {
$request->setSessionTemplate($optionalArgs['sessionTemplate']);
}
if (isset($optionalArgs['sessionCount'])) {
$request->setSessionCount($optionalArgs['sessionCount']);
}

$requestParams = new RequestParamsHeaderDescriptor([
'database' => $request->getDatabase(),
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-23T10:03:07.098058Z",
"updateTime": "2019-09-24T10:02:50.339542Z",
"sources": [
{
"generator": {
"name": "artman",
"version": "0.29.1",
"dockerImage": "googleapis/artman@sha256:b2a73f4dda03ef8fcaa973e3ba26d0cf34091f6c22c70add663af325931aef4d"
"version": "0.37.0",
"dockerImage": "googleapis/artman@sha256:0f66008f69061ea6d41499e2a34da3fc64fc7c9798077e3a37158653a135d801"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "9c9f778aedde02f9826d2ae5d0f9c96409ba0f25",
"internalRef": "264996596"
"sha": "cc332bd19c2dd9640b025e5693e83a1b428d5dff",
"internalRef": "270834186"
}
}
],
Expand Down
9 changes: 7 additions & 2 deletions Spanner/tests/Unit/V1/SpannerClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ public function batchCreateSessionsTest()

// Mock request
$formattedDatabase = $client->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
$sessionCount = 185691686;

$response = $client->batchCreateSessions($formattedDatabase);
$response = $client->batchCreateSessions($formattedDatabase, $sessionCount);
$this->assertEquals($expectedResponse, $response);
$actualRequests = $transport->popReceivedCalls();
$this->assertSame(1, count($actualRequests));
Expand All @@ -182,6 +183,9 @@ public function batchCreateSessionsTest()
$actualValue = $actualRequestObject->getDatabase();

$this->assertProtobufEquals($formattedDatabase, $actualValue);
$actualValue = $actualRequestObject->getSessionCount();

$this->assertProtobufEquals($sessionCount, $actualValue);

$this->assertTrue($transport->isExhausted());
}
Expand Down Expand Up @@ -210,9 +214,10 @@ public function batchCreateSessionsExceptionTest()

// Mock request
$formattedDatabase = $client->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
$sessionCount = 185691686;

try {
$client->batchCreateSessions($formattedDatabase);
$client->batchCreateSessions($formattedDatabase, $sessionCount);
// If the $client method call did not throw, fail the test
$this->fail('Expected an ApiException, but no exception was thrown.');
} catch (ApiException $ex) {
Expand Down