Search in sources :

Example 11 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 12 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)

Example 13 with SessionName

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

the class SpannerClientTest method commitTest.

@Test
public void commitTest() 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]");
    ByteString transactionId = ByteString.EMPTY;
    List<Mutation> mutations = new ArrayList<>();
    CommitResponse actualResponse = client.commit(session, transactionId, 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(transactionId, actualRequest.getTransactionId());
    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) ByteString(com.google.protobuf.ByteString) 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)

Example 14 with SessionName

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

the class SpannerClientTest method commitExceptionTest.

@Test
public void commitExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSpanner.addException(exception);
    try {
        SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
        ByteString transactionId = ByteString.EMPTY;
        List<Mutation> mutations = new ArrayList<>();
        client.commit(session, transactionId, mutations);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) Mutation(com.google.spanner.v1.Mutation) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 15 with SessionName

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

the class GapicSpannerRpc method asyncDeleteSession.

@Override
public ApiFuture<Empty> asyncDeleteSession(String sessionName, @Nullable Map<Option, ?> options) {
    DeleteSessionRequest request = DeleteSessionRequest.newBuilder().setName(sessionName).build();
    GrpcCallContext context = newCallContext(options, sessionName, request, SpannerGrpc.getDeleteSessionMethod());
    return spannerStub.deleteSessionCallable().futureCall(request, context);
}
Also used : DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext)

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