Search in sources :

Example 6 with BeginTransactionResponse

use of com.google.datastore.v1.BeginTransactionResponse in project spring-cloud-gcp by GoogleCloudPlatform.

the class ReactiveFirestoreTransactionManager method startTransaction.

private Mono<ReactiveFirestoreResourceHolder> startTransaction(TransactionDefinition definition) {
    TransactionOptions.Builder txOptions = definition.isReadOnly() ? TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.newBuilder().build()) : TransactionOptions.newBuilder().setReadWrite(TransactionOptions.ReadWrite.newBuilder().build());
    BeginTransactionRequest beginTransactionRequest = BeginTransactionRequest.newBuilder().setOptions(txOptions).setDatabase(this.databasePath).build();
    return ObservableReactiveUtil.<BeginTransactionResponse>unaryCall(obs -> this.firestore.beginTransaction(beginTransactionRequest, obs)).map(beginTransactionResponse -> new ReactiveFirestoreResourceHolder(beginTransactionResponse.getTransaction()));
}
Also used : CommitResponse(com.google.firestore.v1.CommitResponse) FirestoreGrpc(com.google.firestore.v1.FirestoreGrpc) Util(com.google.cloud.spring.data.firestore.util.Util) TransactionDefinition(org.springframework.transaction.TransactionDefinition) Mono(reactor.core.publisher.Mono) Timestamp(com.google.cloud.Timestamp) BeginTransactionRequest(com.google.firestore.v1.BeginTransactionRequest) AbstractReactiveTransactionManager(org.springframework.transaction.reactive.AbstractReactiveTransactionManager) ByteString(com.google.protobuf.ByteString) TransactionSynchronizationManager(org.springframework.transaction.reactive.TransactionSynchronizationManager) BeginTransactionResponse(com.google.firestore.v1.BeginTransactionResponse) Empty(com.google.protobuf.Empty) SmartTransactionObject(org.springframework.transaction.support.SmartTransactionObject) TransactionSystemException(org.springframework.transaction.TransactionSystemException) GenericReactiveTransaction(org.springframework.transaction.reactive.GenericReactiveTransaction) CommitRequest(com.google.firestore.v1.CommitRequest) TransactionOptions(com.google.firestore.v1.TransactionOptions) RollbackRequest(com.google.firestore.v1.RollbackRequest) TransactionException(org.springframework.transaction.TransactionException) FirestoreStub(com.google.firestore.v1.FirestoreGrpc.FirestoreStub) Nullable(org.springframework.lang.Nullable) FirestoreClassMapper(com.google.cloud.spring.data.firestore.mapping.FirestoreClassMapper) ObservableReactiveUtil(com.google.cloud.spring.data.firestore.util.ObservableReactiveUtil) Assert(org.springframework.util.Assert) TransactionOptions(com.google.firestore.v1.TransactionOptions) BeginTransactionRequest(com.google.firestore.v1.BeginTransactionRequest)

Example 7 with BeginTransactionResponse

use of com.google.datastore.v1.BeginTransactionResponse in project java-datastore by googleapis.

the class RemoteRpcTest method testGzip.

@Test
public void testGzip() throws IOException, DatastoreException {
    BeginTransactionResponse response = newBeginTransactionResponse();
    InjectedTestValues injectedTestValues = new InjectedTestValues(gzip(response), new byte[1], true);
    RemoteRpc rpc = newRemoteRpc(injectedTestValues);
    InputStream is = rpc.call("beginTransaction", BeginTransactionResponse.getDefaultInstance());
    BeginTransactionResponse parsedResponse = BeginTransactionResponse.parseFrom(is);
    is.close();
    assertEquals(response, parsedResponse);
    // Check that the underlying stream is exhausted.
    assertEquals(-1, injectedTestValues.inputStream.read());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BeginTransactionResponse(com.google.datastore.v1.BeginTransactionResponse) Test(org.junit.Test)

Example 8 with BeginTransactionResponse

use of com.google.datastore.v1.BeginTransactionResponse in project java-firestore by googleapis.

the class FirestoreClientTest method beginTransactionTest.

@Test
public void beginTransactionTest() throws Exception {
    BeginTransactionResponse expectedResponse = BeginTransactionResponse.newBuilder().setTransaction(ByteString.EMPTY).build();
    mockFirestore.addResponse(expectedResponse);
    String database = "database1789464955";
    BeginTransactionResponse actualResponse = client.beginTransaction(database);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockFirestore.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    BeginTransactionRequest actualRequest = ((BeginTransactionRequest) actualRequests.get(0));
    Assert.assertEquals(database, actualRequest.getDatabase());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) BeginTransactionRequest(com.google.firestore.v1.BeginTransactionRequest) ByteString(com.google.protobuf.ByteString) BeginTransactionResponse(com.google.firestore.v1.BeginTransactionResponse) Test(org.junit.Test)

Aggregations

BeginTransactionResponse (com.google.firestore.v1.BeginTransactionResponse)5 ByteString (com.google.protobuf.ByteString)5 CommitRequest (com.google.firestore.v1.CommitRequest)4 CommitResponse (com.google.firestore.v1.CommitResponse)4 RollbackRequest (com.google.firestore.v1.RollbackRequest)4 Empty (com.google.protobuf.Empty)4 BeginTransactionRequest (com.google.firestore.v1.BeginTransactionRequest)3 Test (org.junit.Test)3 BeginTransactionResponse (com.google.datastore.v1.BeginTransactionResponse)2 Document (com.google.firestore.v1.Document)2 FirestoreGrpc (com.google.firestore.v1.FirestoreGrpc)2 GetDocumentRequest (com.google.firestore.v1.GetDocumentRequest)2 TransactionOptions (com.google.firestore.v1.TransactionOptions)2 Nullable (org.springframework.lang.Nullable)2 TransactionDefinition (org.springframework.transaction.TransactionDefinition)2 TransactionException (org.springframework.transaction.TransactionException)2 TransactionSystemException (org.springframework.transaction.TransactionSystemException)2 AbstractReactiveTransactionManager (org.springframework.transaction.reactive.AbstractReactiveTransactionManager)2 GenericReactiveTransaction (org.springframework.transaction.reactive.GenericReactiveTransaction)2 TransactionSynchronizationManager (org.springframework.transaction.reactive.TransactionSynchronizationManager)2