Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-DATAJDBC-573-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-DATAJDBC-573-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-DATAJDBC-573-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-DATAJDBC-573-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@

import javax.sql.DataSource;

import org.awaitility.Awaitility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;

import java.sql.Connection;
import java.util.concurrent.TimeUnit;

import static org.awaitility.pollinterval.FibonacciPollInterval.*;

/**
* Basic configuration expecting subclasses to provide a {@link DataSource} via {@link #createDataSource()} to be
* exposed to the {@link ApplicationContext}.
Expand All @@ -36,12 +45,17 @@
@Configuration
abstract class DataSourceConfiguration {

private static final Logger LOG = LoggerFactory.getLogger(DataSourceConfiguration.class);


@Autowired Class<?> testClass;
@Autowired Environment environment;

@Bean
DataSource dataSource() {
return createDataSource();
DataSource dataSource = createDataSource();
verifyConnection(dataSource);
return dataSource;
}

@Bean
Expand Down Expand Up @@ -76,4 +90,21 @@ DataSourceInitializer initializer() {
* @param populator will never be {@literal null}.
*/
protected void customizePopulator(ResourceDatabasePopulator populator) {}

private void verifyConnection(DataSource dataSource) {

Awaitility.await() //
.atMost(5L, TimeUnit.MINUTES) //
.pollInterval(fibonacci(TimeUnit.SECONDS)) //
.ignoreExceptions() //
.until(() -> {

LOG.debug("connectivity verifying ...");
try (Connection connection = dataSource.getConnection()) {
return true;
}
});

LOG.info("connectivity verified");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

import org.testcontainers.containers.Db2Container;

import static org.awaitility.pollinterval.FibonacciPollInterval.*;

/**
* {@link DataSource} setup for DB2.
*
Expand Down Expand Up @@ -66,18 +68,6 @@ protected DataSource createDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(DB_2_CONTAINER.getJdbcUrl(),
DB_2_CONTAINER.getUsername(), DB_2_CONTAINER.getPassword());

// DB2 container says its ready but it's like with a cat that denies service and still wants food although it had
// its food. Therefore, we make sure that we can properly establish a connection instead of trusting the cat
// ...err... DB2.
Awaitility.await().ignoreException(SQLException.class).until(() -> {

try (Connection connection = dataSource.getConnection()) {
return true;
}
});

LOG.info("DB2 connectivity verified");

return dataSource;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,14 @@
*/
package org.springframework.data.jdbc.testing;

import static org.awaitility.pollinterval.FibonacciPollInterval.*;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.concurrent.TimeUnit;

import javax.sql.DataSource;

import org.awaitility.Awaitility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;

import org.testcontainers.containers.OracleContainer;

/**
Expand Down Expand Up @@ -61,8 +52,10 @@ protected DataSource createDataSource() {

if (ORACLE_CONTAINER == null) {

LOG.info("Oracle starting...");
OracleContainer container = new OracleContainer("springci/spring-data-oracle-xe-prebuild:18.4.0").withReuse(true);
container.start();
LOG.info("Oracle started");

ORACLE_CONTAINER = container;
}
Expand All @@ -72,17 +65,6 @@ protected DataSource createDataSource() {
DataSource dataSource = new DriverManagerDataSource(jdbcUrl, ORACLE_CONTAINER.getUsername(),
ORACLE_CONTAINER.getPassword());

// Oracle container says its ready but it's like with a cat that denies service and still wants food although it had
// its food. Therefore, we make sure that we can properly establish a connection instead of trusting the cat
// ...err... Oracle.
Awaitility.await().atMost(5L, TimeUnit.MINUTES).pollInterval(fibonacci(TimeUnit.SECONDS))
.ignoreException(SQLException.class).until(() -> {

try (Connection connection = dataSource.getConnection()) {
return true;
}
});

return dataSource;
}

Expand Down
4 changes: 2 additions & 2 deletions spring-data-relational/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-relational</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-DATAJDBC-573-SNAPSHOT</version>

<name>Spring Data Relational</name>
<description>Spring Data Relational support</description>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-DATAJDBC-573-SNAPSHOT</version>
</parent>

<properties>
Expand Down