use of org.springframework.transaction.reactive.TransactionalOperator in project spring-framework by spring-projects.
the class R2dbcTransactionManagerUnitTests method testPropagationSupportsAndRequiresNew.
@Test
void testPropagationSupportsAndRequiresNew() {
when(connectionMock.commitTransaction()).thenReturn(Mono.empty());
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
TransactionalOperator operator = TransactionalOperator.create(tm, definition);
operator.execute(tx1 -> {
assertThat(tx1.isNewTransaction()).isFalse();
DefaultTransactionDefinition innerDef = new DefaultTransactionDefinition();
innerDef.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionalOperator inner = TransactionalOperator.create(tm, innerDef);
return inner.execute(tx2 -> {
assertThat(tx2.isNewTransaction()).isTrue();
return Mono.empty();
});
}).as(StepVerifier::create).verifyComplete();
verify(connectionMock).commitTransaction();
verify(connectionMock).close();
}
use of org.springframework.transaction.reactive.TransactionalOperator in project spring-framework by spring-projects.
the class R2dbcTransactionManagerUnitTests method restoresAutoCommit.
@Test
void restoresAutoCommit() {
when(connectionMock.isAutoCommit()).thenReturn(true);
when(connectionMock.setAutoCommit(anyBoolean())).thenReturn(Mono.empty());
when(connectionMock.commitTransaction()).thenReturn(Mono.empty());
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
TransactionalOperator operator = TransactionalOperator.create(tm, definition);
ConnectionFactoryUtils.getConnection(connectionFactoryMock).as(operator::transactional).as(StepVerifier::create).expectNextCount(1).verifyComplete();
verify(connectionMock).beginTransaction();
verify(connectionMock).setAutoCommit(false);
verify(connectionMock).setAutoCommit(true);
verify(connectionMock).commitTransaction();
verify(connectionMock).close();
}
use of org.springframework.transaction.reactive.TransactionalOperator in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTransactionManagerUnitTests method readonlyShouldInitiateASessionStartAndCommitTransaction.
// DATAMONGO-2265
@Test
void readonlyShouldInitiateASessionStartAndCommitTransaction() {
ReactiveMongoTransactionManager txManager = new ReactiveMongoTransactionManager(databaseFactory);
ReactiveMongoTemplate template = new ReactiveMongoTemplate(databaseFactory);
when(session.commitTransaction()).thenReturn(Mono.empty());
DefaultTransactionDefinition readonlyTxDefinition = new DefaultTransactionDefinition();
readonlyTxDefinition.setReadOnly(true);
TransactionalOperator operator = TransactionalOperator.create(txManager, readonlyTxDefinition);
template.execute(db -> {
db.drop();
return Mono.empty();
}).as(//
operator::transactional).as(//
StepVerifier::create).verifyComplete();
verify(databaseFactory).withSession(eq(session));
verify(session).startTransaction();
verify(session).commitTransaction();
verify(session).close();
}
use of org.springframework.transaction.reactive.TransactionalOperator in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTransactionManagerUnitTests method triggerCommitCorrectly.
// DATAMONGO-2265
@Test
void triggerCommitCorrectly() {
ReactiveMongoTransactionManager txManager = new ReactiveMongoTransactionManager(databaseFactory);
ReactiveMongoTemplate template = new ReactiveMongoTemplate(databaseFactory);
when(session.commitTransaction()).thenReturn(Mono.empty());
TransactionalOperator operator = TransactionalOperator.create(txManager, new DefaultTransactionDefinition());
template.execute(db -> {
db.drop();
return Mono.empty();
}).as(//
operator::transactional).as(//
StepVerifier::create).verifyComplete();
verify(databaseFactory).withSession(eq(session));
verify(session).startTransaction();
verify(session).commitTransaction();
verify(session).close();
}
use of org.springframework.transaction.reactive.TransactionalOperator in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTransactionManagerUnitTests method participateInOnGoingTransactionWithRollbackOnly.
// DATAMONGO-2265
@Test
void participateInOnGoingTransactionWithRollbackOnly() {
ReactiveMongoTransactionManager txManager = new ReactiveMongoTransactionManager(databaseFactory);
ReactiveMongoTemplate template = new ReactiveMongoTemplate(databaseFactory);
when(session.abortTransaction()).thenReturn(Mono.empty());
TransactionalOperator operator = TransactionalOperator.create(txManager, new DefaultTransactionDefinition());
operator.execute(tx -> {
return template.execute(db -> {
db.drop();
tx.setRollbackOnly();
return Mono.empty();
});
}).as(StepVerifier::create).verifyComplete();
verify(databaseFactory, times(1)).withSession(eq(session));
verify(session).startTransaction();
verify(session).abortTransaction();
verify(session).close();
}
Aggregations