From 60bc16d0ca877c945eac50aaa5df0d27660f4216 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Dec 2023 02:02:02 +0000 Subject: [PATCH 1/9] Bump actions/upload-artifact from 3 to 4 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index acad5611..17d26f74 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -38,7 +38,7 @@ jobs: - name: Build and test with Maven run: $MVN_CMD install - name: upload test results - uses: actions/upload-artifact@v3 # upload test results + uses: actions/upload-artifact@v4 # upload test results if: success() || failure() # run this step even if previous step failed with: name: test-results From 32847284695de9565fe3313588c7610d80ddd33a Mon Sep 17 00:00:00 2001 From: Andreas Keefer Date: Sat, 11 May 2024 14:46:48 +0200 Subject: [PATCH 2/9] prepare next release --- README.md | 4 ++++ elasticsearch-evolution-core/pom.xml | 2 +- pom.xml | 2 +- spring-boot-starter-elasticsearch-evolution/pom.xml | 2 +- tests/migration-scripts/pom.xml | 2 +- tests/pom.xml | 2 +- tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-2.2/pom.xml | 2 +- tests/test-spring-boot-2.3/pom.xml | 2 +- tests/test-spring-boot-2.4/pom.xml | 2 +- tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-2.6/pom.xml | 2 +- tests/test-spring-boot-2.7/pom.xml | 2 +- tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-3.1/pom.xml | 2 +- tests/test-spring-boot-3.2/pom.xml | 2 +- 16 files changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3f12c9bd..62d21c90 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,10 @@ ElasticsearchEvolution.configure() ## 6 changelog +### v0.5.3-SNAPSHOT + +- ... + ### v0.5.2 - bugfix ([#293](https://github.com/senacor/elasticsearch-evolution/issues/293)): trailing newlines will no longer be removed from migration scripts. diff --git a/elasticsearch-evolution-core/pom.xml b/elasticsearch-evolution-core/pom.xml index 6b844ac7..7ab9db5a 100644 --- a/elasticsearch-evolution-core/pom.xml +++ b/elasticsearch-evolution-core/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.2 + 0.5.3-SNAPSHOT ../ elasticsearch-evolution-core diff --git a/pom.xml b/pom.xml index 76814b9c..78c020f6 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.2 + 0.5.3-SNAPSHOT pom org.springframework.boot diff --git a/spring-boot-starter-elasticsearch-evolution/pom.xml b/spring-boot-starter-elasticsearch-evolution/pom.xml index 3c9164ef..b327fa96 100644 --- a/spring-boot-starter-elasticsearch-evolution/pom.xml +++ b/spring-boot-starter-elasticsearch-evolution/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.2 + 0.5.3-SNAPSHOT ../ spring-boot-starter-elasticsearch-evolution diff --git a/tests/migration-scripts/pom.xml b/tests/migration-scripts/pom.xml index 4da39f50..5e6b946f 100644 --- a/tests/migration-scripts/pom.xml +++ b/tests/migration-scripts/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.senacor.elasticsearch.evolution migration-scripts - 0.5.2 + 0.5.3-SNAPSHOT jar containing migration files jar diff --git a/tests/pom.xml b/tests/pom.xml index 3aa7f426..843a081f 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.2 + 0.5.3-SNAPSHOT ../ tests diff --git a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml index d69246c3..80b19b25 100644 --- a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.1-scriptsInJarFile - 0.5.2 + 0.5.3-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.2/pom.xml b/tests/test-spring-boot-2.2/pom.xml index 617ad88e..1067010e 100644 --- a/tests/test-spring-boot-2.2/pom.xml +++ b/tests/test-spring-boot-2.2/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.2 - 0.5.2 + 0.5.3-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.3/pom.xml b/tests/test-spring-boot-2.3/pom.xml index 7a4eb7ab..9508791b 100644 --- a/tests/test-spring-boot-2.3/pom.xml +++ b/tests/test-spring-boot-2.3/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.3 - 0.5.2 + 0.5.3-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.4/pom.xml b/tests/test-spring-boot-2.4/pom.xml index f1133ef4..b320ab62 100644 --- a/tests/test-spring-boot-2.4/pom.xml +++ b/tests/test-spring-boot-2.4/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.4 - 0.5.2 + 0.5.3-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml index 23cb14c3..892a280c 100644 --- a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.5-scriptsInJarFile - 0.5.2 + 0.5.3-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.6/pom.xml b/tests/test-spring-boot-2.6/pom.xml index bd936899..2206f03f 100644 --- a/tests/test-spring-boot-2.6/pom.xml +++ b/tests/test-spring-boot-2.6/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.6 - 0.5.2 + 0.5.3-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-2.7/pom.xml b/tests/test-spring-boot-2.7/pom.xml index 196948b8..4405022e 100644 --- a/tests/test-spring-boot-2.7/pom.xml +++ b/tests/test-spring-boot-2.7/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-2.7 - 0.5.2 + 0.5.3-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml index 480c949b..7801e1bf 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.0-scriptsInJarFile - 0.5.2 + 0.5.3-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.1/pom.xml b/tests/test-spring-boot-3.1/pom.xml index e54f064b..ea2b24ac 100644 --- a/tests/test-spring-boot-3.1/pom.xml +++ b/tests/test-spring-boot-3.1/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.1 - 0.5.2 + 0.5.3-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.2/pom.xml b/tests/test-spring-boot-3.2/pom.xml index a739046a..ff5327ef 100644 --- a/tests/test-spring-boot-3.2/pom.xml +++ b/tests/test-spring-boot-3.2/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.2 - 0.5.2 + 0.5.3-SNAPSHOT Demo project for Spring Boot From fa66f87b4b4c6f2784d6bd256d9e2029b6db648b Mon Sep 17 00:00:00 2001 From: Andreas Keefer Date: Sat, 11 May 2024 15:29:37 +0200 Subject: [PATCH 3/9] - The minimum supported Java version is now 17. - Drop spring boot 2 compatibility. Further version may run on spring boot 2, but it is not tested anymore. --- .github/workflows/maven-matrix.yml | 10 +- .github/workflows/quality.yml | 4 +- README.md | 18 +-- elasticsearch-evolution-core/pom.xml | 7 +- .../test/EmbeddedElasticsearchExtension.java | 9 +- pom.xml | 6 +- .../pom.xml | 2 +- tests/migration-scripts/pom.xml | 2 +- tests/pom.xml | 27 +---- .../pom.xml | 114 ------------------ .../evolution/springboot21/Application.java | 13 -- .../src/main/resources/application.properties | 3 - .../springboot21/ApplicationTests.java | 69 ----------- .../evolution/springboot21/EsUtils.java | 72 ----------- tests/test-spring-boot-2.2/pom.xml | 106 ---------------- .../evolution/springboot22/Application.java | 14 --- ...01.00__createTemplateWithIndexMapping.http | 35 ------ .../es/migration/V001.01__addDocument.http | 17 --- .../springboot22/ApplicationTests.java | 66 ---------- .../evolution/springboot22/EsUtils.java | 72 ----------- tests/test-spring-boot-2.3/pom.xml | 107 ---------------- .../evolution/springboot23/Application.java | 14 --- ...01.00__createTemplateWithIndexMapping.http | 35 ------ .../es/migration/V001.01__addDocument.http | 17 --- .../springboot23/ApplicationTests.java | 66 ---------- .../evolution/springboot23/EsUtils.java | 72 ----------- tests/test-spring-boot-2.4/pom.xml | 107 ---------------- .../evolution/springboot24/Application.java | 14 --- ...01.00__createTemplateWithIndexMapping.http | 35 ------ .../es/migration/V001.01__addDocument.http | 17 --- .../springboot24/ApplicationTests.java | 66 ---------- .../evolution/springboot24/EsUtils.java | 72 ----------- .../pom.xml | 114 ------------------ .../evolution/springboot25/Application.java | 13 -- .../src/main/resources/application.properties | 3 - .../springboot25/ApplicationTest.java | 66 ---------- .../evolution/springboot25/EsUtils.java | 72 ----------- tests/test-spring-boot-2.6/pom.xml | 107 ---------------- .../evolution/springboot26/Application.java | 14 --- ...01.00__createTemplateWithIndexMapping.http | 35 ------ .../es/migration/V001.01__addDocument.http | 17 --- .../springboot26/ApplicationTests.java | 66 ---------- .../evolution/springboot26/EsUtils.java | 72 ----------- tests/test-spring-boot-2.7/pom.xml | 107 ---------------- .../evolution/springboot27/Application.java | 14 --- ...01.00__createTemplateWithIndexMapping.http | 35 ------ .../es/migration/V001.01__addDocument.http | 17 --- .../springboot27/ApplicationTests.java | 66 ---------- .../evolution/springboot27/EsUtils.java | 72 ----------- .../pom.xml | 2 +- tests/test-spring-boot-3.1/pom.xml | 2 +- tests/test-spring-boot-3.2/pom.xml | 2 +- 52 files changed, 34 insertions(+), 2150 deletions(-) delete mode 100644 tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml delete mode 100644 tests/test-spring-boot-2.1-scriptsInJarFile/src/main/java/com/senacor/elasticsearch/evolution/springboot21/Application.java delete mode 100644 tests/test-spring-boot-2.1-scriptsInJarFile/src/main/resources/application.properties delete mode 100644 tests/test-spring-boot-2.1-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot21/ApplicationTests.java delete mode 100644 tests/test-spring-boot-2.1-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot21/EsUtils.java delete mode 100644 tests/test-spring-boot-2.2/pom.xml delete mode 100644 tests/test-spring-boot-2.2/src/main/java/com/senacor/elasticsearch/evolution/springboot22/Application.java delete mode 100644 tests/test-spring-boot-2.2/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http delete mode 100644 tests/test-spring-boot-2.2/src/main/resources/es/migration/V001.01__addDocument.http delete mode 100644 tests/test-spring-boot-2.2/src/test/java/com/senacor/elasticsearch/evolution/springboot22/ApplicationTests.java delete mode 100644 tests/test-spring-boot-2.2/src/test/java/com/senacor/elasticsearch/evolution/springboot22/EsUtils.java delete mode 100644 tests/test-spring-boot-2.3/pom.xml delete mode 100644 tests/test-spring-boot-2.3/src/main/java/com/senacor/elasticsearch/evolution/springboot23/Application.java delete mode 100644 tests/test-spring-boot-2.3/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http delete mode 100644 tests/test-spring-boot-2.3/src/main/resources/es/migration/V001.01__addDocument.http delete mode 100644 tests/test-spring-boot-2.3/src/test/java/com/senacor/elasticsearch/evolution/springboot23/ApplicationTests.java delete mode 100644 tests/test-spring-boot-2.3/src/test/java/com/senacor/elasticsearch/evolution/springboot23/EsUtils.java delete mode 100644 tests/test-spring-boot-2.4/pom.xml delete mode 100644 tests/test-spring-boot-2.4/src/main/java/com/senacor/elasticsearch/evolution/springboot24/Application.java delete mode 100644 tests/test-spring-boot-2.4/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http delete mode 100644 tests/test-spring-boot-2.4/src/main/resources/es/migration/V001.01__addDocument.http delete mode 100644 tests/test-spring-boot-2.4/src/test/java/com/senacor/elasticsearch/evolution/springboot24/ApplicationTests.java delete mode 100644 tests/test-spring-boot-2.4/src/test/java/com/senacor/elasticsearch/evolution/springboot24/EsUtils.java delete mode 100644 tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml delete mode 100644 tests/test-spring-boot-2.5-scriptsInJarFile/src/main/java/com/senacor/elasticsearch/evolution/springboot25/Application.java delete mode 100644 tests/test-spring-boot-2.5-scriptsInJarFile/src/main/resources/application.properties delete mode 100644 tests/test-spring-boot-2.5-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot25/ApplicationTest.java delete mode 100644 tests/test-spring-boot-2.5-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot25/EsUtils.java delete mode 100644 tests/test-spring-boot-2.6/pom.xml delete mode 100644 tests/test-spring-boot-2.6/src/main/java/com/senacor/elasticsearch/evolution/springboot26/Application.java delete mode 100644 tests/test-spring-boot-2.6/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http delete mode 100644 tests/test-spring-boot-2.6/src/main/resources/es/migration/V001.01__addDocument.http delete mode 100644 tests/test-spring-boot-2.6/src/test/java/com/senacor/elasticsearch/evolution/springboot26/ApplicationTests.java delete mode 100644 tests/test-spring-boot-2.6/src/test/java/com/senacor/elasticsearch/evolution/springboot26/EsUtils.java delete mode 100644 tests/test-spring-boot-2.7/pom.xml delete mode 100644 tests/test-spring-boot-2.7/src/main/java/com/senacor/elasticsearch/evolution/springboot27/Application.java delete mode 100644 tests/test-spring-boot-2.7/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http delete mode 100644 tests/test-spring-boot-2.7/src/main/resources/es/migration/V001.01__addDocument.http delete mode 100644 tests/test-spring-boot-2.7/src/test/java/com/senacor/elasticsearch/evolution/springboot27/ApplicationTests.java delete mode 100644 tests/test-spring-boot-2.7/src/test/java/com/senacor/elasticsearch/evolution/springboot27/EsUtils.java diff --git a/.github/workflows/maven-matrix.yml b/.github/workflows/maven-matrix.yml index 4555d9f3..9f68013d 100644 --- a/.github/workflows/maven-matrix.yml +++ b/.github/workflows/maven-matrix.yml @@ -23,7 +23,7 @@ jobs: build-with-jdk: strategy: matrix: - java: [ 8, 11, 17, 21 ] + java: [ 17, 21 ] fail-fast: false runs-on: ubuntu-22.04 steps: @@ -109,12 +109,12 @@ jobs: passphrase: ${{ secrets.GPG_PASSPHRASE }} git_user_signingkey: true git_commit_gpgsign: true - - name: Set up JDK 8 + - name: Set up JDK 17 # with JDK 11 the maven-javadoc-plugin > 3.0.1 fails with "cannot find symbol org.elasticsearch.*" uses: actions/setup-java@v4 with: distribution: zulu - java-version: 8 + java-version: 17 - name: Release to maven central env: GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} @@ -140,12 +140,12 @@ jobs: passphrase: ${{ secrets.GPG_PASSPHRASE }} git_user_signingkey: true git_commit_gpgsign: true - - name: Set up JDK 8 + - name: Set up JDK 17 # with JDK 11 the maven-javadoc-plugin > 3.0.1 fails with "cannot find symbol org.elasticsearch.*" uses: actions/setup-java@v4 with: distribution: zulu - java-version: 8 + java-version: 17 - name: Release to maven central env: GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index acad5611..0f5703bc 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -24,12 +24,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up JDK 8 + - name: Set up JDK 17 # build with JDK 8 because of issue https://github.com/trautonen/coveralls-maven-plugin/issues/112 uses: actions/setup-java@v4 with: distribution: zulu - java-version: 8 + java-version: 17 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v3 diff --git a/README.md b/README.md index 62d21c90..f4676b62 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ Successful executed migration scripts will not be executed again! ## 2 Features -- tested on Java 8, 11, 17, and 21 -- runs on Spring-Boot 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1 and 3.2 (and of course without Spring-Boot) +- tested on Java 17 and 21 +- runs on Spring-Boot 3.x (and of course without Spring-Boot) - runs on Elasticsearch version 7.5.x - 8.13.x - runs on Opensearch version 1.x and 2.x - highly configurable (e.g. location(s) of your migration files, migration files format pattern) @@ -33,6 +33,7 @@ Successful executed migration scripts will not be executed again! | Compatibility | Spring Boot | Elasticsearch | Opensearch | |----------------------------------|--------------------------------------------------|----------------------|------------| +| elasticsearch-evolution >= 0.6.0 | 3.x | 7.5.x - 8.13.x | 1.x - 2.x | | elasticsearch-evolution >= 0.4.2 | 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2 | 7.5.x - 8.13.x | 1.x - 2.x | | elasticsearch-evolution >= 0.4.0 | 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7 | 7.5.x - 8.6.x | 1.x - 2.x | | elasticsearch-evolution 0.3.x | 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7 | 7.5.x - 7.17.x | | @@ -219,14 +220,6 @@ spring.elasticsearch.username=my-user-name spring.elasticsearch.password=my-secret-pw ``` -##### 5.1.1.2 spring boot < 2.7 -NOTE: these config properties are deprecated since spring boot 2.6 and may be removed in 2.7! See spring-boot 2.6 [release notes](https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes#elasticsearch-property-consolidation). -```properties -spring.elasticsearch.rest.uris[0]=https://example.com:9200 -spring.elasticsearch.rest.username=my-user-name -spring.elasticsearch.rest.password=my-secret-pw -``` - #### 5.1.2 Customize Elasticsearch-Evolutions AutoConfiguration ##### 5.1.2.1 Custom RestClient @@ -286,9 +279,10 @@ ElasticsearchEvolution.configure() ## 6 changelog -### v0.5.3-SNAPSHOT +### v0.6.0-SNAPSHOT -- ... +- The minimum supported Java version is now 17. +- Drop spring boot 2 compatibility. Further versions may run on spring boot 2, but it is not tested anymore. ### v0.5.2 diff --git a/elasticsearch-evolution-core/pom.xml b/elasticsearch-evolution-core/pom.xml index 7ab9db5a..79d1c417 100644 --- a/elasticsearch-evolution-core/pom.xml +++ b/elasticsearch-evolution-core/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.3-SNAPSHOT + 0.6.0-SNAPSHOT ../ elasticsearch-evolution-core @@ -66,6 +66,11 @@ + + org.springframework + spring-test + test + ch.qos.logback logback-classic diff --git a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/test/EmbeddedElasticsearchExtension.java b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/test/EmbeddedElasticsearchExtension.java index ce5ab940..2e956cee 100644 --- a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/test/EmbeddedElasticsearchExtension.java +++ b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/test/EmbeddedElasticsearchExtension.java @@ -18,7 +18,7 @@ import org.junit.jupiter.params.provider.ArgumentsProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.util.SocketUtils; +import org.springframework.test.util.TestSocketUtils; import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; import org.testcontainers.elasticsearch.ElasticsearchContainer; import org.testcontainers.shaded.com.google.common.collect.ImmutableMap; @@ -84,11 +84,8 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) { .withEnv("cluster.routing.allocation.disk.watermark.low", "97%") .withEnv("cluster.routing.allocation.disk.watermark.high", "98%") .withEnv("cluster.routing.allocation.disk.watermark.flood_stage", "99%"); - // SocketUtils replacement: https://github.com/spring-projects/spring-framework/issues/28210 - // https://github.com/spring-cloud/spring-cloud-function/issues/825 - // https://github.com/spring-cloud/spring-cloud-deployer-local/pull/214 - int httpPort = SocketUtils.findAvailableTcpPort(5000, 30000); - int transportPort = SocketUtils.findAvailableTcpPort(30001, 65535); + int httpPort = TestSocketUtils.findAvailableTcpPort(); + int transportPort = TestSocketUtils.findAvailableTcpPort(); container.setPortBindings(Arrays.asList(httpPort + ":9200", transportPort + ":" + searchContainer.transportPort)); // container.setWaitStrategy(new HttpWaitStrategy() // .forPort(9200) diff --git a/pom.xml b/pom.xml index 78c020f6..0e4020d8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.3-SNAPSHOT + 0.6.0-SNAPSHOT pom org.springframework.boot spring-boot-dependencies - 2.7.18 + 3.2.5 elasticsearch-evolution @@ -87,7 +87,7 @@ UTF-8 UTF-8 - 1.8 + 17 ${java.version} ${java.version} diff --git a/spring-boot-starter-elasticsearch-evolution/pom.xml b/spring-boot-starter-elasticsearch-evolution/pom.xml index b327fa96..f6e75ddb 100644 --- a/spring-boot-starter-elasticsearch-evolution/pom.xml +++ b/spring-boot-starter-elasticsearch-evolution/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.3-SNAPSHOT + 0.6.0-SNAPSHOT ../ spring-boot-starter-elasticsearch-evolution diff --git a/tests/migration-scripts/pom.xml b/tests/migration-scripts/pom.xml index 5e6b946f..b8dbd535 100644 --- a/tests/migration-scripts/pom.xml +++ b/tests/migration-scripts/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.senacor.elasticsearch.evolution migration-scripts - 0.5.3-SNAPSHOT + 0.6.0-SNAPSHOT jar containing migration files jar diff --git a/tests/pom.xml b/tests/pom.xml index 843a081f..72fb6c17 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.5.3-SNAPSHOT + 0.6.0-SNAPSHOT ../ tests @@ -19,27 +19,8 @@ migration-scripts - test-spring-boot-2.7 - test-spring-boot-2.6 - test-spring-boot-2.5-scriptsInJarFile - test-spring-boot-2.4 - test-spring-boot-2.3 - test-spring-boot-2.2 - test-spring-boot-2.1-scriptsInJarFile + test-spring-boot-3.0-scriptsInJarFile + test-spring-boot-3.1 + test-spring-boot-3.2 - - - - jdk17+ - - - [17,) - - - test-spring-boot-3.0-scriptsInJarFile - test-spring-boot-3.1 - test-spring-boot-3.2 - - - diff --git a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml deleted file mode 100644 index 80b19b25..00000000 --- a/tests/test-spring-boot-2.1-scriptsInJarFile/pom.xml +++ /dev/null @@ -1,114 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.18.RELEASE - - - com.senacor.elasticsearch.evolution - test-spring-boot-2.1-scriptsInJarFile - 0.5.3-SNAPSHOT - Demo project for Spring Boot - - - 1.8 - - 2.16.1 - 7.5.2 - 1.19.8 - - - - - - ${project.groupId} - migration-scripts - ${project.version} - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - ${project.groupId} - spring-boot-starter-elasticsearch-evolution - ${project.version} - - - - - org.testcontainers - elasticsearch - ${testcontainers.elasticsearch.version} - test - - - commons-io - commons-io - ${commons-io.version} - test - - - - - - oss.sonatype.org-snapshot - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.jacoco - jacoco-maven-plugin - - 0.8.12 - - - prepare-agent - - prepare-agent - - - - report - post-integration-test - - report - - - - - - maven-surefire-plugin - - true - - - - - - diff --git a/tests/test-spring-boot-2.1-scriptsInJarFile/src/main/java/com/senacor/elasticsearch/evolution/springboot21/Application.java b/tests/test-spring-boot-2.1-scriptsInJarFile/src/main/java/com/senacor/elasticsearch/evolution/springboot21/Application.java deleted file mode 100644 index a4c1aa3b..00000000 --- a/tests/test-spring-boot-2.1-scriptsInJarFile/src/main/java/com/senacor/elasticsearch/evolution/springboot21/Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot21; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.1-scriptsInJarFile/src/main/resources/application.properties b/tests/test-spring-boot-2.1-scriptsInJarFile/src/main/resources/application.properties deleted file mode 100644 index 5db1f692..00000000 --- a/tests/test-spring-boot-2.1-scriptsInJarFile/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -spring.elasticsearch.evolution.locations[0]=classpath:es/mig -spring.elasticsearch.evolution.placeholders.index=test_1 -logging.level.com.senacor.elasticsearch.evolution=DEBUG \ No newline at end of file diff --git a/tests/test-spring-boot-2.1-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot21/ApplicationTests.java b/tests/test-spring-boot-2.1-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot21/ApplicationTests.java deleted file mode 100644 index 50f66bc8..00000000 --- a/tests/test-spring-boot-2.1-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot21/ApplicationTests.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot21; - -import com.github.dockerjava.api.command.InspectContainerResponse; -import org.apache.http.HttpHost; -import org.elasticsearch.client.RestClient; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.test.context.junit4.SpringRunner; -import org.testcontainers.elasticsearch.ElasticsearchContainer; -import org.testcontainers.utility.DockerImageName; - -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(properties = {"spring.elasticsearch.rest.uris=http://localhost:" + ApplicationTests.ELASTICSEARCH_PORT}) -public class ApplicationTests { - - static final int ELASTICSEARCH_PORT = 18769; - - @Autowired - private EsUtils esUtils; - - @Test - public void contextLoads() { - esUtils.refreshIndices(); - - List documents = esUtils.fetchAllDocuments("test_1"); - - assertThat(documents).hasSize(1); - } - - @TestConfiguration - static class Config { - @Bean(destroyMethod = "stop") - public ElasticsearchContainer elasticsearchContainer(@Value("${elasticsearch.version:7.5.2}") String esVersion) { - ElasticsearchContainer container = new ElasticsearchContainer(DockerImageName - .parse("docker.elastic.co/elasticsearch/elasticsearch") - .withTag(esVersion)) { - @Override - protected void containerIsStarted(InspectContainerResponse containerInfo) { - // since testcontainers 1.17 it detects if ES 8.x is running and copies a certificate in this case - // but we don't want security - } - } - .withEnv("ES_JAVA_OPTS", "-Xms128m -Xmx128m") - // since elasticsearch 8 security / https is enabled per default - but for testing it should be disabled - .withEnv("xpack.security.enabled", "false") - .withEnv("cluster.routing.allocation.disk.watermark.low", "97%") - .withEnv("cluster.routing.allocation.disk.watermark.high", "98%") - .withEnv("cluster.routing.allocation.disk.watermark.flood_stage", "99%"); - container.setPortBindings(Collections.singletonList(ELASTICSEARCH_PORT + ":9200")); - container.start(); - return container; - } - - @Bean - public EsUtils esUtils(ElasticsearchContainer elasticsearchContainer) { - return new EsUtils(RestClient.builder(HttpHost.create(elasticsearchContainer.getHttpHostAddress())).build()); - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.1-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot21/EsUtils.java b/tests/test-spring-boot-2.1-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot21/EsUtils.java deleted file mode 100644 index 49eae087..00000000 --- a/tests/test-spring-boot-2.1-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot21/EsUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot21; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.IOUtils; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestClient; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * @author Andreas Keefer - */ -public class EsUtils { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - private final RestClient restClient; - - public EsUtils(RestClient restClient) { - this.restClient = restClient; - } - - public void refreshIndices() { - try { - restClient.performRequest(new Request("GET", "/_refresh")); - } catch (IOException e) { - throw new IllegalStateException("refreshIndices failed", e); - } - } - - public List fetchAllDocuments(String index) { - try { - Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); - Response response = restClient.performRequest(post); - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode < 200 || statusCode >= 300) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed with HTTP status " + - statusCode + ": " + response.toString()); - } - String body = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); - - return parseDocuments(body) - .collect(Collectors.toList()); - } catch (IOException e) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed", e); - } - } - - private Stream parseDocuments(String body) { - try { - JsonNode jsonNode = OBJECT_MAPPER.readTree(body); - return StreamSupport.stream(jsonNode.get("hits").get("hits").spliterator(), false) - .map(hitNode -> hitNode.get("_source")) - .map(JsonNode::toString); - } catch (IOException e) { - throw new IllegalStateException("parseDocuments failed. body=" + body, e); - } - } -} - diff --git a/tests/test-spring-boot-2.2/pom.xml b/tests/test-spring-boot-2.2/pom.xml deleted file mode 100644 index 1067010e..00000000 --- a/tests/test-spring-boot-2.2/pom.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.13.RELEASE - - - com.senacor.elasticsearch.evolution - test-spring-boot-2.2 - 0.5.3-SNAPSHOT - Demo project for Spring Boot - - - 1.8 - - 2.16.1 - 7.5.2 - 1.19.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - ${project.groupId} - spring-boot-starter-elasticsearch-evolution - ${project.version} - - - - - org.testcontainers - elasticsearch - ${testcontainers.elasticsearch.version} - test - - - commons-io - commons-io - ${commons-io.version} - test - - - - - - oss.sonatype.org-snapshot - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.jacoco - jacoco-maven-plugin - 0.8.12 - - - prepare-agent - - prepare-agent - - - - report - post-integration-test - - report - - - - - - maven-surefire-plugin - - true - - - - - - diff --git a/tests/test-spring-boot-2.2/src/main/java/com/senacor/elasticsearch/evolution/springboot22/Application.java b/tests/test-spring-boot-2.2/src/main/java/com/senacor/elasticsearch/evolution/springboot22/Application.java deleted file mode 100644 index 114042fa..00000000 --- a/tests/test-spring-boot-2.2/src/main/java/com/senacor/elasticsearch/evolution/springboot22/Application.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot22; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.2/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http b/tests/test-spring-boot-2.2/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http deleted file mode 100644 index fbd7df47..00000000 --- a/tests/test-spring-boot-2.2/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http +++ /dev/null @@ -1,35 +0,0 @@ -PUT _template/test_1 -Content-Type: application/json - -{ - "index_patterns" : [ - "test_*" - ], - "order" : 1, - "version" : 1, - "settings" : { - "number_of_shards" : 1 - }, - "mappings" : { - "dynamic" : "strict", - "properties" : { - "doc" : { - "dynamic" : false, - "properties" : {} - }, - "searchable" : { - "dynamic" : false, - "properties" : { - "version" : { - "type" : "keyword", - "ignore_above" : 20, - "similarity" : "boolean" - }, - "locked" : { - "type" : "boolean" - } - } - } - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.2/src/main/resources/es/migration/V001.01__addDocument.http b/tests/test-spring-boot-2.2/src/main/resources/es/migration/V001.01__addDocument.http deleted file mode 100644 index 4f18ba0a..00000000 --- a/tests/test-spring-boot-2.2/src/main/resources/es/migration/V001.01__addDocument.http +++ /dev/null @@ -1,17 +0,0 @@ -PUT /test_1/_doc/1?refresh -Content-Type: application/json - -{ - "searchable": { - "version": "1", - "locked": false - }, - "doc": { - "version": "1", - "locked": false, - "success": true, - "a": "a a a", - "b": true, - "c": "c" - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.2/src/test/java/com/senacor/elasticsearch/evolution/springboot22/ApplicationTests.java b/tests/test-spring-boot-2.2/src/test/java/com/senacor/elasticsearch/evolution/springboot22/ApplicationTests.java deleted file mode 100644 index 2b48d2c7..00000000 --- a/tests/test-spring-boot-2.2/src/test/java/com/senacor/elasticsearch/evolution/springboot22/ApplicationTests.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot22; - -import com.github.dockerjava.api.command.InspectContainerResponse; -import org.apache.http.HttpHost; -import org.elasticsearch.client.RestClient; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.testcontainers.elasticsearch.ElasticsearchContainer; -import org.testcontainers.utility.DockerImageName; - -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(properties = {"spring.elasticsearch.rest.uris=http://localhost:" + ApplicationTests.ELASTICSEARCH_PORT}) -class ApplicationTests { - - static final int ELASTICSEARCH_PORT = 18759; - - @Autowired - private EsUtils esUtils; - - @Test - void contextLoads() { - esUtils.refreshIndices(); - - List documents = esUtils.fetchAllDocuments("test_1"); - - assertThat(documents).hasSize(1); - } - - @TestConfiguration - static class Config { - @Bean(destroyMethod = "stop") - public ElasticsearchContainer elasticsearchContainer(@Value("${elasticsearch.version:7.5.2}") String esVersion) { - ElasticsearchContainer container = new ElasticsearchContainer(DockerImageName - .parse("docker.elastic.co/elasticsearch/elasticsearch") - .withTag(esVersion)) { - @Override - protected void containerIsStarted(InspectContainerResponse containerInfo) { - // since testcontainers 1.17 it detects if ES 8.x is running and copies a certificate in this case - // but we don't want security - } - } - .withEnv("ES_JAVA_OPTS", "-Xms128m -Xmx128m") - // since elasticsearch 8 security / https is enabled per default - but for testing it should be disabled - .withEnv("xpack.security.enabled", "false") - .withEnv("cluster.routing.allocation.disk.watermark.low", "97%") - .withEnv("cluster.routing.allocation.disk.watermark.high", "98%") - .withEnv("cluster.routing.allocation.disk.watermark.flood_stage", "99%"); - container.setPortBindings(Collections.singletonList(ELASTICSEARCH_PORT + ":9200")); - container.start(); - return container; - } - - @Bean - public EsUtils esUtils(ElasticsearchContainer elasticsearchContainer) { - return new EsUtils(RestClient.builder(HttpHost.create(elasticsearchContainer.getHttpHostAddress())).build()); - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.2/src/test/java/com/senacor/elasticsearch/evolution/springboot22/EsUtils.java b/tests/test-spring-boot-2.2/src/test/java/com/senacor/elasticsearch/evolution/springboot22/EsUtils.java deleted file mode 100644 index b2350948..00000000 --- a/tests/test-spring-boot-2.2/src/test/java/com/senacor/elasticsearch/evolution/springboot22/EsUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot22; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.IOUtils; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestClient; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * @author Andreas Keefer - */ -public class EsUtils { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - private final RestClient restClient; - - public EsUtils(RestClient restClient) { - this.restClient = restClient; - } - - public void refreshIndices() { - try { - restClient.performRequest(new Request("GET", "/_refresh")); - } catch (IOException e) { - throw new IllegalStateException("refreshIndices failed", e); - } - } - - public List fetchAllDocuments(String index) { - try { - Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); - Response response = restClient.performRequest(post); - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode < 200 || statusCode >= 300) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed with HTTP status " + - statusCode + ": " + response.toString()); - } - String body = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); - - return parseDocuments(body) - .collect(Collectors.toList()); - } catch (IOException e) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed", e); - } - } - - private Stream parseDocuments(String body) { - try { - JsonNode jsonNode = OBJECT_MAPPER.readTree(body); - return StreamSupport.stream(jsonNode.get("hits").get("hits").spliterator(), false) - .map(hitNode -> hitNode.get("_source")) - .map(JsonNode::toString); - } catch (IOException e) { - throw new IllegalStateException("parseDocuments failed. body=" + body, e); - } - } -} - diff --git a/tests/test-spring-boot-2.3/pom.xml b/tests/test-spring-boot-2.3/pom.xml deleted file mode 100644 index 9508791b..00000000 --- a/tests/test-spring-boot-2.3/pom.xml +++ /dev/null @@ -1,107 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.12.RELEASE - - - com.senacor.elasticsearch.evolution - test-spring-boot-2.3 - 0.5.3-SNAPSHOT - Demo project for Spring Boot - - - 1.8 - - 2.16.1 - 7.5.2 - 1.19.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - ${project.groupId} - spring-boot-starter-elasticsearch-evolution - ${project.version} - - - - - org.testcontainers - elasticsearch - ${testcontainers.elasticsearch.version} - test - - - commons-io - commons-io - ${commons-io.version} - test - - - - - - oss.sonatype.org-snapshot - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.jacoco - jacoco-maven-plugin - - 0.8.12 - - - prepare-agent - - prepare-agent - - - - report - post-integration-test - - report - - - - - - maven-surefire-plugin - - true - - - - - - diff --git a/tests/test-spring-boot-2.3/src/main/java/com/senacor/elasticsearch/evolution/springboot23/Application.java b/tests/test-spring-boot-2.3/src/main/java/com/senacor/elasticsearch/evolution/springboot23/Application.java deleted file mode 100644 index 4b792124..00000000 --- a/tests/test-spring-boot-2.3/src/main/java/com/senacor/elasticsearch/evolution/springboot23/Application.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot23; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.3/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http b/tests/test-spring-boot-2.3/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http deleted file mode 100644 index fbd7df47..00000000 --- a/tests/test-spring-boot-2.3/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http +++ /dev/null @@ -1,35 +0,0 @@ -PUT _template/test_1 -Content-Type: application/json - -{ - "index_patterns" : [ - "test_*" - ], - "order" : 1, - "version" : 1, - "settings" : { - "number_of_shards" : 1 - }, - "mappings" : { - "dynamic" : "strict", - "properties" : { - "doc" : { - "dynamic" : false, - "properties" : {} - }, - "searchable" : { - "dynamic" : false, - "properties" : { - "version" : { - "type" : "keyword", - "ignore_above" : 20, - "similarity" : "boolean" - }, - "locked" : { - "type" : "boolean" - } - } - } - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.3/src/main/resources/es/migration/V001.01__addDocument.http b/tests/test-spring-boot-2.3/src/main/resources/es/migration/V001.01__addDocument.http deleted file mode 100644 index 4f18ba0a..00000000 --- a/tests/test-spring-boot-2.3/src/main/resources/es/migration/V001.01__addDocument.http +++ /dev/null @@ -1,17 +0,0 @@ -PUT /test_1/_doc/1?refresh -Content-Type: application/json - -{ - "searchable": { - "version": "1", - "locked": false - }, - "doc": { - "version": "1", - "locked": false, - "success": true, - "a": "a a a", - "b": true, - "c": "c" - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.3/src/test/java/com/senacor/elasticsearch/evolution/springboot23/ApplicationTests.java b/tests/test-spring-boot-2.3/src/test/java/com/senacor/elasticsearch/evolution/springboot23/ApplicationTests.java deleted file mode 100644 index 8a97507f..00000000 --- a/tests/test-spring-boot-2.3/src/test/java/com/senacor/elasticsearch/evolution/springboot23/ApplicationTests.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot23; - -import com.github.dockerjava.api.command.InspectContainerResponse; -import org.apache.http.HttpHost; -import org.elasticsearch.client.RestClient; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.testcontainers.elasticsearch.ElasticsearchContainer; -import org.testcontainers.utility.DockerImageName; - -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(properties = {"spring.elasticsearch.rest.uris=http://localhost:" + ApplicationTests.ELASTICSEARCH_PORT}) -class ApplicationTests { - - static final int ELASTICSEARCH_PORT = 18761; - - @Autowired - private EsUtils esUtils; - - @Test - void contextLoads() { - esUtils.refreshIndices(); - - List documents = esUtils.fetchAllDocuments("test_1"); - - assertThat(documents).hasSize(1); - } - - @TestConfiguration - static class Config { - @Bean(destroyMethod = "stop") - public ElasticsearchContainer elasticsearchContainer(@Value("${elasticsearch.version:7.5.2}") String esVersion) { - ElasticsearchContainer container = new ElasticsearchContainer(DockerImageName - .parse("docker.elastic.co/elasticsearch/elasticsearch") - .withTag(esVersion)) { - @Override - protected void containerIsStarted(InspectContainerResponse containerInfo) { - // since testcontainers 1.17 it detects if ES 8.x is running and copies a certificate in this case - // but we don't want security - } - } - .withEnv("ES_JAVA_OPTS", "-Xms128m -Xmx128m") - // since elasticsearch 8 security / https is enabled per default - but for testing it should be disabled - .withEnv("xpack.security.enabled", "false") - .withEnv("cluster.routing.allocation.disk.watermark.low", "97%") - .withEnv("cluster.routing.allocation.disk.watermark.high", "98%") - .withEnv("cluster.routing.allocation.disk.watermark.flood_stage", "99%"); - container.setPortBindings(Collections.singletonList(ELASTICSEARCH_PORT + ":9200")); - container.start(); - return container; - } - - @Bean - public EsUtils esUtils(ElasticsearchContainer elasticsearchContainer) { - return new EsUtils(RestClient.builder(HttpHost.create(elasticsearchContainer.getHttpHostAddress())).build()); - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.3/src/test/java/com/senacor/elasticsearch/evolution/springboot23/EsUtils.java b/tests/test-spring-boot-2.3/src/test/java/com/senacor/elasticsearch/evolution/springboot23/EsUtils.java deleted file mode 100644 index bde1f552..00000000 --- a/tests/test-spring-boot-2.3/src/test/java/com/senacor/elasticsearch/evolution/springboot23/EsUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot23; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.IOUtils; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestClient; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * @author Andreas Keefer - */ -public class EsUtils { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - private final RestClient restClient; - - public EsUtils(RestClient restClient) { - this.restClient = restClient; - } - - public void refreshIndices() { - try { - restClient.performRequest(new Request("GET", "/_refresh")); - } catch (IOException e) { - throw new IllegalStateException("refreshIndices failed", e); - } - } - - public List fetchAllDocuments(String index) { - try { - Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); - Response response = restClient.performRequest(post); - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode < 200 || statusCode >= 300) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed with HTTP status " + - statusCode + ": " + response.toString()); - } - String body = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); - - return parseDocuments(body) - .collect(Collectors.toList()); - } catch (IOException e) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed", e); - } - } - - private Stream parseDocuments(String body) { - try { - JsonNode jsonNode = OBJECT_MAPPER.readTree(body); - return StreamSupport.stream(jsonNode.get("hits").get("hits").spliterator(), false) - .map(hitNode -> hitNode.get("_source")) - .map(JsonNode::toString); - } catch (IOException e) { - throw new IllegalStateException("parseDocuments failed. body=" + body, e); - } - } -} - diff --git a/tests/test-spring-boot-2.4/pom.xml b/tests/test-spring-boot-2.4/pom.xml deleted file mode 100644 index b320ab62..00000000 --- a/tests/test-spring-boot-2.4/pom.xml +++ /dev/null @@ -1,107 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.4.13 - - - com.senacor.elasticsearch.evolution - test-spring-boot-2.4 - 0.5.3-SNAPSHOT - Demo project for Spring Boot - - - 1.8 - - 2.16.1 - 7.5.2 - 1.19.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - ${project.groupId} - spring-boot-starter-elasticsearch-evolution - ${project.version} - - - - - org.testcontainers - elasticsearch - ${testcontainers.elasticsearch.version} - test - - - commons-io - commons-io - ${commons-io.version} - test - - - - - - oss.sonatype.org-snapshot - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.jacoco - jacoco-maven-plugin - - 0.8.12 - - - prepare-agent - - prepare-agent - - - - report - post-integration-test - - report - - - - - - maven-surefire-plugin - - true - - - - - - diff --git a/tests/test-spring-boot-2.4/src/main/java/com/senacor/elasticsearch/evolution/springboot24/Application.java b/tests/test-spring-boot-2.4/src/main/java/com/senacor/elasticsearch/evolution/springboot24/Application.java deleted file mode 100644 index 6778bd46..00000000 --- a/tests/test-spring-boot-2.4/src/main/java/com/senacor/elasticsearch/evolution/springboot24/Application.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot24; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.4/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http b/tests/test-spring-boot-2.4/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http deleted file mode 100644 index fbd7df47..00000000 --- a/tests/test-spring-boot-2.4/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http +++ /dev/null @@ -1,35 +0,0 @@ -PUT _template/test_1 -Content-Type: application/json - -{ - "index_patterns" : [ - "test_*" - ], - "order" : 1, - "version" : 1, - "settings" : { - "number_of_shards" : 1 - }, - "mappings" : { - "dynamic" : "strict", - "properties" : { - "doc" : { - "dynamic" : false, - "properties" : {} - }, - "searchable" : { - "dynamic" : false, - "properties" : { - "version" : { - "type" : "keyword", - "ignore_above" : 20, - "similarity" : "boolean" - }, - "locked" : { - "type" : "boolean" - } - } - } - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.4/src/main/resources/es/migration/V001.01__addDocument.http b/tests/test-spring-boot-2.4/src/main/resources/es/migration/V001.01__addDocument.http deleted file mode 100644 index 4f18ba0a..00000000 --- a/tests/test-spring-boot-2.4/src/main/resources/es/migration/V001.01__addDocument.http +++ /dev/null @@ -1,17 +0,0 @@ -PUT /test_1/_doc/1?refresh -Content-Type: application/json - -{ - "searchable": { - "version": "1", - "locked": false - }, - "doc": { - "version": "1", - "locked": false, - "success": true, - "a": "a a a", - "b": true, - "c": "c" - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.4/src/test/java/com/senacor/elasticsearch/evolution/springboot24/ApplicationTests.java b/tests/test-spring-boot-2.4/src/test/java/com/senacor/elasticsearch/evolution/springboot24/ApplicationTests.java deleted file mode 100644 index e379f8b1..00000000 --- a/tests/test-spring-boot-2.4/src/test/java/com/senacor/elasticsearch/evolution/springboot24/ApplicationTests.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot24; - -import com.github.dockerjava.api.command.InspectContainerResponse; -import org.apache.http.HttpHost; -import org.elasticsearch.client.RestClient; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.testcontainers.elasticsearch.ElasticsearchContainer; -import org.testcontainers.utility.DockerImageName; - -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(properties = {"spring.elasticsearch.rest.uris=http://localhost:" + ApplicationTests.ELASTICSEARCH_PORT}) -class ApplicationTests { - - static final int ELASTICSEARCH_PORT = 18762; - - @Autowired - private EsUtils esUtils; - - @Test - void contextLoads() { - esUtils.refreshIndices(); - - List documents = esUtils.fetchAllDocuments("test_1"); - - assertThat(documents).hasSize(1); - } - - @TestConfiguration - static class Config { - @Bean(destroyMethod = "stop") - public ElasticsearchContainer elasticsearchContainer(@Value("${elasticsearch.version:7.5.2}") String esVersion) { - ElasticsearchContainer container = new ElasticsearchContainer(DockerImageName - .parse("docker.elastic.co/elasticsearch/elasticsearch") - .withTag(esVersion)) { - @Override - protected void containerIsStarted(InspectContainerResponse containerInfo) { - // since testcontainers 1.17 it detects if ES 8.x is running and copies a certificate in this case - // but we don't want security - } - } - .withEnv("ES_JAVA_OPTS", "-Xms128m -Xmx128m") - // since elasticsearch 8 security / https is enabled per default - but for testing it should be disabled - .withEnv("xpack.security.enabled", "false") - .withEnv("cluster.routing.allocation.disk.watermark.low", "97%") - .withEnv("cluster.routing.allocation.disk.watermark.high", "98%") - .withEnv("cluster.routing.allocation.disk.watermark.flood_stage", "99%"); - container.setPortBindings(Collections.singletonList(ELASTICSEARCH_PORT + ":9200")); - container.start(); - return container; - } - - @Bean - public EsUtils esUtils(ElasticsearchContainer elasticsearchContainer) { - return new EsUtils(RestClient.builder(HttpHost.create(elasticsearchContainer.getHttpHostAddress())).build()); - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.4/src/test/java/com/senacor/elasticsearch/evolution/springboot24/EsUtils.java b/tests/test-spring-boot-2.4/src/test/java/com/senacor/elasticsearch/evolution/springboot24/EsUtils.java deleted file mode 100644 index 93ad5096..00000000 --- a/tests/test-spring-boot-2.4/src/test/java/com/senacor/elasticsearch/evolution/springboot24/EsUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot24; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.IOUtils; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestClient; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * @author Andreas Keefer - */ -public class EsUtils { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - private final RestClient restClient; - - public EsUtils(RestClient restClient) { - this.restClient = restClient; - } - - public void refreshIndices() { - try { - restClient.performRequest(new Request("GET", "/_refresh")); - } catch (IOException e) { - throw new IllegalStateException("refreshIndices failed", e); - } - } - - public List fetchAllDocuments(String index) { - try { - Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); - Response response = restClient.performRequest(post); - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode < 200 || statusCode >= 300) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed with HTTP status " + - statusCode + ": " + response.toString()); - } - String body = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); - - return parseDocuments(body) - .collect(Collectors.toList()); - } catch (IOException e) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed", e); - } - } - - private Stream parseDocuments(String body) { - try { - JsonNode jsonNode = OBJECT_MAPPER.readTree(body); - return StreamSupport.stream(jsonNode.get("hits").get("hits").spliterator(), false) - .map(hitNode -> hitNode.get("_source")) - .map(JsonNode::toString); - } catch (IOException e) { - throw new IllegalStateException("parseDocuments failed. body=" + body, e); - } - } -} - diff --git a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml b/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml deleted file mode 100644 index 892a280c..00000000 --- a/tests/test-spring-boot-2.5-scriptsInJarFile/pom.xml +++ /dev/null @@ -1,114 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.5.14 - - - com.senacor.elasticsearch.evolution - test-spring-boot-2.5-scriptsInJarFile - 0.5.3-SNAPSHOT - Demo project for Spring Boot - - - 1.8 - - 2.16.1 - 7.5.2 - 1.19.8 - - - - - - ${project.groupId} - migration-scripts - ${project.version} - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - ${project.groupId} - spring-boot-starter-elasticsearch-evolution - ${project.version} - - - - - org.testcontainers - elasticsearch - ${testcontainers.elasticsearch.version} - test - - - commons-io - commons-io - ${commons-io.version} - test - - - - - - oss.sonatype.org-snapshot - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.jacoco - jacoco-maven-plugin - - 0.8.12 - - - prepare-agent - - prepare-agent - - - - report - post-integration-test - - report - - - - - - maven-surefire-plugin - - true - - - - - - diff --git a/tests/test-spring-boot-2.5-scriptsInJarFile/src/main/java/com/senacor/elasticsearch/evolution/springboot25/Application.java b/tests/test-spring-boot-2.5-scriptsInJarFile/src/main/java/com/senacor/elasticsearch/evolution/springboot25/Application.java deleted file mode 100644 index 15055b27..00000000 --- a/tests/test-spring-boot-2.5-scriptsInJarFile/src/main/java/com/senacor/elasticsearch/evolution/springboot25/Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot25; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.5-scriptsInJarFile/src/main/resources/application.properties b/tests/test-spring-boot-2.5-scriptsInJarFile/src/main/resources/application.properties deleted file mode 100644 index 5db1f692..00000000 --- a/tests/test-spring-boot-2.5-scriptsInJarFile/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -spring.elasticsearch.evolution.locations[0]=classpath:es/mig -spring.elasticsearch.evolution.placeholders.index=test_1 -logging.level.com.senacor.elasticsearch.evolution=DEBUG \ No newline at end of file diff --git a/tests/test-spring-boot-2.5-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot25/ApplicationTest.java b/tests/test-spring-boot-2.5-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot25/ApplicationTest.java deleted file mode 100644 index b6de4253..00000000 --- a/tests/test-spring-boot-2.5-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot25/ApplicationTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot25; - -import com.github.dockerjava.api.command.InspectContainerResponse; -import org.apache.http.HttpHost; -import org.elasticsearch.client.RestClient; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.testcontainers.elasticsearch.ElasticsearchContainer; -import org.testcontainers.utility.DockerImageName; - -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(properties = {"spring.elasticsearch.rest.uris=http://localhost:" + ApplicationTest.ELASTICSEARCH_PORT}) -class ApplicationTest { - - static final int ELASTICSEARCH_PORT = 18768; - - @Autowired - private EsUtils esUtils; - - @Test - void contextLoads() { - esUtils.refreshIndices(); - - List documents = esUtils.fetchAllDocuments("test_1"); - - assertThat(documents).hasSize(1); - } - - @TestConfiguration - static class Config { - @Bean(destroyMethod = "stop") - public ElasticsearchContainer elasticsearchContainer(@Value("${elasticsearch.version:7.5.2}") String esVersion) { - ElasticsearchContainer container = new ElasticsearchContainer(DockerImageName - .parse("docker.elastic.co/elasticsearch/elasticsearch") - .withTag(esVersion)) { - @Override - protected void containerIsStarted(InspectContainerResponse containerInfo) { - // since testcontainers 1.17 it detects if ES 8.x is running and copies a certificate in this case - // but we don't want security - } - } - .withEnv("ES_JAVA_OPTS", "-Xms128m -Xmx128m") - // since elasticsearch 8 security / https is enabled per default - but for testing it should be disabled - .withEnv("xpack.security.enabled", "false") - .withEnv("cluster.routing.allocation.disk.watermark.low", "97%") - .withEnv("cluster.routing.allocation.disk.watermark.high", "98%") - .withEnv("cluster.routing.allocation.disk.watermark.flood_stage", "99%"); - container.setPortBindings(Collections.singletonList(ELASTICSEARCH_PORT + ":9200")); - container.start(); - return container; - } - - @Bean - public EsUtils esUtils(ElasticsearchContainer elasticsearchContainer) { - return new EsUtils(RestClient.builder(HttpHost.create(elasticsearchContainer.getHttpHostAddress())).build()); - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.5-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot25/EsUtils.java b/tests/test-spring-boot-2.5-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot25/EsUtils.java deleted file mode 100644 index 8f9e5c3a..00000000 --- a/tests/test-spring-boot-2.5-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot25/EsUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot25; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.IOUtils; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestClient; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * @author Andreas Keefer - */ -public class EsUtils { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - private final RestClient restClient; - - public EsUtils(RestClient restClient) { - this.restClient = restClient; - } - - public void refreshIndices() { - try { - restClient.performRequest(new Request("GET", "/_refresh")); - } catch (IOException e) { - throw new IllegalStateException("refreshIndices failed", e); - } - } - - public List fetchAllDocuments(String index) { - try { - Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); - Response response = restClient.performRequest(post); - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode < 200 || statusCode >= 300) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed with HTTP status " + - statusCode + ": " + response.toString()); - } - String body = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); - - return parseDocuments(body) - .collect(Collectors.toList()); - } catch (IOException e) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed", e); - } - } - - private Stream parseDocuments(String body) { - try { - JsonNode jsonNode = OBJECT_MAPPER.readTree(body); - return StreamSupport.stream(jsonNode.get("hits").get("hits").spliterator(), false) - .map(hitNode -> hitNode.get("_source")) - .map(JsonNode::toString); - } catch (IOException e) { - throw new IllegalStateException("parseDocuments failed. body=" + body, e); - } - } -} - diff --git a/tests/test-spring-boot-2.6/pom.xml b/tests/test-spring-boot-2.6/pom.xml deleted file mode 100644 index 2206f03f..00000000 --- a/tests/test-spring-boot-2.6/pom.xml +++ /dev/null @@ -1,107 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.6.14 - - - com.senacor.elasticsearch.evolution - test-spring-boot-2.6 - 0.5.3-SNAPSHOT - Demo project for Spring Boot - - - 1.8 - - 2.16.1 - 7.5.2 - 1.19.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - ${project.groupId} - spring-boot-starter-elasticsearch-evolution - ${project.version} - - - - - org.testcontainers - elasticsearch - ${testcontainers.elasticsearch.version} - test - - - commons-io - commons-io - ${commons-io.version} - test - - - - - - oss.sonatype.org-snapshot - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.jacoco - jacoco-maven-plugin - - 0.8.12 - - - prepare-agent - - prepare-agent - - - - report - post-integration-test - - report - - - - - - maven-surefire-plugin - - true - - - - - - diff --git a/tests/test-spring-boot-2.6/src/main/java/com/senacor/elasticsearch/evolution/springboot26/Application.java b/tests/test-spring-boot-2.6/src/main/java/com/senacor/elasticsearch/evolution/springboot26/Application.java deleted file mode 100644 index ac199c30..00000000 --- a/tests/test-spring-boot-2.6/src/main/java/com/senacor/elasticsearch/evolution/springboot26/Application.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot26; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.6/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http b/tests/test-spring-boot-2.6/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http deleted file mode 100644 index fbd7df47..00000000 --- a/tests/test-spring-boot-2.6/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http +++ /dev/null @@ -1,35 +0,0 @@ -PUT _template/test_1 -Content-Type: application/json - -{ - "index_patterns" : [ - "test_*" - ], - "order" : 1, - "version" : 1, - "settings" : { - "number_of_shards" : 1 - }, - "mappings" : { - "dynamic" : "strict", - "properties" : { - "doc" : { - "dynamic" : false, - "properties" : {} - }, - "searchable" : { - "dynamic" : false, - "properties" : { - "version" : { - "type" : "keyword", - "ignore_above" : 20, - "similarity" : "boolean" - }, - "locked" : { - "type" : "boolean" - } - } - } - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.6/src/main/resources/es/migration/V001.01__addDocument.http b/tests/test-spring-boot-2.6/src/main/resources/es/migration/V001.01__addDocument.http deleted file mode 100644 index 4f18ba0a..00000000 --- a/tests/test-spring-boot-2.6/src/main/resources/es/migration/V001.01__addDocument.http +++ /dev/null @@ -1,17 +0,0 @@ -PUT /test_1/_doc/1?refresh -Content-Type: application/json - -{ - "searchable": { - "version": "1", - "locked": false - }, - "doc": { - "version": "1", - "locked": false, - "success": true, - "a": "a a a", - "b": true, - "c": "c" - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.6/src/test/java/com/senacor/elasticsearch/evolution/springboot26/ApplicationTests.java b/tests/test-spring-boot-2.6/src/test/java/com/senacor/elasticsearch/evolution/springboot26/ApplicationTests.java deleted file mode 100644 index d8cd75ea..00000000 --- a/tests/test-spring-boot-2.6/src/test/java/com/senacor/elasticsearch/evolution/springboot26/ApplicationTests.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot26; - -import com.github.dockerjava.api.command.InspectContainerResponse; -import org.apache.http.HttpHost; -import org.elasticsearch.client.RestClient; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.testcontainers.elasticsearch.ElasticsearchContainer; -import org.testcontainers.utility.DockerImageName; - -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(properties = {"spring.elasticsearch.uris=http://localhost:" + ApplicationTests.ELASTICSEARCH_PORT}) -class ApplicationTests { - - static final int ELASTICSEARCH_PORT = 18772; - - @Autowired - private EsUtils esUtils; - - @Test - void contextLoads() { - esUtils.refreshIndices(); - - List documents = esUtils.fetchAllDocuments("test_1"); - - assertThat(documents).hasSize(1); - } - - @TestConfiguration - static class Config { - @Bean(destroyMethod = "stop") - public ElasticsearchContainer elasticsearchContainer(@Value("${elasticsearch.version:7.5.2}") String esVersion) { - ElasticsearchContainer container = new ElasticsearchContainer(DockerImageName - .parse("docker.elastic.co/elasticsearch/elasticsearch") - .withTag(esVersion)) { - @Override - protected void containerIsStarted(InspectContainerResponse containerInfo) { - // since testcontainers 1.17 it detects if ES 8.x is running and copies a certificate in this case - // but we don't want security - } - } - .withEnv("ES_JAVA_OPTS", "-Xms128m -Xmx128m") - // since elasticsearch 8 security / https is enabled per default - but for testing it should be disabled - .withEnv("xpack.security.enabled", "false") - .withEnv("cluster.routing.allocation.disk.watermark.low", "97%") - .withEnv("cluster.routing.allocation.disk.watermark.high", "98%") - .withEnv("cluster.routing.allocation.disk.watermark.flood_stage", "99%"); - container.setPortBindings(Collections.singletonList(ELASTICSEARCH_PORT + ":9200")); - container.start(); - return container; - } - - @Bean - public EsUtils esUtils(ElasticsearchContainer elasticsearchContainer) { - return new EsUtils(RestClient.builder(HttpHost.create(elasticsearchContainer.getHttpHostAddress())).build()); - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.6/src/test/java/com/senacor/elasticsearch/evolution/springboot26/EsUtils.java b/tests/test-spring-boot-2.6/src/test/java/com/senacor/elasticsearch/evolution/springboot26/EsUtils.java deleted file mode 100644 index 31d618ff..00000000 --- a/tests/test-spring-boot-2.6/src/test/java/com/senacor/elasticsearch/evolution/springboot26/EsUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot26; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.IOUtils; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestClient; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * @author Andreas Keefer - */ -public class EsUtils { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - private final RestClient restClient; - - public EsUtils(RestClient restClient) { - this.restClient = restClient; - } - - public void refreshIndices() { - try { - restClient.performRequest(new Request("GET", "/_refresh")); - } catch (IOException e) { - throw new IllegalStateException("refreshIndices failed", e); - } - } - - public List fetchAllDocuments(String index) { - try { - Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); - Response response = restClient.performRequest(post); - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode < 200 || statusCode >= 300) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed with HTTP status " + - statusCode + ": " + response.toString()); - } - String body = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); - - return parseDocuments(body) - .collect(Collectors.toList()); - } catch (IOException e) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed", e); - } - } - - private Stream parseDocuments(String body) { - try { - JsonNode jsonNode = OBJECT_MAPPER.readTree(body); - return StreamSupport.stream(jsonNode.get("hits").get("hits").spliterator(), false) - .map(hitNode -> hitNode.get("_source")) - .map(JsonNode::toString); - } catch (IOException e) { - throw new IllegalStateException("parseDocuments failed. body=" + body, e); - } - } -} - diff --git a/tests/test-spring-boot-2.7/pom.xml b/tests/test-spring-boot-2.7/pom.xml deleted file mode 100644 index 4405022e..00000000 --- a/tests/test-spring-boot-2.7/pom.xml +++ /dev/null @@ -1,107 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.7.18 - - - com.senacor.elasticsearch.evolution - test-spring-boot-2.7 - 0.5.3-SNAPSHOT - Demo project for Spring Boot - - - 1.8 - - 2.16.1 - 7.5.2 - 1.19.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - ${project.groupId} - spring-boot-starter-elasticsearch-evolution - ${project.version} - - - - - org.testcontainers - elasticsearch - ${testcontainers.elasticsearch.version} - test - - - commons-io - commons-io - ${commons-io.version} - test - - - - - - oss.sonatype.org-snapshot - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.jacoco - jacoco-maven-plugin - - 0.8.12 - - - prepare-agent - - prepare-agent - - - - report - post-integration-test - - report - - - - - - maven-surefire-plugin - - true - - - - - - diff --git a/tests/test-spring-boot-2.7/src/main/java/com/senacor/elasticsearch/evolution/springboot27/Application.java b/tests/test-spring-boot-2.7/src/main/java/com/senacor/elasticsearch/evolution/springboot27/Application.java deleted file mode 100644 index a22e3a8b..00000000 --- a/tests/test-spring-boot-2.7/src/main/java/com/senacor/elasticsearch/evolution/springboot27/Application.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot27; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.7/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http b/tests/test-spring-boot-2.7/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http deleted file mode 100644 index fbd7df47..00000000 --- a/tests/test-spring-boot-2.7/src/main/resources/es/migration/V001.00__createTemplateWithIndexMapping.http +++ /dev/null @@ -1,35 +0,0 @@ -PUT _template/test_1 -Content-Type: application/json - -{ - "index_patterns" : [ - "test_*" - ], - "order" : 1, - "version" : 1, - "settings" : { - "number_of_shards" : 1 - }, - "mappings" : { - "dynamic" : "strict", - "properties" : { - "doc" : { - "dynamic" : false, - "properties" : {} - }, - "searchable" : { - "dynamic" : false, - "properties" : { - "version" : { - "type" : "keyword", - "ignore_above" : 20, - "similarity" : "boolean" - }, - "locked" : { - "type" : "boolean" - } - } - } - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.7/src/main/resources/es/migration/V001.01__addDocument.http b/tests/test-spring-boot-2.7/src/main/resources/es/migration/V001.01__addDocument.http deleted file mode 100644 index 4f18ba0a..00000000 --- a/tests/test-spring-boot-2.7/src/main/resources/es/migration/V001.01__addDocument.http +++ /dev/null @@ -1,17 +0,0 @@ -PUT /test_1/_doc/1?refresh -Content-Type: application/json - -{ - "searchable": { - "version": "1", - "locked": false - }, - "doc": { - "version": "1", - "locked": false, - "success": true, - "a": "a a a", - "b": true, - "c": "c" - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.7/src/test/java/com/senacor/elasticsearch/evolution/springboot27/ApplicationTests.java b/tests/test-spring-boot-2.7/src/test/java/com/senacor/elasticsearch/evolution/springboot27/ApplicationTests.java deleted file mode 100644 index 40a4e773..00000000 --- a/tests/test-spring-boot-2.7/src/test/java/com/senacor/elasticsearch/evolution/springboot27/ApplicationTests.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot27; - -import com.github.dockerjava.api.command.InspectContainerResponse; -import org.apache.http.HttpHost; -import org.elasticsearch.client.RestClient; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.testcontainers.elasticsearch.ElasticsearchContainer; -import org.testcontainers.utility.DockerImageName; - -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(properties = {"spring.elasticsearch.uris=http://localhost:" + ApplicationTests.ELASTICSEARCH_PORT}) -class ApplicationTests { - - static final int ELASTICSEARCH_PORT = 18773; - - @Autowired - private EsUtils esUtils; - - @Test - void contextLoads() { - esUtils.refreshIndices(); - - List documents = esUtils.fetchAllDocuments("test_1"); - - assertThat(documents).hasSize(1); - } - - @TestConfiguration - static class Config { - @Bean(destroyMethod = "stop") - public ElasticsearchContainer elasticsearchContainer(@Value("${elasticsearch.version:7.5.2}") String esVersion) { - ElasticsearchContainer container = new ElasticsearchContainer(DockerImageName - .parse("docker.elastic.co/elasticsearch/elasticsearch") - .withTag(esVersion)) { - @Override - protected void containerIsStarted(InspectContainerResponse containerInfo) { - // since testcontainers 1.17 it detects if ES 8.x is running and copies a certificate in this case - // but we don't want security - } - } - .withEnv("ES_JAVA_OPTS", "-Xms128m -Xmx128m") - // since elasticsearch 8 security / https is enabled per default - but for testing it should be disabled - .withEnv("xpack.security.enabled", "false") - .withEnv("cluster.routing.allocation.disk.watermark.low", "97%") - .withEnv("cluster.routing.allocation.disk.watermark.high", "98%") - .withEnv("cluster.routing.allocation.disk.watermark.flood_stage", "99%"); - container.setPortBindings(Collections.singletonList(ELASTICSEARCH_PORT + ":9200")); - container.start(); - return container; - } - - @Bean - public EsUtils esUtils(ElasticsearchContainer elasticsearchContainer) { - return new EsUtils(RestClient.builder(HttpHost.create(elasticsearchContainer.getHttpHostAddress())).build()); - } - } -} \ No newline at end of file diff --git a/tests/test-spring-boot-2.7/src/test/java/com/senacor/elasticsearch/evolution/springboot27/EsUtils.java b/tests/test-spring-boot-2.7/src/test/java/com/senacor/elasticsearch/evolution/springboot27/EsUtils.java deleted file mode 100644 index 9c550f6a..00000000 --- a/tests/test-spring-boot-2.7/src/test/java/com/senacor/elasticsearch/evolution/springboot27/EsUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.senacor.elasticsearch.evolution.springboot27; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.IOUtils; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestClient; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * @author Andreas Keefer - */ -public class EsUtils { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - private final RestClient restClient; - - public EsUtils(RestClient restClient) { - this.restClient = restClient; - } - - public void refreshIndices() { - try { - restClient.performRequest(new Request("GET", "/_refresh")); - } catch (IOException e) { - throw new IllegalStateException("refreshIndices failed", e); - } - } - - public List fetchAllDocuments(String index) { - try { - Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); - Response response = restClient.performRequest(post); - int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode < 200 || statusCode >= 300) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed with HTTP status " + - statusCode + ": " + response.toString()); - } - String body = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); - - return parseDocuments(body) - .collect(Collectors.toList()); - } catch (IOException e) { - throw new IllegalStateException("fetchAllDocuments(" + index + ") failed", e); - } - } - - private Stream parseDocuments(String body) { - try { - JsonNode jsonNode = OBJECT_MAPPER.readTree(body); - return StreamSupport.stream(jsonNode.get("hits").get("hits").spliterator(), false) - .map(hitNode -> hitNode.get("_source")) - .map(JsonNode::toString); - } catch (IOException e) { - throw new IllegalStateException("parseDocuments failed. body=" + body, e); - } - } -} - diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml index 7801e1bf..f95fc6a0 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.0-scriptsInJarFile - 0.5.3-SNAPSHOT + 0.6.0-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.1/pom.xml b/tests/test-spring-boot-3.1/pom.xml index ea2b24ac..69f533d7 100644 --- a/tests/test-spring-boot-3.1/pom.xml +++ b/tests/test-spring-boot-3.1/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.1 - 0.5.3-SNAPSHOT + 0.6.0-SNAPSHOT Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.2/pom.xml b/tests/test-spring-boot-3.2/pom.xml index ff5327ef..363b4c33 100644 --- a/tests/test-spring-boot-3.2/pom.xml +++ b/tests/test-spring-boot-3.2/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.2 - 0.5.3-SNAPSHOT + 0.6.0-SNAPSHOT Demo project for Spring Boot From 5590cddd8a1d420bc4a7c581fee53efbb3ba3957 Mon Sep 17 00:00:00 2001 From: Andreas Keefer Date: Sat, 11 May 2024 16:45:38 +0200 Subject: [PATCH 4/9] - migrate to java17 with help of openrewrite --- .../core/ElasticsearchEvolution.java | 2 +- .../execution/HistoryRepositoryImpl.java | 4 +- .../execution/MigrationServiceImpl.java | 48 +++++++++++-------- .../input/MigrationScriptParserImpl.java | 19 ++++---- .../input/MigrationScriptReaderImpl.java | 13 ++--- .../migration/MigrationScriptRequest.java | 6 +-- .../core/internal/utils/AssertionUtils.java | 11 +++-- .../execution/MigrationServiceImplTest.java | 8 ++-- .../input/MigrationScriptReaderImplTest.java | 6 ++- .../evolution/core/test/EsUtils.java | 14 +++--- pom.xml | 21 ++++++++ tests/migration-scripts/pom.xml | 21 ++++++++ .../pom.xml | 17 +++++++ .../evolution/springboot30/EsUtils.java | 12 +++-- tests/test-spring-boot-3.1/pom.xml | 17 +++++++ .../evolution/springboot31/EsUtils.java | 12 +++-- tests/test-spring-boot-3.2/pom.xml | 17 +++++++ .../evolution/springboot32/EsUtils.java | 12 +++-- 18 files changed, 188 insertions(+), 72 deletions(-) diff --git a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/ElasticsearchEvolution.java b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/ElasticsearchEvolution.java index 2b182a98..7c36c58e 100644 --- a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/ElasticsearchEvolution.java +++ b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/ElasticsearchEvolution.java @@ -102,7 +102,7 @@ public int migrate() throws MigrationException { logger.info("reading migration scripts..."); Collection rawMigrationScripts = migrationScriptReader.read(); if (rawMigrationScripts.size() > getConfig().getHistoryMaxQuerySize()) { - throw new MigrationException(String.format("configured historyMaxQuerySize of '%s' is to low for the number of migration scripts of '%s'", + throw new MigrationException("configured historyMaxQuerySize of '%s' is to low for the number of migration scripts of '%s'".formatted( getConfig().getHistoryMaxQuerySize(), rawMigrationScripts.size())); } diff --git a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/HistoryRepositoryImpl.java b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/HistoryRepositoryImpl.java index 6478264c..14a7c9c1 100644 --- a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/HistoryRepositoryImpl.java +++ b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/HistoryRepositoryImpl.java @@ -91,7 +91,7 @@ public void saveOrUpdate(MigrationScriptProtocol migrationScriptProtocol) throws } validateHttpStatusIs2xx(res, "saveOrUpdate"); } catch (IOException e) { - throw new MigrationException(String.format("saveOrUpdate of '%s' failed!", migrationScriptProtocol), e); + throw new MigrationException("saveOrUpdate of '%s' failed!".formatted(migrationScriptProtocol), e); } } @@ -238,7 +238,7 @@ private void validateHttpStatusIs2xx(Response response, String description) thro void validateHttpStatusIs2xx(int statusCode, String description) throws MigrationException { if (isNotStatusCode2xx(statusCode)) { - throw new MigrationException(String.format("%s - response status is not OK: %s", description, statusCode)); + throw new MigrationException("%s - response status is not OK: %s".formatted(description, statusCode)); } } diff --git a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/MigrationServiceImpl.java b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/MigrationServiceImpl.java index b12b2615..875aa61e 100644 --- a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/MigrationServiceImpl.java +++ b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/MigrationServiceImpl.java @@ -148,14 +148,14 @@ ExecutionResult executeScript(ParsedMigrationScript scriptToExecute) { if (statusCode >= 200 && statusCode < 300) { success = true; } else { - error = Optional.of(new MigrationException(String.format( - "execution of script '%s' failed with HTTP status %s: %s", + error = Optional.of(new MigrationException( + "execution of script '%s' failed with HTTP status %s: %s".formatted( scriptToExecute.getFileNameInfo(), statusCode, response.toString()))); } } catch (RuntimeException | IOException e) { - error = Optional.of(new MigrationException(String.format("execution of script '%s' failed", scriptToExecute.getFileNameInfo()), e)); + error = Optional.of(new MigrationException("execution of script '%s' failed".formatted(scriptToExecute.getFileNameInfo()), e)); } return new ExecutionResult( @@ -199,10 +199,12 @@ List getPendingScriptsToBeExecuted(Collection getPendingScriptsToBeExecuted(Collection getPendingScriptsToBeExecuted(Collection parse(Collection ra requireNonNull(rawMigrationScripts, "rawMigrationScripts must not be null"); return rawMigrationScripts.stream() .map(this::parse) - .collect(Collectors.toList()); + .toList(); } ParsedMigrationScript parse(RawMigrationScript rawMigrationScript) { @@ -111,8 +110,8 @@ private MigrationScriptRequest parseContent(RawMigrationScript script) { private void parseHeader(MigrationScriptRequest res, String line) { String[] header = line.trim().split("[:=]", 2); if (header.length != 2) { - throw new MigrationException(String.format( - "can't parse header: '%s'. Header must be separated by ':' and should look like this: 'Content-Type: application/json'", + throw new MigrationException( + "can't parse header: '%s'. Header must be separated by ':' and should look like this: 'Content-Type: application/json'".formatted( line)); } res.addHttpHeader(header[0].trim(), header[1].trim()); @@ -121,8 +120,8 @@ private void parseHeader(MigrationScriptRequest res, String line) { private void parseMethodWithPath(MigrationScriptRequest res, String line) { String[] methodAndPath = line.trim().split(" +", 2); if (methodAndPath.length != 2) { - throw new MigrationException(String.format( - "can't parse method and path: '%s'. Method and path must be separated by space and should look like this: 'PUT /my_index'", + throw new MigrationException( + "can't parse method and path: '%s'. Method and path must be separated by space and should look like this: 'PUT /my_index'".formatted( line)); } res.setHttpMethod(HttpMethod.create(methodAndPath[0])) @@ -163,8 +162,8 @@ FileNameInfo parseFileName(String migrationName, String version; String description; if (separatorPos < 0) { - throw new MigrationException(String.format( - "Description in migration filename is required: '%s'. It should look like this: '%s1.2%ssome_desctiption here%s'", + throw new MigrationException( + "Description in migration filename is required: '%s'. It should look like this: '%s1.2%ssome_desctiption here%s'".formatted( migrationName, prefix, separator, suffixes.get(0))); } @@ -193,8 +192,8 @@ private String cleanMigrationName(String migrationName, String prefix, List read() { return readFromLocation(location); } catch (URISyntaxException | IOException e) { throw new MigrationException( - String.format("couldn't read scripts from %s", location), e); + "couldn't read scripts from %s".formatted(location), e); } }) .distinct() - .collect(Collectors.toList()); + .toList(); } /** @@ -94,8 +93,10 @@ protected Stream readFromLocation(String location) throws UR } else if (location.startsWith(FILE_PREFIX)) { return readScriptsFromFilesystem(location); } else { - throw new MigrationException(String.format("could not read location path %s, " + - "should look like this: %ses/migration or this: %s/home/scripts/migration", + throw new MigrationException((""" + could not read location path %s, \ + should look like this: %ses/migration or this: %s/home/scripts/migration\ + """).formatted( location, CLASSPATH_PREFIX, FILE_PREFIX)); } } @@ -142,7 +143,7 @@ private Stream readScriptsFromClassPath(String location) { logger.debug("reading migration script '{}' from classpath...", resource); try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(resource.load()), encoding))) { Path p = Paths.get(resource.getPath()); - res.addAll(read(bufferedReader, p.getFileName().toString()).collect(Collectors.toList())); + res.addAll(read(bufferedReader, p.getFileName().toString()).toList()); } catch (IOException e) { throw new MigrationException("can't read script from classpath: " + resource, e); } diff --git a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/model/migration/MigrationScriptRequest.java b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/model/migration/MigrationScriptRequest.java index 1e5c0d26..76d28aa2 100644 --- a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/model/migration/MigrationScriptRequest.java +++ b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/model/migration/MigrationScriptRequest.java @@ -147,9 +147,9 @@ public static HttpMethod create(String method) throws MigrationException { return Arrays.stream(values()) .filter(m -> m.name().equals(normalizedMethod)) .findFirst() - .orElseThrow(() -> new MigrationException(String.format( - "Method '%s' not supported, only %s is supported.", - method, Arrays.toString(values())))); + .orElseThrow(() -> new MigrationException( + "Method '%s' not supported, only %s is supported.".formatted( + method, Arrays.toString(values())))); } } } diff --git a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/utils/AssertionUtils.java b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/utils/AssertionUtils.java index 99720e88..2a5c6eee 100644 --- a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/utils/AssertionUtils.java +++ b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/utils/AssertionUtils.java @@ -9,30 +9,33 @@ */ public class AssertionUtils { + private AssertionUtils() { + } + public static String requireNotEmpty(String obj, String message, Object... args) { if (Objects.requireNonNull(obj, message).isEmpty()) { - throw new IllegalStateException(String.format(message, args)); + throw new IllegalStateException(message.formatted(args)); } return obj; } public static String requireNotBlank(String obj, String message, Object... args) { if (Objects.requireNonNull(obj, message).trim().isEmpty()) { - throw new IllegalStateException(String.format(message, args)); + throw new IllegalStateException(message.formatted(args)); } return obj; } public static Collection requireNotEmpty(Collection obj, String message, Object... args) { if (Objects.requireNonNull(obj, message).isEmpty()) { - throw new IllegalStateException(String.format(message, args)); + throw new IllegalStateException(message.formatted(args)); } return obj; } public static T requireCondition(T value, Predicate predicate, String message, Object... args) { if (!predicate.test(value)) { - throw new IllegalStateException(String.format(message, args)); + throw new IllegalStateException(message.formatted(args)); } return value; } diff --git a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/MigrationServiceImplTest.java b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/MigrationServiceImplTest.java index a90dc400..9126a73e 100644 --- a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/MigrationServiceImplTest.java +++ b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/execution/MigrationServiceImplTest.java @@ -316,9 +316,11 @@ void successfulScriptWasEdited_shouldThrowChecksumMismatchException() { assertThatThrownBy(() -> underTest.getPendingScriptsToBeExecuted(parsedMigrationScripts)) .isInstanceOf(MigrationException.class) - .hasMessage("The logged execution for the migration script version 1.1 (V1.1__1.1.http) " + - "has a different checksum from the given migration script! " + - "Modifying already-executed scripts is not supported."); + .hasMessage(""" + The logged execution for the migration script version 1.1 (V1.1__1.1.http) \ + has a different checksum from the given migration script! \ + Modifying already-executed scripts is not supported.\ + """); } @Test diff --git a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java index 0217d734..ed7d9523 100644 --- a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java +++ b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java @@ -166,8 +166,10 @@ void withWrongProtocol() { Arrays.asList(".http", ".other"), "\n"); assertThatThrownBy(reader::read) .isInstanceOf(MigrationException.class) - .hasMessage("could not read location path http:scriptreader, should look like this: " + - "classpath:es/migration or this: file:/home/scripts/migration"); + .hasMessage(""" + could not read location path http:scriptreader, should look like this: \ + classpath:es/migration or this: file:/home/scripts/migration\ + """); } } diff --git a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/test/EsUtils.java b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/test/EsUtils.java index 31c20aaf..657bf0c2 100644 --- a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/test/EsUtils.java +++ b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/test/EsUtils.java @@ -39,11 +39,13 @@ public void refreshIndices() { public List fetchAllDocuments(String index) { try { Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); + post.setJsonEntity(""" + {\ + "query": {\ + "match_all": {}\ + }\ + }\ + """); Response response = restClient.performRequest(post); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode < 200 || statusCode >= 300) { @@ -76,7 +78,7 @@ public void indexDocument(String index, String id, HashMap sourc indexRequest.setJsonEntity(OBJECT_MAPPER.writeValueAsString(source)); final Response res = restClient.performRequest(indexRequest); if (res.getStatusLine().getStatusCode() != 201) { - throw new IllegalStateException(String.format("indexDocument failed with status code %s: %s", + throw new IllegalStateException("indexDocument failed with status code %s: %s".formatted( res.getStatusLine().getStatusCode(), res.getStatusLine().getReasonPhrase())); } diff --git a/pom.xml b/pom.xml index 0e4020d8..5ec4f6f7 100644 --- a/pom.xml +++ b/pom.xml @@ -277,9 +277,30 @@ + + org.openrewrite.maven + rewrite-maven-plugin + 5.30.0 + + + org.openrewrite.java.migrate.UpgradeToJava17 + + + + + org.openrewrite.recipe + rewrite-migrate-java + 2.13.0 + + + + + org.openrewrite.maven + rewrite-maven-plugin + maven-failsafe-plugin diff --git a/tests/migration-scripts/pom.xml b/tests/migration-scripts/pom.xml index b8dbd535..73e81685 100644 --- a/tests/migration-scripts/pom.xml +++ b/tests/migration-scripts/pom.xml @@ -14,4 +14,25 @@ UTF-8 + + + + org.openrewrite.maven + rewrite-maven-plugin + 5.30.0 + + + org.openrewrite.java.migrate.UpgradeToJava17 + + + + + org.openrewrite.recipe + rewrite-migrate-java + 2.13.0 + + + + + diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml index f95fc6a0..24013620 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml @@ -108,6 +108,23 @@ true + + org.openrewrite.maven + rewrite-maven-plugin + 5.30.0 + + + org.openrewrite.java.migrate.UpgradeToJava17 + + + + + org.openrewrite.recipe + rewrite-migrate-java + 2.13.0 + + + diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot30/EsUtils.java b/tests/test-spring-boot-3.0-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot30/EsUtils.java index 91518057..7fb150df 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot30/EsUtils.java +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/src/test/java/com/senacor/elasticsearch/evolution/springboot30/EsUtils.java @@ -38,11 +38,13 @@ public void refreshIndices() { public List fetchAllDocuments(String index) { try { Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); + post.setJsonEntity(""" + {\ + "query": {\ + "match_all": {}\ + }\ + }\ + """); Response response = restClient.performRequest(post); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode < 200 || statusCode >= 300) { diff --git a/tests/test-spring-boot-3.1/pom.xml b/tests/test-spring-boot-3.1/pom.xml index 69f533d7..3b033964 100644 --- a/tests/test-spring-boot-3.1/pom.xml +++ b/tests/test-spring-boot-3.1/pom.xml @@ -101,6 +101,23 @@ true + + org.openrewrite.maven + rewrite-maven-plugin + 5.30.0 + + + org.openrewrite.java.migrate.UpgradeToJava17 + + + + + org.openrewrite.recipe + rewrite-migrate-java + 2.13.0 + + + diff --git a/tests/test-spring-boot-3.1/src/test/java/com/senacor/elasticsearch/evolution/springboot31/EsUtils.java b/tests/test-spring-boot-3.1/src/test/java/com/senacor/elasticsearch/evolution/springboot31/EsUtils.java index 4c69d697..89235dcc 100644 --- a/tests/test-spring-boot-3.1/src/test/java/com/senacor/elasticsearch/evolution/springboot31/EsUtils.java +++ b/tests/test-spring-boot-3.1/src/test/java/com/senacor/elasticsearch/evolution/springboot31/EsUtils.java @@ -38,11 +38,13 @@ public void refreshIndices() { public List fetchAllDocuments(String index) { try { Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); + post.setJsonEntity(""" + {\ + "query": {\ + "match_all": {}\ + }\ + }\ + """); Response response = restClient.performRequest(post); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode < 200 || statusCode >= 300) { diff --git a/tests/test-spring-boot-3.2/pom.xml b/tests/test-spring-boot-3.2/pom.xml index 363b4c33..9a78e7f7 100644 --- a/tests/test-spring-boot-3.2/pom.xml +++ b/tests/test-spring-boot-3.2/pom.xml @@ -101,6 +101,23 @@ true + + org.openrewrite.maven + rewrite-maven-plugin + 5.30.0 + + + org.openrewrite.java.migrate.UpgradeToJava17 + + + + + org.openrewrite.recipe + rewrite-migrate-java + 2.13.0 + + + diff --git a/tests/test-spring-boot-3.2/src/test/java/com/senacor/elasticsearch/evolution/springboot32/EsUtils.java b/tests/test-spring-boot-3.2/src/test/java/com/senacor/elasticsearch/evolution/springboot32/EsUtils.java index e4129a2c..7258feb2 100644 --- a/tests/test-spring-boot-3.2/src/test/java/com/senacor/elasticsearch/evolution/springboot32/EsUtils.java +++ b/tests/test-spring-boot-3.2/src/test/java/com/senacor/elasticsearch/evolution/springboot32/EsUtils.java @@ -38,11 +38,13 @@ public void refreshIndices() { public List fetchAllDocuments(String index) { try { Request post = new Request("POST", "/" + index + "/_search"); - post.setJsonEntity("{" + - " \"query\": {" + - " \"match_all\": {}" + - " }" + - "}"); + post.setJsonEntity(""" + {\ + "query": {\ + "match_all": {}\ + }\ + }\ + """); Response response = restClient.performRequest(post); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode < 200 || statusCode >= 300) { From f777260dce06d67d423cb238ff2ac9e48fa5a6e9 Mon Sep 17 00:00:00 2001 From: Andreas Keefer Date: Sun, 12 May 2024 12:45:34 +0200 Subject: [PATCH 5/9] fix https://github.com/trautonen/coveralls-maven-plugin/issues/141 ClassNotFoundException: javax.xml.bind.DatatypeConverter since running on JDK 17 --- pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index 5ec4f6f7..eeae1ae5 100644 --- a/pom.xml +++ b/pom.xml @@ -180,6 +180,16 @@ org.eluder.coveralls coveralls-maven-plugin ${coveralls-maven-plugin.version} + + + + javax.xml.bind + jaxb-api + 2.3.1 + + maven-compiler-plugin From b28240a992e2dd80756aa6a2c580cf7741191fd1 Mon Sep 17 00:00:00 2001 From: Andreas Keefer Date: Sun, 19 May 2024 09:32:31 +0200 Subject: [PATCH 6/9] fixes issue #298: added option to trim trailing newline in migration scripts for backward compatibility / hash stability --- README.md | 3 + .../core/ElasticsearchEvolution.java | 3 +- .../config/ElasticsearchEvolutionConfig.java | 20 ++++- .../input/MigrationScriptReaderImpl.java | 22 +++-- .../input/MigrationScriptReaderImplTest.java | 87 ++++++++++++------- 5 files changed, 96 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index f4676b62..31488902 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,8 @@ Elasticsearch-Evolution can be configured to your needs: - **baselineVersion** (default=1.0): Version to use as a baseline. versions lower than it will not be applied. - **lineSeparator** (default=\n): Line separator, used only temporary between reading raw migration file line-by-line and parsing it later. Only needed for backward compatibility / checksum stability! Should be one of `\n`, `\r` or `\r\n` - **outOfOrder** (default=false): Allows migrations to be run "out of order". If you already have versions 1.0 and 3.0 applied, and now a version 2.0 is found, it will be applied too instead of being rejected. +- **trimTrailingNewlineInMigrations** (default=false): Whether to remove a trailing newline in migration scripts. Only + needed for backward compatibility / checksum stability! ### 5.1 Spring Boot @@ -281,6 +283,7 @@ ElasticsearchEvolution.configure() ### v0.6.0-SNAPSHOT +- Added option to trim a trailing newline in migration scripts (fixes [#298](https://github.com/senacor/elasticsearch-evolution/issues/298)). NOTE: This option is only needed for backward compatibility / checksum stability! - The minimum supported Java version is now 17. - Drop spring boot 2 compatibility. Further versions may run on spring boot 2, but it is not tested anymore. diff --git a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/ElasticsearchEvolution.java b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/ElasticsearchEvolution.java index 7c36c58e..20f5d8e3 100644 --- a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/ElasticsearchEvolution.java +++ b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/ElasticsearchEvolution.java @@ -151,7 +151,8 @@ protected MigrationScriptReader createMigrationScriptReader() { getConfig().getEncoding(), getConfig().getEsMigrationPrefix(), getConfig().getEsMigrationSuffixes(), - getConfig().getLineSeparator()); + getConfig().getLineSeparator(), + getConfig().isTrimTrailingNewlineInMigrations()); } protected HistoryRepository createHistoryRepository() { diff --git a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfig.java b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfig.java index 7983add7..6d93a194 100644 --- a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfig.java +++ b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/api/config/ElasticsearchEvolutionConfig.java @@ -41,7 +41,8 @@ public class ElasticsearchEvolutionConfig { /** * Line separator, used only temporary between reading raw migration file line-by-line and parsing it later. - * Only needed for backward compatibility / checksum stability! + *

+ * NOTE: Only needed for backward compatibility / checksum stability! *

* Should be one of * - '\n' (LF - Linux/Unix/OS X) @@ -103,6 +104,13 @@ public class ElasticsearchEvolutionConfig { */ private boolean validateOnMigrate = true; + /** + * Whether to remove a trailing newline in migration scripts. + *

+ * NOTE: This is only needed for backward compatibility / checksum stability! + */ + private boolean trimTrailingNewlineInMigrations = false; + /** * version to use as a baseline. * The baseline version will be the first one applied, the versions below will be ignored. @@ -295,6 +303,15 @@ public ElasticsearchEvolutionConfig setValidateOnMigrate(boolean validateOnMigra return this; } + public boolean isTrimTrailingNewlineInMigrations() { + return trimTrailingNewlineInMigrations; + } + + public ElasticsearchEvolutionConfig setTrimTrailingNewlineInMigrations(boolean trimTrailingNewlineInMigrations) { + this.trimTrailingNewlineInMigrations = trimTrailingNewlineInMigrations; + return this; + } + public String getBaselineVersion() { return baselineVersion; } @@ -330,6 +347,7 @@ public String toString() { ", historyIndex='" + historyIndex + '\'' + ", historyMaxQuerySize=" + historyMaxQuerySize + ", validateOnMigrate=" + validateOnMigrate + + ", trimTrailingNewlineInMigrations=" + trimTrailingNewlineInMigrations + ", baselineVersion='" + baselineVersion + '\'' + ", outOfOrder='" + outOfOrder + '\'' + '}'; diff --git a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImpl.java b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImpl.java index 8a622ebe..5d605fa1 100644 --- a/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImpl.java +++ b/elasticsearch-evolution-core/src/main/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImpl.java @@ -38,25 +38,28 @@ public class MigrationScriptReaderImpl implements MigrationScriptReader { private final String esMigrationPrefix; private final List esMigrationSuffixes; private final String lineSeparator; + private final boolean trimTrailingNewlineInMigrations; /** - * @param locations Locations of migrations scripts, e.g classpath:es/migration or file:/home/migration - * @param encoding migrations scripts encoding - * @param esMigrationFilePrefix File name prefix for ES migrations. - * @param esMigrationFileSuffixes File name suffix for ES migrations. - * @param lineSeparator Line separator. should be '\n' per default and only something else for backward compatibility / hash stability + * @param locations Locations of migrations scripts, e.g classpath:es/migration or file:/home/migration + * @param encoding migrations scripts encoding + * @param esMigrationFilePrefix File name prefix for ES migrations. + * @param esMigrationFileSuffixes File name suffix for ES migrations. + * @param lineSeparator Line separator. should be '\n' per default and only something else for backward compatibility / checksum stability + * @param trimTrailingNewlineInMigrations Whether to remove a trailing newline in migration scripts. */ - public MigrationScriptReaderImpl(List locations, Charset encoding, String esMigrationFilePrefix, List esMigrationFileSuffixes, - String lineSeparator) { + String lineSeparator, + boolean trimTrailingNewlineInMigrations) { this.locations = locations; this.encoding = encoding; this.esMigrationPrefix = esMigrationFilePrefix; this.esMigrationSuffixes = esMigrationFileSuffixes; this.lineSeparator = lineSeparator; + this.trimTrailingNewlineInMigrations = trimTrailingNewlineInMigrations; } /** @@ -164,6 +167,11 @@ Stream read(BufferedReader reader, String filename) throws I if (content.isEmpty()) { return Stream.empty(); } + + if (trimTrailingNewlineInMigrations && content.endsWith(lineSeparator)) { + content = content.substring(0, content.length() - lineSeparator.length()); + } + return Stream.of(new RawMigrationScript().setFileName(filename).setContent(content)); } diff --git a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java index ed7d9523..1e9db964 100644 --- a/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java +++ b/elasticsearch-evolution-core/src/test/java/com/senacor/elasticsearch/evolution/core/internal/migration/input/MigrationScriptReaderImplTest.java @@ -36,7 +36,7 @@ void nonJarFile() { singletonList("classpath:scriptreader"), StandardCharsets.UTF_8, "c", - singletonList(".http"), "\n"); + singletonList(".http"), "\n", false); List actual = reader.read(); assertThat(actual) .containsExactlyInAnyOrder( @@ -50,7 +50,7 @@ void inJarFile() { singletonList("classpath:META-INF"), StandardCharsets.UTF_8, "MANIFEST", - singletonList(".MF"), "\n"); + singletonList(".MF"), "\n", false); List res = reader.read(); @@ -67,7 +67,7 @@ void invalidClasspath() { singletonList(classpath), StandardCharsets.UTF_8, "c", - singletonList(".http"), "\n") { + singletonList(".http"), "\n", false) { @Override protected Stream readFromLocation(String location) throws URISyntaxException, IOException { throw new URISyntaxException("input", "reason"); @@ -85,7 +85,7 @@ void multipleSuffixes() { singletonList("classpath:scriptreader"), StandardCharsets.UTF_8, "c", - Arrays.asList(".http", ".other"), "\n"); + Arrays.asList(".http", ".other"), "\n", false); List actual = reader.read(); assertThat(actual) .containsExactlyInAnyOrder( @@ -100,7 +100,7 @@ void handlingDuplicates() { Arrays.asList("classpath:scriptreader", "classpath:scriptreader"), StandardCharsets.UTF_8, "c", - Arrays.asList(".http", ".other"), "\n"); + Arrays.asList(".http", ".other"), "\n", false); List actual = reader.read(); assertThat(actual) .containsExactlyInAnyOrder( @@ -115,7 +115,7 @@ void exclude_locations_with_suffix() { singletonList("classpath:scriptreader/issue36/location"), StandardCharsets.UTF_8, "c", - singletonList(".http"), "\n"); + singletonList(".http"), "\n", false); List actual = reader.read(); @@ -132,7 +132,7 @@ void handle_locations_with_suffix() { "classpath:scriptreader/issue36/location_with_suffix"), StandardCharsets.UTF_8, "c", - singletonList(".http"), "\n"); + singletonList(".http"), "\n", false); List actual = reader.read(); @@ -148,7 +148,7 @@ void include_trailing_newlines() { Arrays.asList("classpath:scriptreader/issue293_trailing_newlines"), StandardCharsets.UTF_8, "w", - singletonList(".http"), "\n"); + singletonList(".http"), "\n", false); List actual = reader.read(); @@ -163,7 +163,7 @@ void withWrongProtocol() { Arrays.asList("classpath:scriptreader", "http:scriptreader"), StandardCharsets.UTF_8, "c", - Arrays.asList(".http", ".other"), "\n"); + Arrays.asList(".http", ".other"), "\n", false); assertThatThrownBy(reader::read) .isInstanceOf(MigrationException.class) .hasMessage(""" @@ -183,7 +183,7 @@ void normalPath() throws URISyntaxException { singletonList("file:" + absolutePathToScriptreader), StandardCharsets.UTF_8, "c", - singletonList(".http"), "\n"); + singletonList(".http"), "\n", false); List actual = reader.read(); assertThat(actual) .containsExactlyInAnyOrder( @@ -199,7 +199,7 @@ void exclude_locations_with_suffix() throws URISyntaxException { singletonList("file:"+absolutePathToScriptreader+"/issue36/location"), StandardCharsets.UTF_8, "c", - singletonList(".http"), "\n"); + singletonList(".http"), "\n", false); List actual = reader.read(); @@ -218,7 +218,7 @@ void handle_locations_with_suffix() throws URISyntaxException { "file:"+absolutePathToScriptreader+"/issue36/location_with_suffix"), StandardCharsets.UTF_8, "c", - singletonList(".http"), "\n"); + singletonList(".http"), "\n", false); List actual = reader.read(); @@ -230,12 +230,12 @@ void handle_locations_with_suffix() throws URISyntaxException { @Test void invalidPath() { - assertThatThrownBy(() -> - new MigrationScriptReaderImpl( - singletonList("file:X:/snc/scripts"), - StandardCharsets.UTF_8, - "c", - singletonList(".http"), "\n").read()) + final MigrationScriptReaderImpl underTest = new MigrationScriptReaderImpl( + singletonList("file:X:/snc/scripts"), + StandardCharsets.UTF_8, + "c", + singletonList(".http"), "\n", false); + assertThatThrownBy(() -> underTest.read()) .isInstanceOf(MigrationException.class) .hasMessage("couldn't read scripts from file:X:/snc/scripts"); } @@ -245,12 +245,12 @@ void invalidPath() { void validAndInvalidPath() throws URISyntaxException { URL resourceDirectory = resolveURL("scriptreader"); String absolutePathToScriptreader = Paths.get(resourceDirectory.toURI()).toFile().getAbsolutePath(); - assertThatThrownBy(() -> - new MigrationScriptReaderImpl( - Arrays.asList("file:X:/snc/scripts", "file:" + absolutePathToScriptreader), - StandardCharsets.UTF_8, - "c", - singletonList(".http"), "\n").read()) + final MigrationScriptReaderImpl underTest = new MigrationScriptReaderImpl( + Arrays.asList("file:X:/snc/scripts", "file:" + absolutePathToScriptreader), + StandardCharsets.UTF_8, + "c", + singletonList(".http"), "\n", false); + assertThatThrownBy(() -> underTest.read()) .isInstanceOf(MigrationException.class) .hasMessage("couldn't read scripts from file:X:/snc/scripts"); } @@ -263,7 +263,7 @@ void validPathButNoFiles() throws URISyntaxException { singletonList("file:" + absolutePathToScriptreader), StandardCharsets.UTF_8, "d", - singletonList(".http"), "\n"); + singletonList(".http"), "\n", false); List actual = reader.read(); assertThat(actual).isEmpty(); } @@ -272,9 +272,9 @@ void validPathButNoFiles() throws URISyntaxException { @ParameterizedTest @ValueSource(strings = { - "foo\nbar", - "foo\r\nbar", - "foo\rbar" + "foo\nbar\n", + "foo\r\nbar\r\n", + "foo\rbar\r" }) void read_should_normalize_new_lines_to_defined_line_separator(String input) throws IOException { final String lineSeparator = ""; @@ -282,7 +282,34 @@ void read_should_normalize_new_lines_to_defined_line_separator(String input) thr singletonList("ignore"), StandardCharsets.UTF_8, "ignore", - singletonList(".ignore"), lineSeparator); + singletonList(".ignore"), + lineSeparator, + false); + + final Stream res; + try (BufferedReader bufferedReader = new BufferedReader(new StringReader(input))) { + res = reader.read(bufferedReader, "filename"); + } + + assertThat(res) + .containsExactlyInAnyOrder(new RawMigrationScript().setFileName("filename").setContent("foo" + lineSeparator + "bar" + lineSeparator)); + } + + @ParameterizedTest + @ValueSource(strings = { + "foo\nbar\n", + "foo\r\nbar\r\n", + "foo\rbar\r" + }) + void read_should_trim_trailing_newlines_if_config_is_set(String input) throws IOException { + final String lineSeparator = ""; + MigrationScriptReaderImpl reader = new MigrationScriptReaderImpl( + singletonList("ignore"), + StandardCharsets.UTF_8, + "ignore", + singletonList(".ignore"), + lineSeparator, + true); final Stream res; try (BufferedReader bufferedReader = new BufferedReader(new StringReader(input))) { @@ -290,7 +317,7 @@ void read_should_normalize_new_lines_to_defined_line_separator(String input) thr } assertThat(res) - .containsExactlyInAnyOrder(new RawMigrationScript().setFileName("filename").setContent("foo"+lineSeparator+"bar")); + .containsExactlyInAnyOrder(new RawMigrationScript().setFileName("filename").setContent("foo" + lineSeparator + "bar")); } private URL resolveURL(String path) { From 4d47f9c7d88d1269999c73b594ca35eeac82a5d3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 01:56:26 +0000 Subject: [PATCH 7/9] Bump org.openrewrite.recipe:rewrite-migrate-java from 2.13.0 to 2.14.0 Bumps [org.openrewrite.recipe:rewrite-migrate-java](https://github.com/openrewrite/rewrite-migrate-java) from 2.13.0 to 2.14.0. - [Release notes](https://github.com/openrewrite/rewrite-migrate-java/releases) - [Commits](https://github.com/openrewrite/rewrite-migrate-java/compare/v2.13.0...v2.14.0) --- updated-dependencies: - dependency-name: org.openrewrite.recipe:rewrite-migrate-java dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- tests/migration-scripts/pom.xml | 2 +- tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-3.1/pom.xml | 2 +- tests/test-spring-boot-3.2/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index eeae1ae5..9e8c1003 100644 --- a/pom.xml +++ b/pom.xml @@ -300,7 +300,7 @@ org.openrewrite.recipe rewrite-migrate-java - 2.13.0 + 2.14.0 diff --git a/tests/migration-scripts/pom.xml b/tests/migration-scripts/pom.xml index 73e81685..6b316c3c 100644 --- a/tests/migration-scripts/pom.xml +++ b/tests/migration-scripts/pom.xml @@ -29,7 +29,7 @@ org.openrewrite.recipe rewrite-migrate-java - 2.13.0 + 2.14.0 diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml index 24013620..5768f02b 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml @@ -121,7 +121,7 @@ org.openrewrite.recipe rewrite-migrate-java - 2.13.0 + 2.14.0 diff --git a/tests/test-spring-boot-3.1/pom.xml b/tests/test-spring-boot-3.1/pom.xml index 3b033964..4bf31c88 100644 --- a/tests/test-spring-boot-3.1/pom.xml +++ b/tests/test-spring-boot-3.1/pom.xml @@ -114,7 +114,7 @@ org.openrewrite.recipe rewrite-migrate-java - 2.13.0 + 2.14.0 diff --git a/tests/test-spring-boot-3.2/pom.xml b/tests/test-spring-boot-3.2/pom.xml index 9a78e7f7..46fc7d08 100644 --- a/tests/test-spring-boot-3.2/pom.xml +++ b/tests/test-spring-boot-3.2/pom.xml @@ -114,7 +114,7 @@ org.openrewrite.recipe rewrite-migrate-java - 2.13.0 + 2.14.0 From 87564fb0c122e904931d54ee0eb7a84f5347bc48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 01:56:33 +0000 Subject: [PATCH 8/9] Bump org.openrewrite.maven:rewrite-maven-plugin from 5.30.0 to 5.31.0 Bumps [org.openrewrite.maven:rewrite-maven-plugin](https://github.com/openrewrite/rewrite-maven-plugin) from 5.30.0 to 5.31.0. - [Release notes](https://github.com/openrewrite/rewrite-maven-plugin/releases) - [Commits](https://github.com/openrewrite/rewrite-maven-plugin/compare/v5.30.0...v5.31.0) --- updated-dependencies: - dependency-name: org.openrewrite.maven:rewrite-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- tests/migration-scripts/pom.xml | 2 +- tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-3.1/pom.xml | 2 +- tests/test-spring-boot-3.2/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index eeae1ae5..a1bc8957 100644 --- a/pom.xml +++ b/pom.xml @@ -290,7 +290,7 @@ org.openrewrite.maven rewrite-maven-plugin - 5.30.0 + 5.31.0 org.openrewrite.java.migrate.UpgradeToJava17 diff --git a/tests/migration-scripts/pom.xml b/tests/migration-scripts/pom.xml index 73e81685..756ea6d3 100644 --- a/tests/migration-scripts/pom.xml +++ b/tests/migration-scripts/pom.xml @@ -19,7 +19,7 @@ org.openrewrite.maven rewrite-maven-plugin - 5.30.0 + 5.31.0 org.openrewrite.java.migrate.UpgradeToJava17 diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml index 24013620..c48b08a9 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml @@ -111,7 +111,7 @@ org.openrewrite.maven rewrite-maven-plugin - 5.30.0 + 5.31.0 org.openrewrite.java.migrate.UpgradeToJava17 diff --git a/tests/test-spring-boot-3.1/pom.xml b/tests/test-spring-boot-3.1/pom.xml index 3b033964..82841ba7 100644 --- a/tests/test-spring-boot-3.1/pom.xml +++ b/tests/test-spring-boot-3.1/pom.xml @@ -104,7 +104,7 @@ org.openrewrite.maven rewrite-maven-plugin - 5.30.0 + 5.31.0 org.openrewrite.java.migrate.UpgradeToJava17 diff --git a/tests/test-spring-boot-3.2/pom.xml b/tests/test-spring-boot-3.2/pom.xml index 9a78e7f7..d0944e5d 100644 --- a/tests/test-spring-boot-3.2/pom.xml +++ b/tests/test-spring-boot-3.2/pom.xml @@ -104,7 +104,7 @@ org.openrewrite.maven rewrite-maven-plugin - 5.30.0 + 5.31.0 org.openrewrite.java.migrate.UpgradeToJava17 From 16845d0b006a9dbd8b9d3bebacdf2bdc5e527846 Mon Sep 17 00:00:00 2001 From: Andreas Keefer Date: Tue, 21 May 2024 19:41:33 +0200 Subject: [PATCH 9/9] prepare 0.6.0 release --- README.md | 6 +++--- elasticsearch-evolution-core/pom.xml | 2 +- pom.xml | 2 +- spring-boot-starter-elasticsearch-evolution/pom.xml | 2 +- tests/migration-scripts/pom.xml | 2 +- tests/pom.xml | 2 +- tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml | 2 +- tests/test-spring-boot-3.1/pom.xml | 2 +- tests/test-spring-boot-3.2/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 31488902..f7994a41 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ First add the latest version of Elasticsearch-Evolution spring boot starter as a com.senacor.elasticsearch.evolution spring-boot-starter-elasticsearch-evolution - 0.5.2 + 0.6.0 ``` @@ -73,7 +73,7 @@ First add the latest version of Elasticsearch-Evolution core as a dependency: com.senacor.elasticsearch.evolution elasticsearch-evolution-core - 0.5.2 + 0.6.0 ``` @@ -281,7 +281,7 @@ ElasticsearchEvolution.configure() ## 6 changelog -### v0.6.0-SNAPSHOT +### v0.6.0 - Added option to trim a trailing newline in migration scripts (fixes [#298](https://github.com/senacor/elasticsearch-evolution/issues/298)). NOTE: This option is only needed for backward compatibility / checksum stability! - The minimum supported Java version is now 17. diff --git a/elasticsearch-evolution-core/pom.xml b/elasticsearch-evolution-core/pom.xml index 79d1c417..d125c71b 100644 --- a/elasticsearch-evolution-core/pom.xml +++ b/elasticsearch-evolution-core/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.6.0-SNAPSHOT + 0.6.0 ../ elasticsearch-evolution-core diff --git a/pom.xml b/pom.xml index a62a102f..1ec7215c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.6.0-SNAPSHOT + 0.6.0 pom org.springframework.boot diff --git a/spring-boot-starter-elasticsearch-evolution/pom.xml b/spring-boot-starter-elasticsearch-evolution/pom.xml index f6e75ddb..398b40a9 100644 --- a/spring-boot-starter-elasticsearch-evolution/pom.xml +++ b/spring-boot-starter-elasticsearch-evolution/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.6.0-SNAPSHOT + 0.6.0 ../ spring-boot-starter-elasticsearch-evolution diff --git a/tests/migration-scripts/pom.xml b/tests/migration-scripts/pom.xml index 8a451f69..dbfb84f1 100644 --- a/tests/migration-scripts/pom.xml +++ b/tests/migration-scripts/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.senacor.elasticsearch.evolution migration-scripts - 0.6.0-SNAPSHOT + 0.6.0 jar containing migration files jar diff --git a/tests/pom.xml b/tests/pom.xml index 72fb6c17..0c376514 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -6,7 +6,7 @@ com.senacor.elasticsearch.evolution elasticsearch-evolution-parent - 0.6.0-SNAPSHOT + 0.6.0 ../ tests diff --git a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml index 2eeeb5c3..dfa8e16b 100644 --- a/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml +++ b/tests/test-spring-boot-3.0-scriptsInJarFile/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.0-scriptsInJarFile - 0.6.0-SNAPSHOT + 0.6.0 Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.1/pom.xml b/tests/test-spring-boot-3.1/pom.xml index 57aee671..8e2eccd7 100644 --- a/tests/test-spring-boot-3.1/pom.xml +++ b/tests/test-spring-boot-3.1/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.1 - 0.6.0-SNAPSHOT + 0.6.0 Demo project for Spring Boot diff --git a/tests/test-spring-boot-3.2/pom.xml b/tests/test-spring-boot-3.2/pom.xml index 275186c7..7483ce87 100644 --- a/tests/test-spring-boot-3.2/pom.xml +++ b/tests/test-spring-boot-3.2/pom.xml @@ -10,7 +10,7 @@ com.senacor.elasticsearch.evolution test-spring-boot-3.2 - 0.6.0-SNAPSHOT + 0.6.0 Demo project for Spring Boot