diff --git a/ci/smoke-tests.yml b/ci/smoke-tests.yml index 0fe67b42..8bd21c48 100644 --- a/ci/smoke-tests.yml +++ b/ci/smoke-tests.yml @@ -13,6 +13,7 @@ smoke_tests: - data-jdbc - data-jpa - data-mongodb + - data-mongodb-reactive - data-r2dbc - data-redis - event-listener diff --git a/data-mongodb-reactive/README.adoc b/data-mongodb-reactive/README.adoc new file mode 100644 index 00000000..885ec4be --- /dev/null +++ b/data-mongodb-reactive/README.adoc @@ -0,0 +1 @@ +Tests if Spring Data MongoDB Reactive works diff --git a/data-mongodb-reactive/build.gradle b/data-mongodb-reactive/build.gradle new file mode 100644 index 00000000..ecbbaf57 --- /dev/null +++ b/data-mongodb-reactive/build.gradle @@ -0,0 +1,16 @@ +plugins { + id 'java' + id 'org.springframework.boot' + id 'org.springframework.aot.smoke-test' + id 'org.graalvm.buildtools.native' +} + +dependencies { + implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + aotTestImplementation(project(":aot-smoke-test-support")) + aotTestImplementation("org.awaitility:awaitility:4.2.0") +} diff --git a/data-mongodb-reactive/docker-compose.yml b/data-mongodb-reactive/docker-compose.yml new file mode 100644 index 00000000..fdac667c --- /dev/null +++ b/data-mongodb-reactive/docker-compose.yml @@ -0,0 +1,6 @@ +version: '3.1' +services: + mongo: + image: 'mongo:5' + ports: + - 27017 diff --git a/data-mongodb-reactive/src/aotTest/java/com/example/data/mongodb/reactive/DataMongoDbReactiveApplicationAotTests.java b/data-mongodb-reactive/src/aotTest/java/com/example/data/mongodb/reactive/DataMongoDbReactiveApplicationAotTests.java new file mode 100644 index 00000000..460804f0 --- /dev/null +++ b/data-mongodb-reactive/src/aotTest/java/com/example/data/mongodb/reactive/DataMongoDbReactiveApplicationAotTests.java @@ -0,0 +1,33 @@ +package com.example.data.mongodb.reactive; + +import java.time.Duration; + +import org.awaitility.Awaitility; +import org.junit.jupiter.api.Test; + +import org.springframework.aot.smoketest.support.assertj.AssertableOutput; +import org.springframework.aot.smoketest.support.junit.AotSmokeTest; + +import static org.assertj.core.api.Assertions.assertThat; + +@AotSmokeTest +class DataMongoDbReactiveApplicationAotTests { + + @Test + void findAll(AssertableOutput output) { + Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> { + assertThat(output).hasSingleLineContaining("findAll(): Person{firstname='first-1', lastname='last-1'}") + .hasSingleLineContaining("findAll(): Person{firstname='first-2', lastname='last-2'}") + .hasSingleLineContaining("findAll(): Person{firstname='first-3', lastname='last-3'}"); + }); + } + + @Test + void findByLastName(AssertableOutput output) { + Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> { + assertThat(output) + .hasSingleLineContaining("findByLastname(): Person{firstname='first-3', lastname='last-3'}"); + }); + } + +} diff --git a/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/CLR.java b/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/CLR.java new file mode 100644 index 00000000..069765d2 --- /dev/null +++ b/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/CLR.java @@ -0,0 +1,30 @@ +package com.example.data.mongodb.reactive; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +@Component +class CLR implements CommandLineRunner { + + private final PersonRepository personRepository; + + CLR(PersonRepository personRepository) { + this.personRepository = personRepository; + } + + @Override + public void run(String... args) { + this.personRepository.save(new Person("first-1", "last-1")).block(); + this.personRepository.save(new Person("first-2", "last-2")).block(); + this.personRepository.save(new Person("first-3", "last-3")).block(); + + this.personRepository.findAll().subscribe((person) -> { + System.out.printf("findAll(): %s%n", person); + }, ex -> ex.printStackTrace(System.out)); + + this.personRepository.findByLastname("last-3").subscribe((person) -> { + System.out.printf("findByLastname(): %s%n", person); + }, ex -> ex.printStackTrace(System.out)); + } + +} diff --git a/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/DataMongoDbReactiveApplication.java b/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/DataMongoDbReactiveApplication.java new file mode 100644 index 00000000..5c85d6ad --- /dev/null +++ b/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/DataMongoDbReactiveApplication.java @@ -0,0 +1,14 @@ +package com.example.data.mongodb.reactive; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataMongoDbReactiveApplication { + + public static void main(String[] args) throws InterruptedException { + SpringApplication.run(DataMongoDbReactiveApplication.class, args); + Thread.currentThread().join(); // To be able to measure memory consumption + } + +} diff --git a/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/Person.java b/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/Person.java new file mode 100644 index 00000000..16c2755f --- /dev/null +++ b/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/Person.java @@ -0,0 +1,55 @@ +package com.example.data.mongodb.reactive; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.index.Indexed; +import org.springframework.data.mongodb.core.mapping.Document; + +@Document +public class Person { + + @Id + private String id; + + private String firstname; + + @Indexed + private String lastname; + + public Person() { + } + + public Person(String firstname, String lastname) { + this.firstname = firstname; + this.lastname = lastname; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + public String getLastname() { + return lastname; + } + + public void setLastname(String lastname) { + this.lastname = lastname; + } + + @Override + public String toString() { + return "Person{" + "firstname='" + firstname + '\'' + ", lastname='" + lastname + '\'' + '}'; + } + +} diff --git a/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/PersonRepository.java b/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/PersonRepository.java new file mode 100644 index 00000000..11fbded8 --- /dev/null +++ b/data-mongodb-reactive/src/main/java/com/example/data/mongodb/reactive/PersonRepository.java @@ -0,0 +1,11 @@ +package com.example.data.mongodb.reactive; + +import reactor.core.publisher.Flux; + +import org.springframework.data.repository.reactive.ReactiveCrudRepository; + +public interface PersonRepository extends ReactiveCrudRepository { + + Flux findByLastname(String lastname); + +} diff --git a/data-mongodb-reactive/src/main/resources/application.properties b/data-mongodb-reactive/src/main/resources/application.properties new file mode 100644 index 00000000..377c6940 --- /dev/null +++ b/data-mongodb-reactive/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.data.mongodb.host=${MONGO_HOST:localhost} +spring.data.mongodb.port=${MONGO_PORT_27017:27017} diff --git a/data-mongodb-reactive/src/test/java/com/example/data/mongodb/reactive/DataMongoDbReactiveApplicationTests.java b/data-mongodb-reactive/src/test/java/com/example/data/mongodb/reactive/DataMongoDbReactiveApplicationTests.java new file mode 100644 index 00000000..6b848733 --- /dev/null +++ b/data-mongodb-reactive/src/test/java/com/example/data/mongodb/reactive/DataMongoDbReactiveApplicationTests.java @@ -0,0 +1,14 @@ +package com.example.data.mongodb.reactive; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DataMongoDbReactiveApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/settings.gradle b/settings.gradle index 0b4e9bc8..42ee405e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -41,6 +41,7 @@ include "configuration-properties" include "data-jdbc" include "data-jpa" include "data-mongodb" +include "data-mongodb-reactive" include "data-r2dbc" include "data-redis" include "event-listener"