Search in sources :

Example 1 with TransactionOptions

use of com.google.firestore.v1beta1.TransactionOptions in project java-spanner by googleapis.

the class SpannerClientTest method commitTest4.

@Test
public void commitTest4() throws Exception {
    CommitResponse expectedResponse = CommitResponse.newBuilder().setCommitTimestamp(Timestamp.newBuilder().build()).setCommitStats(CommitResponse.CommitStats.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    String session = "session1984987798";
    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, 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) ByteString(com.google.protobuf.ByteString) Mutation(com.google.spanner.v1.Mutation) Test(org.junit.Test)

Example 2 with TransactionOptions

use of com.google.firestore.v1beta1.TransactionOptions in project java-spanner by googleapis.

the class SpannerClientTest method commitExceptionTest4.

@Test
public void commitExceptionTest4() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSpanner.addException(exception);
    try {
        String session = "session1984987798";
        TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build();
        List<Mutation> mutations = new ArrayList<>();
        client.commit(session, singleUseTransaction, mutations);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) TransactionOptions(com.google.spanner.v1.TransactionOptions) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Mutation(com.google.spanner.v1.Mutation) Test(org.junit.Test)

Example 3 with TransactionOptions

use of com.google.firestore.v1beta1.TransactionOptions 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 4 with TransactionOptions

use of com.google.firestore.v1beta1.TransactionOptions 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 5 with TransactionOptions

use of com.google.firestore.v1beta1.TransactionOptions in project java-spanner by googleapis.

the class SpannerClientTest method beginTransactionTest2.

@Test
public void beginTransactionTest2() throws Exception {
    Transaction expectedResponse = Transaction.newBuilder().setId(ByteString.EMPTY).setReadTimestamp(Timestamp.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    String session = "session1984987798";
    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, 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) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

TransactionOptions (com.google.spanner.v1.TransactionOptions)16 Test (org.junit.Test)12 TransactionSelector (com.google.spanner.v1.TransactionSelector)6 Session (com.google.spanner.v1.Session)5 ArrayList (java.util.ArrayList)5 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 ByteString (com.google.protobuf.ByteString)4 Mutation (com.google.spanner.v1.Mutation)4 PartitionResponse (com.google.spanner.v1.PartitionResponse)4 SessionName (com.google.spanner.v1.SessionName)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 BeginTransactionRequest (com.google.spanner.v1.BeginTransactionRequest)3 CommitRequest (com.google.spanner.v1.CommitRequest)3 PartitionQueryRequest (com.google.spanner.v1.PartitionQueryRequest)3 Transaction (com.google.spanner.v1.Transaction)3 TransactionOptions (com.google.datastore.v1.TransactionOptions)2 GcpManagedChannel (com.google.grpc.gcp.GcpManagedChannel)2 CommitResponse (com.google.spanner.v1.CommitResponse)2 SpannerStub (com.google.spanner.v1.SpannerGrpc.SpannerStub)2