Skip to content

Commit

Permalink
Merge pull request #29638 from geoand/mongodb-panache-it-rr
Browse files Browse the repository at this point in the history
Move mongodb-panache ITs to RESTEasy Reactive
  • Loading branch information
jponge authored Dec 2, 2022
2 parents 71e0df3 + b3d8eae commit 0a9755a
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 75 deletions.
25 changes: 4 additions & 21 deletions integration-tests/mongodb-panache-kotlin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-panache-kotlin</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
<artifactId>quarkus-rest-client-reactive</artifactId>
</dependency>

<dependency>
Expand Down Expand Up @@ -112,20 +108,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson-deployment</artifactId>
<artifactId>quarkus-rest-client-reactive-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -138,7 +121,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny-deployment</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.quarkus.panache.common.Sort
import io.smallrye.mutiny.Uni
import org.bson.types.ObjectId
import org.jboss.logging.Logger
import org.jboss.resteasy.annotations.SseElementType
import org.jboss.resteasy.reactive.RestStreamElementType
import org.reactivestreams.Publisher
import java.net.URI
import java.time.LocalDate.parse
Expand Down Expand Up @@ -42,7 +42,7 @@ class ReactiveBookEntityResource {
@GET
@Path("/stream")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.APPLICATION_JSON)
@RestStreamElementType(MediaType.APPLICATION_JSON)
fun streamBooks(@QueryParam("sort") sort: String?): Publisher<ReactiveBookEntity> {
return if (sort != null) {
ReactiveBookEntity.streamAll(Sort.ascending(sort))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.quarkus.panache.common.Sort
import io.smallrye.mutiny.Uni
import org.bson.types.ObjectId
import org.jboss.logging.Logger
import org.jboss.resteasy.annotations.SseElementType
import org.jboss.resteasy.reactive.RestStreamElementType
import org.reactivestreams.Publisher
import java.net.URI
import java.time.LocalDate
Expand Down Expand Up @@ -47,7 +47,7 @@ class ReactiveBookRepositoryResource {
@GET
@Path("/stream")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.APPLICATION_JSON)
@RestStreamElementType(MediaType.APPLICATION_JSON)
fun streamBooks(@QueryParam("sort") sort: String?): Publisher<Book> {
return if (sort != null) {
reactiveBookRepository.streamAll(Sort.ascending(sort))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import java.util.Calendar
import java.util.Collections
import java.util.Date
import java.util.GregorianCalendar
import java.util.concurrent.atomic.LongAdder
import javax.ws.rs.client.Client
import javax.ws.rs.client.ClientBuilder
import javax.ws.rs.client.WebTarget
Expand Down Expand Up @@ -194,7 +195,7 @@ internal open class ReactiveMongodbPanacheResourceTest {
val client: Client = ClientBuilder.newClient()
val target: WebTarget = client.target("http://localhost:8081$endpoint/stream")
SseEventSource.target(target).build().use { source ->
val nbEvent = IntegerAdder()
val nbEvent = LongAdder()
source.register { inboundSseEvent ->
try {
val theBook: BookDTO = objectMapper.readValue(inboundSseEvent.readData(), BookDTO::class.java)
Expand All @@ -205,7 +206,7 @@ internal open class ReactiveMongodbPanacheResourceTest {
nbEvent.increment()
}
source.open()
await().atMost(Duration.ofSeconds(10)).until({ nbEvent.count() == 3 })
await().atMost(Duration.ofSeconds(10)).until({ nbEvent.sum() == 3L })
}

// delete all
Expand Down Expand Up @@ -337,15 +338,6 @@ internal open class ReactiveMongodbPanacheResourceTest {
return cal.getTime()
}

private class IntegerAdder {
var cpt = 0
fun increment() {
cpt++
}

fun count(): Int = cpt
}

@Test
fun testMoreEntityFunctionalities() {
get("/test/reactive/entity").then().statusCode(200)
Expand Down
25 changes: 4 additions & 21 deletions integration-tests/mongodb-panache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
<artifactId>quarkus-rest-client-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -95,20 +91,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson-deployment</artifactId>
<artifactId>quarkus-rest-client-reactive-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -121,7 +104,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny-deployment</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import org.bson.types.ObjectId;
import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.SseElementType;
import org.jboss.resteasy.reactive.RestStreamElementType;
import org.reactivestreams.Publisher;

import io.quarkus.panache.common.Parameters;
Expand Down Expand Up @@ -40,7 +40,7 @@ public Uni<List<ReactiveBookEntity>> getBooks(@QueryParam("sort") String sort) {
@GET
@Path("/stream")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.APPLICATION_JSON)
@RestStreamElementType(MediaType.APPLICATION_JSON)
public Publisher<ReactiveBookEntity> streamBooks(@QueryParam("sort") String sort) {
if (sort != null) {
return ReactiveBookEntity.streamAll(Sort.ascending(sort));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import org.bson.types.ObjectId;
import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.SseElementType;
import org.jboss.resteasy.reactive.RestStreamElementType;
import org.reactivestreams.Publisher;

import io.quarkus.it.mongodb.panache.book.Book;
Expand Down Expand Up @@ -44,7 +44,7 @@ public Uni<List<Book>> getBooks(@QueryParam("sort") String sort) {
@GET
@Path("/stream")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.APPLICATION_JSON)
@RestStreamElementType(MediaType.APPLICATION_JSON)
public Publisher<Book> streamBooks(@QueryParam("sort") String sort) {
if (sort != null) {
return reactiveBookRepository.streamAll(Sort.ascending(sort));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.concurrent.atomic.LongAdder;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
Expand Down Expand Up @@ -197,7 +198,7 @@ private void callReactiveBookEndpoint(String endpoint) throws InterruptedExcepti
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8081" + endpoint + "/stream");
try (SseEventSource source = SseEventSource.target(target).build()) {
final IntegerAdder nbEvent = new IntegerAdder();
final LongAdder nbEvent = new LongAdder();
source.register((inboundSseEvent) -> {
try {
BookDTO theBook = objectMapper.readValue(inboundSseEvent.readData(), BookDTO.class);
Expand All @@ -208,7 +209,7 @@ private void callReactiveBookEndpoint(String endpoint) throws InterruptedExcepti
nbEvent.increment();
});
source.open();
await().atMost(Duration.ofSeconds(10)).until(() -> nbEvent.count() == 3);
await().atMost(Duration.ofSeconds(10)).until(() -> nbEvent.sum() == 3);
}

//delete all
Expand Down Expand Up @@ -343,18 +344,6 @@ private Date yearToDate(int year) {
return cal.getTime();
}

private static class IntegerAdder {
int cpt = 0;

public void increment() {
cpt++;
}

public int count() {
return cpt;
}
}

@Test
public void testMoreEntityFunctionalities() {
get("/test/reactive/entity").then().statusCode(200);
Expand Down

0 comments on commit 0a9755a

Please sign in to comment.