Search in sources :

Example 6 with DatabaseName

use of com.google.firestore.admin.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()));
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) DatabaseName(com.google.spanner.v1.DatabaseName) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 7 with DatabaseName

use of com.google.firestore.admin.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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) DatabaseName(com.google.spanner.v1.DatabaseName) Test(org.junit.Test)

Example 8 with DatabaseName

use of com.google.firestore.admin.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()));
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListSessionsPagedResponse(com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse) DatabaseName(com.google.spanner.v1.DatabaseName) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 9 with DatabaseName

use of com.google.firestore.admin.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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) DatabaseName(com.google.firestore.admin.v1.DatabaseName) ExportDocumentsRequest(com.google.firestore.admin.v1.ExportDocumentsRequest) ExportDocumentsResponse(com.google.firestore.admin.v1.ExportDocumentsResponse) Operation(com.google.longrunning.Operation) Test(org.junit.Test)

Example 10 with DatabaseName

use of com.google.firestore.admin.v1.DatabaseName in project java-spanner by googleapis.

the class DatabaseAdminGaxTest method getDatabaseTest.

@Test
public void getDatabaseTest() {
    Exception exception = setupException();
    DatabaseName name2 = DatabaseName.of(PROJECT, INSTANCE, "DATABASE");
    com.google.spanner.admin.database.v1.Database expectedResponse = com.google.spanner.admin.database.v1.Database.newBuilder().setName(name2.toString()).build();
    if (exceptionAtCall == 0) {
        mockDatabaseAdmin.addException(exception);
    }
    mockDatabaseAdmin.addResponse(expectedResponse);
    if (exceptionAtCall == 1) {
        mockDatabaseAdmin.addException(exception);
    }
    mockDatabaseAdmin.addResponse(expectedResponse);
    for (int i = 0; i < 2; i++) {
        Database actualResponse = client.getDatabase(INSTANCE, "DATABASE");
        Assert.assertEquals(name2.toString(), actualResponse.getId().getName());
    }
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(2, actualRequests.size());
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) DatabaseName(com.google.spanner.admin.database.v1.DatabaseName) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 AbstractMessage (com.google.protobuf.AbstractMessage)10 DatabaseName (com.google.spanner.admin.database.v1.DatabaseName)10 StatusRuntimeException (io.grpc.StatusRuntimeException)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)9 DatabaseName (com.google.spanner.v1.DatabaseName)7 ArrayList (java.util.ArrayList)6 DatabaseName (com.google.firestore.admin.v1.DatabaseName)4 Empty (com.google.protobuf.Empty)4 ExecutionException (java.util.concurrent.ExecutionException)4 Operation (com.google.longrunning.Operation)3 Session (com.google.spanner.v1.Session)3 ByteString (com.google.protobuf.ByteString)2 Database (com.google.spanner.admin.database.v1.Database)2 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)2 ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)2 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)1 ServiceOptions (com.google.cloud.ServiceOptions)1 ObservableReactiveUtil (com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil)1 ListSessionsPagedResponse (com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse)1