Search in sources :

Example 6 with SessionName

use of com.google.spanner.v1.SessionName in project java-spanner by googleapis.

the class SpannerClientTest method getSessionExceptionTest.

@Test
public void getSessionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSpanner.addException(exception);
    try {
        SessionName name = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
        client.getSession(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 7 with SessionName

use of com.google.spanner.v1.SessionName in project java-spanner by googleapis.

the class SpannerClientTest method deleteSessionTest.

@Test
public void deleteSessionTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockSpanner.addResponse(expectedResponse);
    SessionName name = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
    client.deleteSession(name);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteSessionRequest actualRequest = ((DeleteSessionRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 8 with SessionName

use of com.google.spanner.v1.SessionName in project java-spanner by googleapis.

the class SpannerClientTest method beginTransactionTest.

@Test
public void beginTransactionTest() throws Exception {
    Transaction expectedResponse = Transaction.newBuilder().setId(ByteString.EMPTY).setReadTimestamp(Timestamp.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
    TransactionOptions options = TransactionOptions.newBuilder().build();
    Transaction actualResponse = client.beginTransaction(session, options);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    BeginTransactionRequest actualRequest = ((BeginTransactionRequest) actualRequests.get(0));
    Assert.assertEquals(session.toString(), actualRequest.getSession());
    Assert.assertEquals(options, actualRequest.getOptions());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Transaction(com.google.spanner.v1.Transaction) TransactionOptions(com.google.spanner.v1.TransactionOptions) BeginTransactionRequest(com.google.spanner.v1.BeginTransactionRequest) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 9 with SessionName

use of com.google.spanner.v1.SessionName in project java-spanner by googleapis.

the class SpannerClientTest method rollbackTest.

@Test
public void rollbackTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockSpanner.addResponse(expectedResponse);
    SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
    ByteString transactionId = ByteString.EMPTY;
    client.rollback(session, transactionId);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    RollbackRequest actualRequest = ((RollbackRequest) actualRequests.get(0));
    Assert.assertEquals(session.toString(), actualRequest.getSession());
    Assert.assertEquals(transactionId, actualRequest.getTransactionId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) RollbackRequest(com.google.spanner.v1.RollbackRequest) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 10 with SessionName

use of com.google.spanner.v1.SessionName in project java-spanner by googleapis.

the class SpannerClientTest method commitTest2.

@Test
public void commitTest2() throws Exception {
    CommitResponse expectedResponse = CommitResponse.newBuilder().setCommitTimestamp(Timestamp.newBuilder().build()).setCommitStats(CommitResponse.CommitStats.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
    TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build();
    List<Mutation> mutations = new ArrayList<>();
    CommitResponse actualResponse = client.commit(session, singleUseTransaction, mutations);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0));
    Assert.assertEquals(session.toString(), actualRequest.getSession());
    Assert.assertEquals(singleUseTransaction, actualRequest.getSingleUseTransaction());
    Assert.assertEquals(mutations, actualRequest.getMutationsList());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) AbstractMessage(com.google.protobuf.AbstractMessage) TransactionOptions(com.google.spanner.v1.TransactionOptions) ArrayList(java.util.ArrayList) CommitResponse(com.google.spanner.v1.CommitResponse) Mutation(com.google.spanner.v1.Mutation) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 ByteString (com.google.protobuf.ByteString)13 SessionName (com.google.spanner.v1.SessionName)12 ArrayList (java.util.ArrayList)10 CommitRequest (com.google.spanner.v1.CommitRequest)9 CommitResponse (com.google.spanner.v1.CommitResponse)9 RollbackRequest (com.google.spanner.v1.RollbackRequest)9 Empty (com.google.protobuf.Empty)8 Before (org.junit.Before)8 ApiFutures (com.google.api.core.ApiFutures)6 Timestamp (com.google.cloud.Timestamp)6 NUM_IN_USE_SESSIONS (com.google.cloud.spanner.MetricRegistryConstants.NUM_IN_USE_SESSIONS)6 NUM_READ_SESSIONS (com.google.cloud.spanner.MetricRegistryConstants.NUM_READ_SESSIONS)6 NUM_SESSIONS_BEING_PREPARED (com.google.cloud.spanner.MetricRegistryConstants.NUM_SESSIONS_BEING_PREPARED)6 NUM_WRITE_SESSIONS (com.google.cloud.spanner.MetricRegistryConstants.NUM_WRITE_SESSIONS)6 SPANNER_LABEL_KEYS (com.google.cloud.spanner.MetricRegistryConstants.SPANNER_LABEL_KEYS)6 SPANNER_LABEL_KEYS_WITH_TYPE (com.google.cloud.spanner.MetricRegistryConstants.SPANNER_LABEL_KEYS_WITH_TYPE)6 FakeMetricRegistry (com.google.cloud.spanner.MetricRegistryTestUtils.FakeMetricRegistry)6 MetricsRecord (com.google.cloud.spanner.MetricRegistryTestUtils.MetricsRecord)6 PointWithFunction (com.google.cloud.spanner.MetricRegistryTestUtils.PointWithFunction)6