Search in sources :

Example 36 with StepVerifier

use of reactor.test.StepVerifier in project spring-framework by spring-projects.

the class TransactionalOperatorTests method commitWithFlux.

@Test
public void commitWithFlux() {
    TransactionalOperator operator = TransactionalOperator.create(tm, new DefaultTransactionDefinition());
    Flux.just(1, 2, 3, 4).as(operator::transactional).as(StepVerifier::create).expectNextCount(4).verifyComplete();
    assertThat(tm.commit).isTrue();
    assertThat(tm.rollback).isFalse();
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 37 with StepVerifier

use of reactor.test.StepVerifier in project spring-framework by spring-projects.

the class ReactiveTransactionSupportTests method transactionTemplateWithException.

@Test
public void transactionTemplateWithException() {
    ReactiveTestTransactionManager tm = new ReactiveTestTransactionManager(false, true);
    TransactionalOperator operator = TransactionalOperator.create(tm, new DefaultTransactionDefinition());
    RuntimeException ex = new RuntimeException("Some application exception");
    Mono.error(ex).as(operator::transactional).as(StepVerifier::create).expectError(RuntimeException.class).verify();
    assertHasBegan(tm);
    assertHasNotCommitted(tm);
    assertHasRolledBack(tm);
    assertHasNotSetRollbackOnly(tm);
    assertHasCleanedUp(tm);
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 38 with StepVerifier

use of reactor.test.StepVerifier in project spring-framework by spring-projects.

the class ReactiveTransactionSupportTests method transactionTemplate.

@Test
public void transactionTemplate() {
    ReactiveTestTransactionManager tm = new ReactiveTestTransactionManager(false, true);
    TransactionalOperator operator = TransactionalOperator.create(tm, new DefaultTransactionDefinition());
    Flux.just("Walter").as(operator::transactional).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    assertHasBegan(tm);
    assertHasCommitted(tm);
    assertHasNoRollback(tm);
    assertHasNotSetRollbackOnly(tm);
    assertHasCleanedUp(tm);
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 39 with StepVerifier

use of reactor.test.StepVerifier in project spring-framework by spring-projects.

the class ReactiveTransactionSupportTests method noExistingTransaction.

@Test
public void noExistingTransaction() {
    ReactiveTransactionManager tm = new ReactiveTestTransactionManager(false, true);
    tm.getReactiveTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_SUPPORTS)).contextWrite(TransactionContextManager.createTransactionContext()).cast(GenericReactiveTransaction.class).as(StepVerifier::create).consumeNextWith(actual -> assertThat(actual.hasTransaction()).isFalse()).verifyComplete();
    tm.getReactiveTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED)).cast(GenericReactiveTransaction.class).contextWrite(TransactionContextManager.createTransactionContext()).as(StepVerifier::create).consumeNextWith(actual -> {
        assertThat(actual.hasTransaction()).isTrue();
        assertThat(actual.isNewTransaction()).isTrue();
    }).verifyComplete();
    tm.getReactiveTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_MANDATORY)).contextWrite(TransactionContextManager.createTransactionContext()).cast(GenericReactiveTransaction.class).as(StepVerifier::create).expectError(IllegalTransactionStateException.class).verify();
}
Also used : Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) StepVerifier(reactor.test.StepVerifier) TransactionDefinition(org.springframework.transaction.TransactionDefinition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) ReactiveTransaction(org.springframework.transaction.ReactiveTransaction) IllegalTransactionStateException(org.springframework.transaction.IllegalTransactionStateException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) ReactiveTransactionManager(org.springframework.transaction.ReactiveTransactionManager) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) ReactiveTransactionManager(org.springframework.transaction.ReactiveTransactionManager) IllegalTransactionStateException(org.springframework.transaction.IllegalTransactionStateException) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 40 with StepVerifier

use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.

the class ReactiveMongoDatabaseUtilsUnitTests method shouldParticipateInOngoingMongoTransactionWhenSessionSychronizationIsNative.

// DATAMONGO-2265
@Test
void shouldParticipateInOngoingMongoTransactionWhenSessionSychronizationIsNative() {
    when(session.getServerSession()).thenReturn(serverSession);
    when(databaseFactory.getSession(any())).thenReturn(Mono.just(session));
    ReactiveMongoTransactionManager txManager = new ReactiveMongoTransactionManager(databaseFactory);
    when(session.abortTransaction()).thenReturn(Mono.empty());
    TransactionalOperator operator = TransactionalOperator.create(txManager, new DefaultTransactionDefinition());
    operator.execute(tx -> {
        return TransactionSynchronizationManager.forCurrentTransaction().doOnNext(synchronizationManager -> {
            assertThat(synchronizationManager.isSynchronizationActive()).isTrue();
            assertThat(tx.isNewTransaction()).isTrue();
            assertThat(synchronizationManager.hasResource(databaseFactory)).isTrue();
        }).then(Mono.fromRunnable(tx::setRollbackOnly));
    }).as(StepVerifier::create).verifyComplete();
    verify(session).startTransaction();
    verify(session).abortTransaction();
    verify(session).close();
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers(org.mockito.ArgumentMatchers) StepVerifier(reactor.test.StepVerifier) Mock(org.mockito.Mock) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) Mono(reactor.core.publisher.Mono) ClientSession(com.mongodb.reactivestreams.client.ClientSession) ServerSession(com.mongodb.session.ServerSession) Test(org.junit.jupiter.api.Test) TransactionSynchronizationManager(org.springframework.transaction.reactive.TransactionSynchronizationManager) Mockito(org.mockito.Mockito) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) MongoDatabase(com.mongodb.reactivestreams.client.MongoDatabase) Assertions(org.assertj.core.api.Assertions) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

StepVerifier (reactor.test.StepVerifier)234 Test (org.junit.jupiter.api.Test)176 Mono (reactor.core.publisher.Mono)111 Flux (reactor.core.publisher.Flux)92 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)77 Duration (java.time.Duration)76 BeforeEach (org.junit.jupiter.api.BeforeEach)60 Test (org.junit.Test)55 Query (org.springframework.data.mongodb.core.query.Query)54 Assertions (org.assertj.core.api.Assertions)53 Document (org.bson.Document)49 Arrays (java.util.Arrays)46 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)44 Criteria (org.springframework.data.mongodb.core.query.Criteria)44 TimeUnit (java.util.concurrent.TimeUnit)42 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)42 Disposable (reactor.core.Disposable)39 List (java.util.List)38 ClassPathResource (org.springframework.core.io.ClassPathResource)38 AtomicReference (java.util.concurrent.atomic.AtomicReference)37