diff --git a/eventuate-common-flyway/build.gradle b/eventuate-common-flyway/build.gradle new file mode 100644 index 00000000..5b8f64e3 --- /dev/null +++ b/eventuate-common-flyway/build.gradle @@ -0,0 +1,9 @@ +dependencies { + testImplementation "org.springframework.boot:spring-boot-starter-test:$springBootVersion" + testImplementation "org.flywaydb:flyway-core:$flywayVersion" + testImplementation "org.flywaydb:flyway-mysql:$flywayVersion" + testImplementation project(":eventuate-common-spring-jdbc") + testImplementation project(":eventuate-common-testcontainers") + testImplementation "org.testcontainers:testcontainers:$testContainersVersion" + +} \ No newline at end of file diff --git a/eventuate-common-flyway/src/test/java/io/eventuate/common/flyway/FlywayTest.java b/eventuate-common-flyway/src/test/java/io/eventuate/common/flyway/FlywayTest.java new file mode 100644 index 00000000..1307e8d8 --- /dev/null +++ b/eventuate-common-flyway/src/test/java/io/eventuate/common/flyway/FlywayTest.java @@ -0,0 +1,41 @@ +package io.eventuate.common.flyway; + +import io.eventuate.common.spring.jdbc.EventuateCommonJdbcOperationsConfiguration; +import io.eventuate.common.testcontainers.DatabaseContainerFactory; +import io.eventuate.common.testcontainers.EventuateDatabaseContainer; +import io.eventuate.common.testcontainers.PropertyProvidingContainer; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@SpringBootTest(classes = FlywayTest.Config.class) +@RunWith(SpringJUnit4ClassRunner.class) +@TestPropertySource(properties="spring.flyway.locations=classpath:flyway/{vendor}") +public class FlywayTest { + + public static EventuateDatabaseContainer database = DatabaseContainerFactory.makeVanillaDatabaseContainerFromDockerFile(); + + @DynamicPropertySource + static void registerMySqlProperties(DynamicPropertyRegistry registry) { + PropertyProvidingContainer.startAndProvideProperties(registry, database); + } + + + @Configuration + @EnableAutoConfiguration + @Import(EventuateCommonJdbcOperationsConfiguration.class) + public static class Config { + } + + @Test + public void shouldInitializationDatabase() { + + } +} diff --git a/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/AbstractEventuateMySqlContainer.java b/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/AbstractEventuateMySqlContainer.java index 1a6f857b..fe2e18b6 100644 --- a/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/AbstractEventuateMySqlContainer.java +++ b/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/AbstractEventuateMySqlContainer.java @@ -35,6 +35,7 @@ public void registerProperties(BiConsumer> registry) { registry.accept("spring.datasource.url", this::getLocalJdbcUrl); registry.accept("spring.datasource.username", () -> "mysqluser"); registry.accept("spring.datasource.password", () -> "mysqlpw"); + registry.accept("spring.datasource.driver-class-name", () -> "com.mysql.cj.jdbc.Driver"); } @Override diff --git a/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/AbstractEventuatePostgresContainer.java b/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/AbstractEventuatePostgresContainer.java index 7d9b4911..766cf7c1 100644 --- a/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/AbstractEventuatePostgresContainer.java +++ b/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/AbstractEventuatePostgresContainer.java @@ -34,6 +34,8 @@ public void registerProperties(BiConsumer> registry) { registry.accept("spring.datasource.url", this::getLocalJdbcUrl); registry.accept("spring.datasource.username", () -> "postgresuser"); registry.accept("spring.datasource.password", () -> "postgrespw"); + registry.accept("spring.datasource.driver-class-name", () -> "org.postgresql.Driver"); + } @Override diff --git a/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/EventuateZookeeperContainer.java b/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/EventuateZookeeperContainer.java index aacd3d8d..83d3e4df 100644 --- a/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/EventuateZookeeperContainer.java +++ b/eventuate-common-testcontainers/src/main/java/io/eventuate/common/testcontainers/EventuateZookeeperContainer.java @@ -1,5 +1,6 @@ package io.eventuate.common.testcontainers; +import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.images.builder.ImageFromDockerfile; import java.nio.file.Path; @@ -20,6 +21,7 @@ public EventuateZookeeperContainer(Path path) { private void withConfiguration() { withExposedPorts(2181); + waitingFor(Wait.forHealthcheck()); } @Override diff --git a/eventuate-common-testcontainers/src/test/java/io/eventuate/common/testcontainers/EventuateZookeeperContainerTest.java b/eventuate-common-testcontainers/src/test/java/io/eventuate/common/testcontainers/EventuateZookeeperContainerTest.java new file mode 100644 index 00000000..f7bb087b --- /dev/null +++ b/eventuate-common-testcontainers/src/test/java/io/eventuate/common/testcontainers/EventuateZookeeperContainerTest.java @@ -0,0 +1,18 @@ +package io.eventuate.common.testcontainers; + +import org.junit.ClassRule; +import org.junit.Test; + +import java.nio.file.FileSystems; + +public class EventuateZookeeperContainerTest { + + @ClassRule + public static EventuateZookeeperContainer container = new EventuateZookeeperContainer(FileSystems.getDefault().getPath("../zookeeper/Dockerfile")); + + @Test + public void shouldStart() { + } + + +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index b4906b0b..ce694d75 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,6 +20,7 @@ springDataR2dbcVersion=1.3.0 assertjVersion=3.23.1 testContainersVersion=1.17.3 jacksonVersion=2.13.4 +flywayVersion=8.5.13 removeContainers=false diff --git a/mysql/Dockerfile-vanilla-mysql8 b/mysql/Dockerfile-vanilla-mysql8 index 784a89d9..a993525a 100644 --- a/mysql/Dockerfile-vanilla-mysql8 +++ b/mysql/Dockerfile-vanilla-mysql8 @@ -6,3 +6,5 @@ COPY 0.configure-root-user.sh /docker-entrypoint-initdb.d RUN touch /docker-entrypoint-initdb.d/6.configure-users.sql RUN chown mysql -R /docker-entrypoint-initdb.d + +HEALTHCHECK --interval=2s --retries=30 CMD /healthcheck.sh diff --git a/zookeeper/Dockerfile b/zookeeper/Dockerfile index 8a74e5f9..65a799ee 100644 --- a/zookeeper/Dockerfile +++ b/zookeeper/Dockerfile @@ -17,4 +17,4 @@ VOLUME ["/usr/local/apache-zookeeper-3.5.6-bin/conf", "/usr/local/zookeeper-data COPY run-zk.sh . ENTRYPOINT ["./run-zk.sh"] CMD ["start-foreground"] -HEALTHCHECK --start-period=20s --interval=15s CMD (echo ruok | nc localhost 2181) || exit 1 +HEALTHCHECK --interval=3s --retries=30 CMD (echo ruok | nc localhost 2181) || exit 1