Search in sources :

Example 1 with Poller

use of uk.gov.justice.services.test.utils.core.messaging.Poller in project microservice_framework by CJSCommonPlatform.

the class StreamStatusJdbcRepositoryIT method initDatabase.

@Before
public void initDatabase() throws Exception {
    final TestDataSourceFactory testDataSourceFactory = new TestDataSourceFactory(LIQUIBASE_STREAM_STATUS_CHANGELOG_XML);
    final JdbcDataSource dataSource = testDataSourceFactory.createDataSource();
    jdbcRepository = new StreamStatusJdbcRepository(dataSource, new JdbcRepositoryHelper());
    try {
        final Poller poller = new Poller();
        poller.pollUntilFound(() -> {
            try {
                dataSource.getConnection().prepareStatement("SELECT COUNT (*) FROM stream_buffer;").execute();
                return Optional.of("Success");
            } catch (SQLException e) {
                e.printStackTrace();
                fail("EventJdbcRepository construction failed");
                return Optional.empty();
            }
        });
    } catch (final Exception e) {
        e.printStackTrace();
        fail("EventJdbcRepository construction failed");
    }
}
Also used : JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper) SQLException(java.sql.SQLException) TestDataSourceFactory(uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Poller(uk.gov.justice.services.test.utils.core.messaging.Poller) SQLException(java.sql.SQLException) Before(org.junit.Before)

Example 2 with Poller

use of uk.gov.justice.services.test.utils.core.messaging.Poller in project microservice_framework by CJSCommonPlatform.

the class EventStreamJdbcRepositoryIT method initialize.

@Before
public void initialize() {
    try {
        jdbcRepository.dataSource = new TestDataSourceFactory(LIQUIBASE_EVENT_STORE_DB_CHANGELOG_XML).createDataSource();
        jdbcRepository.logger = mock(Logger.class);
        jdbcRepository.eventStreamJdbcRepositoryHelper = new JdbcRepositoryHelper();
        jdbcRepository.clock = new UtcClock();
        final Poller poller = new Poller();
        poller.pollUntilFound(() -> {
            try {
                jdbcRepository.dataSource.getConnection().prepareStatement("SELECT COUNT (*) FROM event_stream;").execute();
                return Optional.of("Success");
            } catch (SQLException e) {
                e.printStackTrace();
                return Optional.empty();
            }
        });
    } catch (final Exception e) {
        e.printStackTrace();
        Assert.fail("EventStreamJdbcRepository construction failed");
    }
}
Also used : UtcClock(uk.gov.justice.services.common.util.UtcClock) JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper) SQLException(java.sql.SQLException) TestDataSourceFactory(uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory) Logger(org.slf4j.Logger) Poller(uk.gov.justice.services.test.utils.core.messaging.Poller) InvalidPositionException(uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException) SQLException(java.sql.SQLException) Before(org.junit.Before)

Example 3 with Poller

use of uk.gov.justice.services.test.utils.core.messaging.Poller in project microservice_framework by CJSCommonPlatform.

the class StreamBufferJdbcRepositoryIT method initDatabase.

@Before
public void initDatabase() throws Exception {
    final TestDataSourceFactory testDataSourceFactory = new TestDataSourceFactory(LIQUIBASE_STREAM_STATUS_CHANGELOG_XML);
    final JdbcDataSource dataSource = testDataSourceFactory.createDataSource();
    jdbcRepository = new StreamBufferJdbcRepository(dataSource, new JdbcRepositoryHelper());
    try {
        final Poller poller = new Poller();
        poller.pollUntilFound(() -> {
            try {
                dataSource.getConnection().prepareStatement("SELECT COUNT (*) FROM stream_buffer;").execute();
                return Optional.of("Success");
            } catch (SQLException e) {
                e.printStackTrace();
                fail("EventJdbcRepository construction failed");
                return Optional.empty();
            }
        });
    } catch (final Exception e) {
        e.printStackTrace();
        fail("EventJdbcRepository construction failed");
    }
}
Also used : JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper) SQLException(java.sql.SQLException) TestDataSourceFactory(uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Poller(uk.gov.justice.services.test.utils.core.messaging.Poller) SQLException(java.sql.SQLException) Before(org.junit.Before)

Example 4 with Poller

use of uk.gov.justice.services.test.utils.core.messaging.Poller in project microservice_framework by CJSCommonPlatform.

the class EventJdbcRepositoryIT method initialize.

@Before
public void initialize() {
    try {
        jdbcRepository.dataSource = new TestDataSourceFactory(LIQUIBASE_EVENT_STORE_DB_CHANGELOG_XML).createDataSource();
        jdbcRepository.logger = mock(Logger.class);
        jdbcRepository.eventInsertionStrategy = new AnsiSQLEventLogInsertionStrategy();
        jdbcRepository.jdbcRepositoryHelper = new JdbcRepositoryHelper();
        final Poller poller = new Poller();
        poller.pollUntilFound(() -> {
            try {
                jdbcRepository.dataSource.getConnection().prepareStatement("SELECT COUNT (*) FROM event_log;").execute();
                return Optional.of("Success");
            } catch (SQLException e) {
                e.printStackTrace();
                fail("EventJdbcRepository construction failed");
                return Optional.empty();
            }
        });
    } catch (final Exception e) {
        e.printStackTrace();
        fail("EventJdbcRepository construction failed");
    }
}
Also used : JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper) SQLException(java.sql.SQLException) TestDataSourceFactory(uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory) AnsiSQLEventLogInsertionStrategy(uk.gov.justice.services.eventsourcing.repository.jdbc.AnsiSQLEventLogInsertionStrategy) Logger(org.slf4j.Logger) Poller(uk.gov.justice.services.test.utils.core.messaging.Poller) JdbcRepositoryException(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException) SQLException(java.sql.SQLException) InvalidPositionException(uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException) Before(org.junit.Before)

Aggregations

SQLException (java.sql.SQLException)4 Before (org.junit.Before)4 JdbcRepositoryHelper (uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper)4 Poller (uk.gov.justice.services.test.utils.core.messaging.Poller)4 TestDataSourceFactory (uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory)4 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)2 Logger (org.slf4j.Logger)2 InvalidPositionException (uk.gov.justice.services.eventsourcing.repository.jdbc.exception.InvalidPositionException)2 UtcClock (uk.gov.justice.services.common.util.UtcClock)1 AnsiSQLEventLogInsertionStrategy (uk.gov.justice.services.eventsourcing.repository.jdbc.AnsiSQLEventLogInsertionStrategy)1 JdbcRepositoryException (uk.gov.justice.services.jdbc.persistence.JdbcRepositoryException)1