Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,25 @@ public final UnaryCallable<CreateSessionRequest, Session> createSessionCallable(
* <pre><code>
* try (SpannerClient spannerClient = SpannerClient.create()) {
* DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
* BatchCreateSessionsResponse response = spannerClient.batchCreateSessions(database);
* int sessionCount = 0;
* BatchCreateSessionsResponse response = spannerClient.batchCreateSessions(database, sessionCount);
* }
* </code></pre>
*
* @param database Required. The database in which the new sessions are created.
* @param 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).
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final BatchCreateSessionsResponse batchCreateSessions(DatabaseName database) {
public final BatchCreateSessionsResponse batchCreateSessions(
DatabaseName database, int sessionCount) {

BatchCreateSessionsRequest request =
BatchCreateSessionsRequest.newBuilder()
.setDatabase(database == null ? null : database.toString())
.setSessionCount(sessionCount)
.build();
return batchCreateSessions(request);
}
Expand All @@ -370,17 +377,25 @@ public final BatchCreateSessionsResponse batchCreateSessions(DatabaseName databa
* <pre><code>
* try (SpannerClient spannerClient = SpannerClient.create()) {
* DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
* BatchCreateSessionsResponse response = spannerClient.batchCreateSessions(database.toString());
* int sessionCount = 0;
* BatchCreateSessionsResponse response = spannerClient.batchCreateSessions(database.toString(), sessionCount);
* }
* </code></pre>
*
* @param database Required. The database in which the new sessions are created.
* @param 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).
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final BatchCreateSessionsResponse batchCreateSessions(String database) {
public final BatchCreateSessionsResponse batchCreateSessions(String database, int sessionCount) {

BatchCreateSessionsRequest request =
BatchCreateSessionsRequest.newBuilder().setDatabase(database).build();
BatchCreateSessionsRequest.newBuilder()
.setDatabase(database)
.setSessionCount(sessionCount)
.build();
return batchCreateSessions(request);
}

Expand All @@ -396,8 +411,10 @@ public final BatchCreateSessionsResponse batchCreateSessions(String database) {
* <pre><code>
* try (SpannerClient spannerClient = SpannerClient.create()) {
* DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
* int sessionCount = 0;
* BatchCreateSessionsRequest request = BatchCreateSessionsRequest.newBuilder()
* .setDatabase(database.toString())
* .setSessionCount(sessionCount)
* .build();
* BatchCreateSessionsResponse response = spannerClient.batchCreateSessions(request);
* }
Expand All @@ -422,8 +439,10 @@ public final BatchCreateSessionsResponse batchCreateSessions(BatchCreateSessions
* <pre><code>
* try (SpannerClient spannerClient = SpannerClient.create()) {
* DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
* int sessionCount = 0;
* BatchCreateSessionsRequest request = BatchCreateSessionsRequest.newBuilder()
* .setDatabase(database.toString())
* .setSessionCount(sessionCount)
* .build();
* ApiFuture&lt;BatchCreateSessionsResponse&gt; future = spannerClient.batchCreateSessionsCallable().futureCall(request);
* // Do something
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ public void batchCreateSessionsTest() {
mockSpanner.addResponse(expectedResponse);

DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
int sessionCount = 185691686;

BatchCreateSessionsResponse actualResponse = client.batchCreateSessions(database);
BatchCreateSessionsResponse actualResponse = client.batchCreateSessions(database, sessionCount);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
BatchCreateSessionsRequest actualRequest = (BatchCreateSessionsRequest) actualRequests.get(0);

Assert.assertEquals(database, DatabaseName.parse(actualRequest.getDatabase()));
Assert.assertEquals(sessionCount, actualRequest.getSessionCount());
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
Expand All @@ -172,8 +174,9 @@ public void batchCreateSessionsExceptionTest() throws Exception {

try {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
int sessionCount = 185691686;

client.batchCreateSessions(database);
client.batchCreateSessions(database, sessionCount);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
Expand Down
10 changes: 5 additions & 5 deletions google-cloud-clients/google-cloud-spanner/synth.metadata
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"updateTime": "2019-08-23T07:57:47.645515Z",
"updateTime": "2019-09-24T07:54:52.495423Z",
"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": "cc332bd19c2dd9640b025e5693e83a1b428d5dff",
"internalRef": "270834186"
}
}
],
Expand Down