Search in sources :

Example 6 with FirestoreTemplate

use of org.springframework.cloud.gcp.data.firestore.FirestoreTemplate in project spring-cloud-gcp by spring-cloud.

the class ReactiveFirestoreTransactionManagerTest method triggerRollbackCorrectly.

@Test
public void triggerRollbackCorrectly() {
    FirestoreTemplate template = getFirestoreTemplate();
    ReactiveFirestoreTransactionManager txManager = new ReactiveFirestoreTransactionManager(this.firestoreStub, this.parent);
    TransactionalOperator operator = TransactionalOperator.create(txManager);
    template.findById(Mono.defer(() -> {
        throw new FirestoreDataException("BOOM!");
    }), FirestoreTemplateTests.TestEntity.class).as(operator::transactional).as(StepVerifier::create).expectError().verify();
    verify(this.firestoreStub, times(1)).beginTransaction(any(), any());
    verify(this.firestoreStub, times(0)).commit(any(), any());
    verify(this.firestoreStub, times(1)).rollback(any(), any());
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) FirestoreDataException(org.springframework.cloud.gcp.data.firestore.FirestoreDataException) FirestoreTemplateTests(org.springframework.cloud.gcp.data.firestore.FirestoreTemplateTests) StepVerifier(reactor.test.StepVerifier) FirestoreTemplate(org.springframework.cloud.gcp.data.firestore.FirestoreTemplate) Test(org.junit.Test)

Aggregations

FirestoreTemplate (org.springframework.cloud.gcp.data.firestore.FirestoreTemplate)6 Test (org.junit.Test)5 GetDocumentRequest (com.google.firestore.v1.GetDocumentRequest)3 TransactionalOperator (org.springframework.transaction.reactive.TransactionalOperator)3 StepVerifier (reactor.test.StepVerifier)3 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)2 FirestoreOptions (com.google.cloud.firestore.FirestoreOptions)2 BeginTransactionResponse (com.google.firestore.v1.BeginTransactionResponse)2 CommitRequest (com.google.firestore.v1.CommitRequest)2 CommitResponse (com.google.firestore.v1.CommitResponse)2 Document (com.google.firestore.v1.Document)2 RollbackRequest (com.google.firestore.v1.RollbackRequest)2 ByteString (com.google.protobuf.ByteString)2 Empty (com.google.protobuf.Empty)2 FirestoreDataException (org.springframework.cloud.gcp.data.firestore.FirestoreDataException)2 FirestoreTemplateTests (org.springframework.cloud.gcp.data.firestore.FirestoreTemplateTests)2 FirestoreDefaultClassMapper (org.springframework.cloud.gcp.data.firestore.mapping.FirestoreDefaultClassMapper)2 FirestoreMappingContext (org.springframework.cloud.gcp.data.firestore.mapping.FirestoreMappingContext)2 FirestoreGrpc (com.google.firestore.v1.FirestoreGrpc)1 StreamObserver (io.grpc.stub.StreamObserver)1