Merge pull request #9169 from kwoyke/JAVA-73
JAVA-73: Wrap up running Live Tests with Docker
This commit is contained in:
commit
068523493b
|
@ -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.
|
||||
|
|
|
@ -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"]
|
|
@ -0,0 +1 @@
|
|||
rs.initiate();
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
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
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
docker stop spring-data-mongodb-live-test
|
||||
docker rm spring-data-mongodb-live-test
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
mvn clean compile test -P live-all -f ../../../pom.xml
|
|
@ -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<User> 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
|
||||
|
|
30
pom.xml
30
pom.xml
|
@ -1319,6 +1319,36 @@
|
|||
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>live-all</id>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/SpringContextTest.java</exclude>
|
||||
<exclude>**/*UnitTest.java</exclude>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*IntTest.java</exclude>
|
||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
<exclude>**/*JdbcTest.java</exclude>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/*LiveTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
|
||||
<reporting>
|
||||
|
|
Loading…
Reference in New Issue