From 6762557f1ec4e0731aa8291d02b8e93ce91b966a Mon Sep 17 00:00:00 2001 From: fejera Date: Sun, 17 Nov 2019 15:04:03 +0100 Subject: [PATCH 1/7] added live-all profile to root pom --- pom.xml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pom.xml b/pom.xml index bc4c38f386..63561cb65e 100644 --- a/pom.xml +++ b/pom.xml @@ -1671,6 +1671,39 @@ + + + live-all + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/SpringContextTest.java + **/*UnitTest.java + **/*IntegrationTest.java + **/*IntTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/*JdbcTest.java + + + **/*LiveTest.java + + + + + + + + + + + + From ae8ef36227de957b2696acf94bb782941dcefe1a Mon Sep 17 00:00:00 2001 From: fejera Date: Sun, 17 Nov 2019 15:05:58 +0100 Subject: [PATCH 2/7] added live-test resources --- persistence-modules/spring-data-mongodb/live-test.sh | 11 +++++++++++ .../spring-data-mongodb/live-test/Dockerfile | 8 ++++++++ .../spring-data-mongodb/live-test/init-session.js | 1 + 3 files changed, 20 insertions(+) create mode 100755 persistence-modules/spring-data-mongodb/live-test.sh create mode 100644 persistence-modules/spring-data-mongodb/live-test/Dockerfile create mode 100644 persistence-modules/spring-data-mongodb/live-test/init-session.js diff --git a/persistence-modules/spring-data-mongodb/live-test.sh b/persistence-modules/spring-data-mongodb/live-test.sh new file mode 100755 index 0000000000..bb513a90bb --- /dev/null +++ b/persistence-modules/spring-data-mongodb/live-test.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +docker image build -t spring-data-mongodb:live-test live-test/ + +docker run -p 27017:27017 --name spring-data-mongodb-live-test -it spring-data-mongodb:live-test +#wait + +mvn clean compile test -P live-all + +docker stop spring-data-mongodb-live-test +docker rm spring-data-mongodb-live-test diff --git a/persistence-modules/spring-data-mongodb/live-test/Dockerfile b/persistence-modules/spring-data-mongodb/live-test/Dockerfile new file mode 100644 index 0000000000..9e3634feb0 --- /dev/null +++ b/persistence-modules/spring-data-mongodb/live-test/Dockerfile @@ -0,0 +1,8 @@ +FROM mongo:4.2.1 + +COPY init-session.js /docker-entrypoint-initdb.d/ + +EXPOSE 27017 + +HEALTHCHECK --interval=5s --timeout=3s --start-period=10s CMD mongo db.stats() +CMD ["mongod", "--replSet", "rs0"] diff --git a/persistence-modules/spring-data-mongodb/live-test/init-session.js b/persistence-modules/spring-data-mongodb/live-test/init-session.js new file mode 100644 index 0000000000..2e968884cc --- /dev/null +++ b/persistence-modules/spring-data-mongodb/live-test/init-session.js @@ -0,0 +1 @@ +rs.initiate(); From 23fb4ae451fef29cb5a81d486542e32cb4d5b979 Mon Sep 17 00:00:00 2001 From: fejera Date: Sun, 24 Nov 2019 12:42:59 +0100 Subject: [PATCH 3/7] cleaned up and documented live testing script usage --- persistence-modules/spring-data-mongodb/LIVE-TEST.md | 9 +++++++++ .../spring-data-mongodb/live-test-setup.sh | 5 +++++ .../spring-data-mongodb/live-test-teardown.sh | 4 ++++ persistence-modules/spring-data-mongodb/live-test.sh | 8 -------- 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 persistence-modules/spring-data-mongodb/LIVE-TEST.md create mode 100644 persistence-modules/spring-data-mongodb/live-test-setup.sh create mode 100644 persistence-modules/spring-data-mongodb/live-test-teardown.sh diff --git a/persistence-modules/spring-data-mongodb/LIVE-TEST.md b/persistence-modules/spring-data-mongodb/LIVE-TEST.md new file mode 100644 index 0000000000..9da1ea249e --- /dev/null +++ b/persistence-modules/spring-data-mongodb/LIVE-TEST.md @@ -0,0 +1,9 @@ +========= + +## Spring Data MongoDB Live Testing + + +There are 3 scripts to simplify running live tests: +1. `live-test-setup.sh` builds a docker image with the necessary setup and runs it. The environment is ready, when the log stops - it takes approximately 30 seconds. +2. `live-test.sh` runs the live tests (but no other tests). +3. `live-test-setup.sh` stops and removes the docker image. diff --git a/persistence-modules/spring-data-mongodb/live-test-setup.sh b/persistence-modules/spring-data-mongodb/live-test-setup.sh new file mode 100644 index 0000000000..37e6c48dbd --- /dev/null +++ b/persistence-modules/spring-data-mongodb/live-test-setup.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +docker image build -t spring-data-mongodb:live-test live-test/ + +docker run -p 27017:27017 --name spring-data-mongodb-live-test spring-data-mongodb:live-test diff --git a/persistence-modules/spring-data-mongodb/live-test-teardown.sh b/persistence-modules/spring-data-mongodb/live-test-teardown.sh new file mode 100644 index 0000000000..a29163bc7a --- /dev/null +++ b/persistence-modules/spring-data-mongodb/live-test-teardown.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +docker stop spring-data-mongodb-live-test +docker rm spring-data-mongodb-live-test diff --git a/persistence-modules/spring-data-mongodb/live-test.sh b/persistence-modules/spring-data-mongodb/live-test.sh index bb513a90bb..5a079bdac8 100755 --- a/persistence-modules/spring-data-mongodb/live-test.sh +++ b/persistence-modules/spring-data-mongodb/live-test.sh @@ -1,11 +1,3 @@ #!/bin/bash -docker image build -t spring-data-mongodb:live-test live-test/ - -docker run -p 27017:27017 --name spring-data-mongodb-live-test -it spring-data-mongodb:live-test -#wait - mvn clean compile test -P live-all - -docker stop spring-data-mongodb-live-test -docker rm spring-data-mongodb-live-test From 1afd7a40e20ba55edd147e2f95c873f46c3b8539 Mon Sep 17 00:00:00 2001 From: fejera Date: Mon, 2 Dec 2019 10:18:42 +0100 Subject: [PATCH 4/7] moved live test resources to src/live-test/resources --- persistence-modules/spring-data-mongodb/live-test-setup.sh | 2 +- .../{live-test => src/live-test/resources}/Dockerfile | 0 .../{live-test => src/live-test/resources}/init-session.js | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename persistence-modules/spring-data-mongodb/{live-test => src/live-test/resources}/Dockerfile (100%) rename persistence-modules/spring-data-mongodb/{live-test => src/live-test/resources}/init-session.js (100%) diff --git a/persistence-modules/spring-data-mongodb/live-test-setup.sh b/persistence-modules/spring-data-mongodb/live-test-setup.sh index 37e6c48dbd..e8e0437083 100644 --- a/persistence-modules/spring-data-mongodb/live-test-setup.sh +++ b/persistence-modules/spring-data-mongodb/live-test-setup.sh @@ -1,5 +1,5 @@ #!/bin/bash -docker image build -t spring-data-mongodb:live-test live-test/ +docker image build -t spring-data-mongodb:live-test src/live-test/resources/ docker run -p 27017:27017 --name spring-data-mongodb-live-test spring-data-mongodb:live-test diff --git a/persistence-modules/spring-data-mongodb/live-test/Dockerfile b/persistence-modules/spring-data-mongodb/src/live-test/resources/Dockerfile similarity index 100% rename from persistence-modules/spring-data-mongodb/live-test/Dockerfile rename to persistence-modules/spring-data-mongodb/src/live-test/resources/Dockerfile diff --git a/persistence-modules/spring-data-mongodb/live-test/init-session.js b/persistence-modules/spring-data-mongodb/src/live-test/resources/init-session.js similarity index 100% rename from persistence-modules/spring-data-mongodb/live-test/init-session.js rename to persistence-modules/spring-data-mongodb/src/live-test/resources/init-session.js From acf4fa5af9ad36f7273c11ee4be36dbe95434056 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 23 Apr 2020 22:18:45 +0200 Subject: [PATCH 5/7] JAVA-73: Move scripts under live-test-resources --- persistence-modules/spring-data-mongodb/LIVE-TEST.md | 9 --------- persistence-modules/spring-data-mongodb/README.md | 9 +++++++++ .../{ => src/live-test/resources}/live-test-setup.sh | 2 +- .../{ => src/live-test/resources}/live-test-teardown.sh | 0 .../{ => src/live-test/resources}/live-test.sh | 0 5 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 persistence-modules/spring-data-mongodb/LIVE-TEST.md rename persistence-modules/spring-data-mongodb/{ => src/live-test/resources}/live-test-setup.sh (58%) rename persistence-modules/spring-data-mongodb/{ => src/live-test/resources}/live-test-teardown.sh (100%) rename persistence-modules/spring-data-mongodb/{ => src/live-test/resources}/live-test.sh (100%) mode change 100755 => 100644 diff --git a/persistence-modules/spring-data-mongodb/LIVE-TEST.md b/persistence-modules/spring-data-mongodb/LIVE-TEST.md deleted file mode 100644 index 9da1ea249e..0000000000 --- a/persistence-modules/spring-data-mongodb/LIVE-TEST.md +++ /dev/null @@ -1,9 +0,0 @@ -========= - -## Spring Data MongoDB Live Testing - - -There are 3 scripts to simplify running live tests: -1. `live-test-setup.sh` builds a docker image with the necessary setup and runs it. The environment is ready, when the log stops - it takes approximately 30 seconds. -2. `live-test.sh` runs the live tests (but no other tests). -3. `live-test-setup.sh` stops and removes the docker image. diff --git a/persistence-modules/spring-data-mongodb/README.md b/persistence-modules/spring-data-mongodb/README.md index c4f21dffc0..381bf83fa8 100644 --- a/persistence-modules/spring-data-mongodb/README.md +++ b/persistence-modules/spring-data-mongodb/README.md @@ -13,3 +13,12 @@ - [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) - [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions ) - [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) + + +## Spring Data MongoDB Live Testing + + +There are 3 scripts to simplify running live tests: +1. [`live-test-setup.sh`](src/live-test/resources/live-test-setup.sh) builds a docker image with the necessary setup and runs it. The environment is ready, when the log stops - it takes approximately 30 seconds. +2. [`live-test.sh`](src/live-test/resources/live-test.sh) runs the live tests (but no other tests). +3. [`live-test-teardown.sh`](src/live-test/resources/live-test-teardown.sh) stops and removes the docker image. diff --git a/persistence-modules/spring-data-mongodb/live-test-setup.sh b/persistence-modules/spring-data-mongodb/src/live-test/resources/live-test-setup.sh similarity index 58% rename from persistence-modules/spring-data-mongodb/live-test-setup.sh rename to persistence-modules/spring-data-mongodb/src/live-test/resources/live-test-setup.sh index e8e0437083..78968d51aa 100644 --- a/persistence-modules/spring-data-mongodb/live-test-setup.sh +++ b/persistence-modules/spring-data-mongodb/src/live-test/resources/live-test-setup.sh @@ -1,5 +1,5 @@ #!/bin/bash -docker image build -t spring-data-mongodb:live-test src/live-test/resources/ +docker image build -t spring-data-mongodb:live-test . docker run -p 27017:27017 --name spring-data-mongodb-live-test spring-data-mongodb:live-test diff --git a/persistence-modules/spring-data-mongodb/live-test-teardown.sh b/persistence-modules/spring-data-mongodb/src/live-test/resources/live-test-teardown.sh similarity index 100% rename from persistence-modules/spring-data-mongodb/live-test-teardown.sh rename to persistence-modules/spring-data-mongodb/src/live-test/resources/live-test-teardown.sh diff --git a/persistence-modules/spring-data-mongodb/live-test.sh b/persistence-modules/spring-data-mongodb/src/live-test/resources/live-test.sh old mode 100755 new mode 100644 similarity index 100% rename from persistence-modules/spring-data-mongodb/live-test.sh rename to persistence-modules/spring-data-mongodb/src/live-test/resources/live-test.sh From ffa8e0839df894019e1b3cc501728c9c0f5d9aa6 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 23 Apr 2020 22:38:10 +0200 Subject: [PATCH 6/7] JAVA-73: Fix live-test.sh and cleanup pom.xml --- .../spring-data-mongodb/src/live-test/resources/live-test.sh | 2 +- pom.xml | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/persistence-modules/spring-data-mongodb/src/live-test/resources/live-test.sh b/persistence-modules/spring-data-mongodb/src/live-test/resources/live-test.sh index 5a079bdac8..307a68a3bd 100644 --- a/persistence-modules/spring-data-mongodb/src/live-test/resources/live-test.sh +++ b/persistence-modules/spring-data-mongodb/src/live-test/resources/live-test.sh @@ -1,3 +1,3 @@ #!/bin/bash -mvn clean compile test -P live-all +mvn clean compile test -P live-all -f ../../../pom.xml diff --git a/pom.xml b/pom.xml index f94c89a5c0..314a6a9f43 100644 --- a/pom.xml +++ b/pom.xml @@ -1341,10 +1341,7 @@ - - - - + From d2f60283b8eb3d8633f2bcb5eda3fc69fbff330c Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 26 Apr 2020 15:46:04 +0200 Subject: [PATCH 7/7] JAVA-73: Remove unused test methods --- .../MongoTransactionalLiveTest.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionalLiveTest.java b/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionalLiveTest.java index bafcd770ec..6cd9657006 100644 --- a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionalLiveTest.java +++ b/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionalLiveTest.java @@ -62,24 +62,6 @@ public class MongoTransactionalLiveTest { } } - @Test(expected = MongoCommandException.class) - @Transactional - public void whenCountDuringMongoTransaction_thenException() { - userRepository.save(new User("John", 30)); - userRepository.save(new User("Ringo", 35)); - userRepository.count(); - } - - @Test - @Transactional - public void whenQueryDuringMongoTransaction_thenSuccess() { - userRepository.save(new User("Jane", 20)); - userRepository.save(new User("Nick", 33)); - List users = mongoTemplate.find(new Query(), User.class); - - assertTrue(users.size() > 1); - } - // ==== Using test instead of before and after due to @transactional doesn't allow list collection @Test