Search in sources :

Example 31 with StepVerifier

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

the class SingleConnectionFactoryUnitTests method releaseConnectionShouldCloseUnrelatedConnection.

@Test
void releaseConnectionShouldCloseUnrelatedConnection() {
    Connection connectionMock = mock(Connection.class);
    Connection otherConnection = mock(Connection.class);
    ConnectionFactoryMetadata metadata = mock(ConnectionFactoryMetadata.class);
    when(otherConnection.close()).thenReturn(Mono.empty());
    SingleConnectionFactory factory = new SingleConnectionFactory(connectionMock, metadata, false);
    factory.create().as(StepVerifier::create).expectNextCount(1).verifyComplete();
    ConnectionFactoryUtils.releaseConnection(otherConnection, factory).as(StepVerifier::create).verifyComplete();
    verify(otherConnection).close();
}
Also used : Connection(io.r2dbc.spi.Connection) H2Connection(io.r2dbc.h2.H2Connection) StepVerifier(reactor.test.StepVerifier) ConnectionFactoryMetadata(io.r2dbc.spi.ConnectionFactoryMetadata) Test(org.junit.jupiter.api.Test)

Example 32 with StepVerifier

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

the class TransactionalOperatorTests method monoSubscriptionNotCancelled.

@Test
public void monoSubscriptionNotCancelled() {
    AtomicBoolean cancelled = new AtomicBoolean();
    TransactionalOperator operator = TransactionalOperator.create(tm, new DefaultTransactionDefinition());
    Mono.just(true).doOnCancel(() -> cancelled.set(true)).as(operator::transactional).as(StepVerifier::create).expectNext(true).verifyComplete();
    assertThat(tm.commit).isTrue();
    assertThat(tm.rollback).isFalse();
    assertThat(cancelled).isFalse();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 33 with StepVerifier

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

the class TransactionalOperatorTests method commitWithMono.

@Test
public void commitWithMono() {
    TransactionalOperator operator = TransactionalOperator.create(tm, new DefaultTransactionDefinition());
    Mono.just(true).as(operator::transactional).as(StepVerifier::create).expectNext(true).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 34 with StepVerifier

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

the class TransactionalOperatorTests method cancellationPropagatedToFlux.

@Test
public void cancellationPropagatedToFlux() {
    AtomicBoolean cancelled = new AtomicBoolean();
    TransactionalOperator operator = TransactionalOperator.create(tm, new DefaultTransactionDefinition());
    Flux.create(sink -> sink.onCancel(() -> cancelled.set(true))).as(operator::transactional).as(StepVerifier::create).thenAwait().thenCancel().verify();
    assertThat(tm.commit).isFalse();
    assertThat(tm.rollback).isTrue();
    assertThat(cancelled).isTrue();
}
Also used : Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) StepVerifier(reactor.test.StepVerifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Mono(reactor.core.publisher.Mono) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Test(org.junit.jupiter.api.Test)

Example 35 with StepVerifier

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

the class TransactionalOperatorTests method cancellationPropagatedToMono.

@Test
public void cancellationPropagatedToMono() {
    AtomicBoolean cancelled = new AtomicBoolean();
    TransactionalOperator operator = TransactionalOperator.create(tm, new DefaultTransactionDefinition());
    Mono.create(sink -> sink.onCancel(() -> cancelled.set(true))).as(operator::transactional).as(StepVerifier::create).thenAwait().thenCancel().verify();
    assertThat(tm.commit).isFalse();
    assertThat(tm.rollback).isTrue();
    assertThat(cancelled).isTrue();
}
Also used : Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) StepVerifier(reactor.test.StepVerifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Mono(reactor.core.publisher.Mono) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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