Search in sources :

Example 21 with StepVerifier

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

the class Neo4jReactiveHealthIndicatorTests method neo4jIsUp.

@Test
void neo4jIsUp() {
    ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", "test");
    Driver driver = mockDriver(resultSummary, "4711", "ultimate collectors edition");
    Neo4jReactiveHealthIndicator healthIndicator = new Neo4jReactiveHealthIndicator(driver);
    healthIndicator.health().as(StepVerifier::create).consumeNextWith((health) -> {
        assertThat(health.getStatus()).isEqualTo(Status.UP);
        assertThat(health.getDetails()).containsEntry("server", "4711@My Home");
        assertThat(health.getDetails()).containsEntry("edition", "ultimate collectors edition");
    }).verifyComplete();
}
Also used : Status(org.springframework.boot.actuate.health.Status) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Driver(org.neo4j.driver.Driver) StepVerifier(reactor.test.StepVerifier) RxSession(org.neo4j.driver.reactive.RxSession) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SessionExpiredException(org.neo4j.driver.exceptions.SessionExpiredException) BDDMockito.then(org.mockito.BDDMockito.then) Mono(reactor.core.publisher.Mono) Mockito.times(org.mockito.Mockito.times) RxResult(org.neo4j.driver.reactive.RxResult) Test(org.junit.jupiter.api.Test) Values(org.neo4j.driver.Values) SessionConfig(org.neo4j.driver.SessionConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BDDMockito.given(org.mockito.BDDMockito.given) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ResultSummary(org.neo4j.driver.summary.ResultSummary) Record(org.neo4j.driver.Record) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) ResultSummary(org.neo4j.driver.summary.ResultSummary) Driver(org.neo4j.driver.Driver) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 22 with StepVerifier

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

the class R2dbcTransactionManagerUnitTests method testSimpleTransaction.

@Test
void testSimpleTransaction() {
    TestTransactionSynchronization sync = new TestTransactionSynchronization(TransactionSynchronization.STATUS_COMMITTED);
    AtomicInteger commits = new AtomicInteger();
    when(connectionMock.commitTransaction()).thenReturn(Mono.fromRunnable(commits::incrementAndGet));
    TransactionalOperator operator = TransactionalOperator.create(tm);
    ConnectionFactoryUtils.getConnection(connectionFactoryMock).flatMap(connection -> TransactionSynchronizationManager.forCurrentTransaction().doOnNext(synchronizationManager -> synchronizationManager.registerSynchronization(sync))).as(operator::transactional).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    assertThat(commits).hasValue(1);
    verify(connectionMock).isAutoCommit();
    verify(connectionMock).beginTransaction();
    verify(connectionMock).commitTransaction();
    verify(connectionMock).close();
    verifyNoMoreInteractions(connectionMock);
    assertThat(sync.beforeCommitCalled).isTrue();
    assertThat(sync.afterCommitCalled).isTrue();
    assertThat(sync.beforeCompletionCalled).isTrue();
    assertThat(sync.afterCompletionCalled).isTrue();
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) TransactionDefinition(org.springframework.transaction.TransactionDefinition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IllegalTransactionStateException(org.springframework.transaction.IllegalTransactionStateException) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) BDDMockito.when(org.mockito.BDDMockito.when) BDDMockito.verify(org.mockito.BDDMockito.verify) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionSynchronization(org.springframework.transaction.reactive.TransactionSynchronization) BDDMockito.never(org.mockito.BDDMockito.never) R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) Mono(reactor.core.publisher.Mono) BDDMockito.verifyNoMoreInteractions(org.mockito.BDDMockito.verifyNoMoreInteractions) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) TransactionSynchronizationManager(org.springframework.transaction.reactive.TransactionSynchronizationManager) IsolationLevel(io.r2dbc.spi.IsolationLevel) Assertions.fail(org.assertj.core.api.Assertions.fail) BDDMockito.mock(org.mockito.BDDMockito.mock) Statement(io.r2dbc.spi.Statement) BDDMockito.reset(org.mockito.BDDMockito.reset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 23 with StepVerifier

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

the class R2dbcTransactionManagerUnitTests method appliesIsolationLevel.

@Test
void appliesIsolationLevel() {
    when(connectionMock.commitTransaction()).thenReturn(Mono.empty());
    when(connectionMock.getTransactionIsolationLevel()).thenReturn(IsolationLevel.READ_COMMITTED);
    when(connectionMock.setTransactionIsolationLevel(any())).thenReturn(Mono.empty());
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
    TransactionalOperator operator = TransactionalOperator.create(tm, definition);
    ConnectionFactoryUtils.getConnection(connectionFactoryMock).as(operator::transactional).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    verify(connectionMock).beginTransaction();
    verify(connectionMock).setTransactionIsolationLevel(IsolationLevel.READ_COMMITTED);
    verify(connectionMock).setTransactionIsolationLevel(IsolationLevel.SERIALIZABLE);
    verify(connectionMock).commitTransaction();
    verify(connectionMock).close();
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 24 with StepVerifier

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

the class R2dbcTransactionManagerUnitTests method doesNotSetAutoCommitDisabled.

@Test
void doesNotSetAutoCommitDisabled() {
    when(connectionMock.isAutoCommit()).thenReturn(false);
    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, never()).setAutoCommit(anyBoolean());
    verify(connectionMock).commitTransaction();
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 25 with StepVerifier

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

the class R2dbcTransactionManagerUnitTests method appliesReadOnly.

@Test
void appliesReadOnly() {
    when(connectionMock.commitTransaction()).thenReturn(Mono.empty());
    when(connectionMock.setTransactionIsolationLevel(any())).thenReturn(Mono.empty());
    Statement statement = mock(Statement.class);
    when(connectionMock.createStatement(anyString())).thenReturn(statement);
    when(statement.execute()).thenReturn(Mono.empty());
    tm.setEnforceReadOnly(true);
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setReadOnly(true);
    TransactionalOperator operator = TransactionalOperator.create(tm, definition);
    ConnectionFactoryUtils.getConnection(connectionFactoryMock).as(operator::transactional).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    verify(connectionMock).isAutoCommit();
    verify(connectionMock).beginTransaction();
    verify(connectionMock).createStatement("SET TRANSACTION READ ONLY");
    verify(connectionMock).commitTransaction();
    verify(connectionMock).close();
    verifyNoMoreInteractions(connectionMock);
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Statement(io.r2dbc.spi.Statement) StepVerifier(reactor.test.StepVerifier) 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