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();
}
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);
}
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);
}
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();
}
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();
}
Aggregations