From 4eceed39353a238fc165ec5d2fe871e000deeaff Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Tue, 7 Nov 2023 13:37:29 -0600 Subject: [PATCH 1/3] Add support for running Oracle locally on Apple ARM64 * Adds `local-dev-oracle` Maven profile that can be used to build a server jar that includes the Oracle database driver for local testing only. * Introduces SystemStubsExtension for setting testcontainers required env vars when running tests on Mac M * Decorates the OracleSmokeTest with the above which serves as an example of how to conditionally run an Oracle testcontainers test on Mac M. * In tandem, a new page was added to thw Wiki https://github.com/spring-cloud/spring-cloud-dataflow/wiki/Oracle-on-Mac-ARM64 Resolves #5539 --- README.md | 15 +++++++- spring-cloud-dataflow-server/pom.xml | 18 +++++++++- .../server/db/migration/OracleSmokeTest.java | 36 ++++++++++++++++--- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1c01470fd5..c3ec3566d0 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ stream or task and managing its lifecycle. Clone the repo and type - $ ./mvnw -s settings.xml clean install + $ ./mvnw -s .settings.xml clean install Looking for more information? Follow this [link](https://github.com/spring-cloud/spring-cloud-dataflow/blob/master/spring-cloud-dataflow-docs/src/main/asciidoc/appendix-building.adoc). @@ -87,6 +87,19 @@ For more information please refer to the [Git documentation, Formatting and Whit ---- +## Running Locally w/ Oracle +By default, the Dataflow server jar does not include the Oracle database driver dependency. +If you want to use Oracle for development/testing when running locally, you can specify the `local-dev-oracle` Maven profile when building. +The following command will include the Oracle driver dependency in the jar: +``` +$ ./mvnw -s .settings.xml clean package -Plocal-dev-oracle +``` +You can follow the steps in the [Oracle on Mac ARM64](https://github.com/spring-cloud/spring-cloud-dataflow/wiki/Oracle-on-Mac-ARM64#run-container-in-docker) Wiki to run Oracle XE locally in Docker with Dataflow pointing at it. + +> **NOTE:** If you are not running Mac ARM64 just skip the steps related to Homebrew and Colima + +---- + ## Contributing We welcome contributions! See the [CONTRIBUTING](./CONTRIBUTING.adoc) guide for details. diff --git a/spring-cloud-dataflow-server/pom.xml b/spring-cloud-dataflow-server/pom.xml index 969df342e9..3512f2268c 100644 --- a/spring-cloud-dataflow-server/pom.xml +++ b/spring-cloud-dataflow-server/pom.xml @@ -18,6 +18,7 @@ UTF-8 UTF-8 1.8 + 21.9.0.0 3.4.1 3.3.0 ../src/checkstyle/checkstyle.xml @@ -127,6 +128,11 @@ assertj-core test + + uk.org.webcompere + system-stubs-jupiter + 2.1.3 + org.testcontainers junit-jupiter @@ -179,7 +185,7 @@ com.oracle.database.jdbc ojdbc8 - 21.9.0.0 + ${oracle-driver-ojdbc8.version} test @@ -409,5 +415,15 @@ + + local-dev-oracle + + + com.oracle.database.jdbc + ojdbc8 + ${oracle-driver-ojdbc8.version} + + + diff --git a/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/OracleSmokeTest.java b/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/OracleSmokeTest.java index e958e66dd5..9b9acbb1f3 100644 --- a/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/OracleSmokeTest.java +++ b/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/OracleSmokeTest.java @@ -15,22 +15,50 @@ */ package org.springframework.cloud.dataflow.server.db.migration; +import java.util.Locale; + import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.extension.ExtendWith; import org.testcontainers.containers.OracleContainer; +import org.testcontainers.utility.DockerImageName; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; -import org.springframework.test.context.DynamicPropertyRegistry; -import org.springframework.test.context.DynamicPropertySource; - +import org.springframework.core.log.LogAccessor; /** * Basic database schema and JPA tests for Oracle XE. * * @author Corneil du Plessis + * @author Chris Bono */ +@ExtendWith(SystemStubsExtension.class) public class OracleSmokeTest extends AbstractSmokeTest { + + private static final LogAccessor LOG = new LogAccessor(OracleSmokeTest.class); + + private static final String WIKI_LINK = "https://github.com/spring-cloud/spring-cloud-dataflow/wiki/Oracle-on-Mac-ARM64"; + + @SystemStub + private static EnvironmentVariables ENV_VARS; + @BeforeAll static void startContainer() { - container = new OracleContainer(); + if (runningOnMacArm64()) { + LOG.warn(() -> "You are running on Mac ARM64. If this test fails, make sure Colima is running prior " + + "to test invocation. See " + WIKI_LINK + " for details"); + ENV_VARS.set("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE", "/var/run/docker.sock"); + ENV_VARS.set("DOCKER_HOST", String.format("unix://%s/.colima/docker.sock", System.getProperty("user.home"))); + } + container = new OracleContainer(DockerImageName.parse("gvenzl/oracle-xe") + .withTag("18-slim-faststart")); container.start(); } + + private static boolean runningOnMacArm64() { + String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); + String osArchitecture = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH); + return osName.contains("mac") && osArchitecture.equals("aarch64"); + } } From 361e5897f5b574d9b9ad4227b9a45f6fc944debb Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Tue, 7 Nov 2023 14:39:00 -0600 Subject: [PATCH 2/3] Factor out the OracleContainerSupport to test module --- spring-cloud-dataflow-server/pom.xml | 18 +++--- .../server/db/migration/OracleSmokeTest.java | 36 +---------- spring-cloud-dataflow-test/pom.xml | 15 +++++ .../db/oracle/OracleContainerSupport.java | 62 +++++++++++++++++++ .../spring-cloud-skipper-server/pom.xml | 7 +++ .../db/migration/OracleSkipperSmokeTest.java | 11 ++-- 6 files changed, 100 insertions(+), 49 deletions(-) create mode 100644 spring-cloud-dataflow-test/src/main/java/org/springframework/cloud/dataflow/server/db/oracle/OracleContainerSupport.java diff --git a/spring-cloud-dataflow-server/pom.xml b/spring-cloud-dataflow-server/pom.xml index 3512f2268c..0d7ae69a33 100644 --- a/spring-cloud-dataflow-server/pom.xml +++ b/spring-cloud-dataflow-server/pom.xml @@ -90,6 +90,13 @@ h2 2.2.222 + + + org.springframework.cloud + spring-cloud-dataflow-test + ${project.version} + test + org.springframework.boot spring-boot-starter-test @@ -117,7 +124,6 @@ json-unit-assertj test - org.awaitility awaitility @@ -128,11 +134,6 @@ assertj-core test - - uk.org.webcompere - system-stubs-jupiter - 2.1.3 - org.testcontainers junit-jupiter @@ -173,29 +174,24 @@ junit test - com.ibm.db2 jcc 11.5.8.0 test - - com.oracle.database.jdbc ojdbc8 ${oracle-driver-ojdbc8.version} test - mysql mysql-connector-java 8.0.33 test - org.junit.jupiter junit-jupiter-api diff --git a/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/OracleSmokeTest.java b/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/OracleSmokeTest.java index 9b9acbb1f3..3005662951 100644 --- a/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/OracleSmokeTest.java +++ b/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/migration/OracleSmokeTest.java @@ -15,17 +15,9 @@ */ package org.springframework.cloud.dataflow.server.db.migration; -import java.util.Locale; - import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.extension.ExtendWith; -import org.testcontainers.containers.OracleContainer; -import org.testcontainers.utility.DockerImageName; -import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; -import uk.org.webcompere.systemstubs.jupiter.SystemStub; -import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; -import org.springframework.core.log.LogAccessor; +import org.springframework.cloud.dataflow.server.db.oracle.OracleContainerSupport; /** * Basic database schema and JPA tests for Oracle XE. @@ -33,32 +25,10 @@ * @author Corneil du Plessis * @author Chris Bono */ -@ExtendWith(SystemStubsExtension.class) -public class OracleSmokeTest extends AbstractSmokeTest { - - private static final LogAccessor LOG = new LogAccessor(OracleSmokeTest.class); - - private static final String WIKI_LINK = "https://github.com/spring-cloud/spring-cloud-dataflow/wiki/Oracle-on-Mac-ARM64"; - - @SystemStub - private static EnvironmentVariables ENV_VARS; +public class OracleSmokeTest extends AbstractSmokeTest implements OracleContainerSupport { @BeforeAll static void startContainer() { - if (runningOnMacArm64()) { - LOG.warn(() -> "You are running on Mac ARM64. If this test fails, make sure Colima is running prior " + - "to test invocation. See " + WIKI_LINK + " for details"); - ENV_VARS.set("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE", "/var/run/docker.sock"); - ENV_VARS.set("DOCKER_HOST", String.format("unix://%s/.colima/docker.sock", System.getProperty("user.home"))); - } - container = new OracleContainer(DockerImageName.parse("gvenzl/oracle-xe") - .withTag("18-slim-faststart")); - container.start(); - } - - private static boolean runningOnMacArm64() { - String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); - String osArchitecture = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH); - return osName.contains("mac") && osArchitecture.equals("aarch64"); + container = OracleContainerSupport.startContainer(); } } diff --git a/spring-cloud-dataflow-test/pom.xml b/spring-cloud-dataflow-test/pom.xml index d35d3b2e1a..71acc98524 100644 --- a/spring-cloud-dataflow-test/pom.xml +++ b/spring-cloud-dataflow-test/pom.xml @@ -15,17 +15,32 @@ true 3.4.1 + org.springframework.cloud spring-cloud-dataflow-core-dsl ${project.version} + + uk.org.webcompere + system-stubs-jupiter + 2.1.3 + + + org.testcontainers + junit-jupiter + + + org.testcontainers + oracle-xe + org.springframework.boot spring-boot-starter-test + diff --git a/spring-cloud-dataflow-test/src/main/java/org/springframework/cloud/dataflow/server/db/oracle/OracleContainerSupport.java b/spring-cloud-dataflow-test/src/main/java/org/springframework/cloud/dataflow/server/db/oracle/OracleContainerSupport.java new file mode 100644 index 0000000000..e912499278 --- /dev/null +++ b/spring-cloud-dataflow-test/src/main/java/org/springframework/cloud/dataflow/server/db/oracle/OracleContainerSupport.java @@ -0,0 +1,62 @@ +/* + * Copyright 2023-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cloud.dataflow.server.db.oracle; + +import java.util.Locale; + +import org.junit.jupiter.api.extension.ExtendWith; +import org.testcontainers.containers.OracleContainer; +import org.testcontainers.utility.DockerImageName; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; + +import org.springframework.core.log.LogAccessor; + +/** + * Provides support for testing against an {@link OracleContainer Oracle testcontainer}. + * + * @author Corneil du Plessis + * @author Chris Bono + */ +@ExtendWith(SystemStubsExtension.class) +public interface OracleContainerSupport { + + LogAccessor LOG = new LogAccessor(OracleContainerSupport.class); + + @SystemStub + EnvironmentVariables ENV_VARS = new EnvironmentVariables(); + + static OracleContainer startContainer() { + if (runningOnMacArm64()) { + String wiki = "https://github.com/spring-cloud/spring-cloud-dataflow/wiki/Oracle-on-Mac-ARM64"; + LOG.warn(() -> "You are running on Mac ARM64. If this test fails, make sure Colima is running prior " + + "to test invocation. See " + wiki + " for details"); + ENV_VARS.set("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE", "/var/run/docker.sock"); + ENV_VARS.set("DOCKER_HOST", String.format("unix://%s/.colima/docker.sock", System.getProperty("user.home"))); + } + OracleContainer oracleContainer = new OracleContainer(DockerImageName.parse("gvenzl/oracle-xe") + .withTag("18-slim-faststart")); + oracleContainer.start(); + return oracleContainer; + } + + static boolean runningOnMacArm64() { + String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); + String osArchitecture = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH); + return osName.contains("mac") && osArchitecture.equals("aarch64"); + } +} diff --git a/spring-cloud-skipper/spring-cloud-skipper-server/pom.xml b/spring-cloud-skipper/spring-cloud-skipper-server/pom.xml index c33a69f554..4df728943b 100644 --- a/spring-cloud-skipper/spring-cloud-skipper-server/pom.xml +++ b/spring-cloud-skipper/spring-cloud-skipper-server/pom.xml @@ -104,6 +104,13 @@ org.mariadb.jdbc mariadb-java-client + + + org.springframework.cloud + spring-cloud-dataflow-test + ${project.version} + test + org.springframework.boot spring-boot-starter-test diff --git a/spring-cloud-skipper/spring-cloud-skipper-server/src/test/java/org/springframework/cloud/skipper/server/db/migration/OracleSkipperSmokeTest.java b/spring-cloud-skipper/spring-cloud-skipper-server/src/test/java/org/springframework/cloud/skipper/server/db/migration/OracleSkipperSmokeTest.java index 95efb5bf07..c8c31a7d46 100644 --- a/spring-cloud-skipper/spring-cloud-skipper-server/src/test/java/org/springframework/cloud/skipper/server/db/migration/OracleSkipperSmokeTest.java +++ b/spring-cloud-skipper/spring-cloud-skipper-server/src/test/java/org/springframework/cloud/skipper/server/db/migration/OracleSkipperSmokeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,18 +16,19 @@ package org.springframework.cloud.skipper.server.db.migration; import org.junit.jupiter.api.BeforeAll; -import org.testcontainers.containers.OracleContainer; +import org.springframework.cloud.dataflow.server.db.oracle.OracleContainerSupport; /** * Basic database schema and JPA tests for Oracle XE. * * @author Corneil du Plessis + * @author Chris Bono */ -public class OracleSkipperSmokeTest extends AbstractSkipperSmokeTest { +public class OracleSkipperSmokeTest extends AbstractSkipperSmokeTest implements OracleContainerSupport { + @BeforeAll static void startContainer() { - container = new OracleContainer(); - container.start(); + container = OracleContainerSupport.startContainer(); } } From 07593b6f567c22a7f9fc234365c1f5d15300dddb Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Tue, 7 Nov 2023 14:47:50 -0600 Subject: [PATCH 3/3] Downgrade to SystemStubs 1.x for JDK 8 support --- spring-cloud-dataflow-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-dataflow-test/pom.xml b/spring-cloud-dataflow-test/pom.xml index 71acc98524..09f69802cb 100644 --- a/spring-cloud-dataflow-test/pom.xml +++ b/spring-cloud-dataflow-test/pom.xml @@ -25,7 +25,7 @@ uk.org.webcompere system-stubs-jupiter - 2.1.3 + 1.2.0 org.testcontainers