use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.
the class SpannerClientTest method createSessionTest.
@Test
public void createSessionTest() throws Exception {
Session expectedResponse = Session.newBuilder().setName(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).setApproximateLastUseTime(Timestamp.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Session actualResponse = client.createSession(database);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateSessionRequest actualRequest = ((CreateSessionRequest) actualRequests.get(0));
Assert.assertEquals(database.toString(), actualRequest.getDatabase());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.
the class SpannerClientTest method listSessionsExceptionTest.
@Test
public void listSessionsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
client.listSessions(database);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.
the class SpannerClientTest method listSessionsTest.
@Test
public void listSessionsTest() throws Exception {
Session responsesElement = Session.newBuilder().build();
ListSessionsResponse expectedResponse = ListSessionsResponse.newBuilder().setNextPageToken("").addAllSessions(Arrays.asList(responsesElement)).build();
mockSpanner.addResponse(expectedResponse);
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
ListSessionsPagedResponse pagedListResponse = client.listSessions(database);
List<Session> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSessionsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSessionsRequest actualRequest = ((ListSessionsRequest) actualRequests.get(0));
Assert.assertEquals(database.toString(), actualRequest.getDatabase());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.
the class GapicSpannerRpc method batchCreateSessions.
@Override
public List<Session> batchCreateSessions(String databaseName, int sessionCount, @Nullable Map<String, String> labels, @Nullable Map<Option, ?> options) throws SpannerException {
BatchCreateSessionsRequest.Builder requestBuilder = BatchCreateSessionsRequest.newBuilder().setDatabase(databaseName).setSessionCount(sessionCount);
if (labels != null && !labels.isEmpty()) {
Session.Builder session = Session.newBuilder().putAllLabels(labels);
requestBuilder.setSessionTemplate(session);
}
BatchCreateSessionsRequest request = requestBuilder.build();
GrpcCallContext context = newCallContext(options, databaseName, request, SpannerGrpc.getBatchCreateSessionsMethod());
return get(spannerStub.batchCreateSessionsCallable().futureCall(request, context)).getSessionList();
}
use of com.google.spanner.v1.DatabaseName in project java-firestore by googleapis.
the class FirestoreAdminClientTest method exportDocumentsTest.
@Test
public void exportDocumentsTest() throws Exception {
ExportDocumentsResponse expectedResponse = ExportDocumentsResponse.newBuilder().setOutputUriPrefix("outputUriPrefix499858205").build();
Operation resultOperation = Operation.newBuilder().setName("exportDocumentsTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockFirestoreAdmin.addResponse(resultOperation);
DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
ExportDocumentsResponse actualResponse = client.exportDocumentsAsync(name).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ExportDocumentsRequest actualRequest = ((ExportDocumentsRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations