Skip to content

Commit

Permalink
fix: Make sessionCount required for batchCreateSessions. (#2348)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored and dwsupplee committed Sep 30, 2019
1 parent 7bd19ce commit dfc7b37
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
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

0 comments on commit dfc7b37

Please sign in to comment.