Skip to content

Commit

Permalink
Merge pull request #26011 from evanchooly/mdbClientDevServices
Browse files Browse the repository at this point in the history
Enable dev services for all named mongodb-client connections
  • Loading branch information
evanchooly authored Jun 30, 2022
2 parents b8eb028 + db6e5c0 commit f150b14
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ public List<DevServicesResultBuildItem> startMongo(List<MongoConnectionNameBuild
connectionNames.add(mongoConnection.getName());
}

// TODO: handle named connections as well
if (connectionNames.size() != 1) {
return null;
}
if (!isDefault(connectionNames.get(0))) {
return null;
}

Map<String, CapturedProperties> currentCapturedProperties = captureProperties(connectionNames,
mongoClientBuildTimeConfig);

Expand All @@ -93,26 +85,24 @@ public List<DevServicesResultBuildItem> startMongo(List<MongoConnectionNameBuild

List<RunningDevService> newDevServices = new ArrayList<>(mongoConnections.size());

// TODO: we need to go through each connection
String connectionName = connectionNames.get(0);
RunningDevService devService;
StartupLogCompressor compressor = new StartupLogCompressor(
(launchMode.isTest() ? "(test) " : "") + "Mongo Dev Services Starting:", consoleInstalledBuildItem,
loggingSetupBuildItem);
try {
devService = startMongo(dockerStatusBuildItem, connectionName, currentCapturedProperties.get(connectionName),
!devServicesSharedNetworkBuildItem.isEmpty(), globalDevServicesConfig.timeout);
if (devService == null) {
for (String connectionName : connectionNames) {
RunningDevService devService;
StartupLogCompressor compressor = new StartupLogCompressor(
(launchMode.isTest() ? "(test) " : "") + "Mongo Dev Services Starting:", consoleInstalledBuildItem,
loggingSetupBuildItem);
try {
devService = startMongo(dockerStatusBuildItem, connectionName, currentCapturedProperties.get(connectionName),
!devServicesSharedNetworkBuildItem.isEmpty(), globalDevServicesConfig.timeout);
if (devService == null) {
compressor.closeAndDumpCaptured();
} else {
compressor.close();
newDevServices.add(devService);
}
} catch (Throwable t) {
compressor.closeAndDumpCaptured();
} else {
compressor.close();
throw new RuntimeException(t);
}
} catch (Throwable t) {
compressor.closeAndDumpCaptured();
throw new RuntimeException(t);
}
if (devService != null) {
newDevServices.add(devService);
}

if (first) {
Expand Down
26 changes: 20 additions & 6 deletions integration-tests/mongodb-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
Expand All @@ -120,5 +114,25 @@
</plugins>
</build>

<profiles>
<profile>
<id>no-windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,68 @@
import javax.ws.rs.*;
import javax.ws.rs.core.Response;

import com.mongodb.WriteConcern;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;

import io.quarkus.mongodb.MongoClientName;
import io.smallrye.common.annotation.Blocking;

@Path("/books")
@Blocking
public class BookResource {

@Inject
@MongoClientName("parameter-injection")
MongoClient client;

@Inject
@MongoClientName("dev-services")
MongoClient devServiced;
@Inject
@MongoClientName("dev-services2")
MongoClient devServiced2;

private MongoCollection<Book> getCollection() {
return client.getDatabase("books").getCollection("my-collection", Book.class);
}

private MongoCollection<Book> getServicedCollection() {
return devServiced.getDatabase("books").getCollection("my-collection", Book.class);
}

private MongoCollection<Book> getServiced2Collection() {
return devServiced.getDatabase("books").getCollection("my-collection", Book.class);
}

@GET
public List<Book> getBooks() {
FindIterable<Book> iterable = getCollection().find();
List<Book> books = new ArrayList<>();
for (Book doc : iterable) {
books.add(doc);
WriteConcern writeConcern = client.getDatabase("temp").getWriteConcern();
// force a test failure if we're not getting the correct, and correctly configured named mongodb client
if (Boolean.TRUE.equals(writeConcern.getJournal())) {
for (Book doc : iterable) {
books.add(doc);
}
}
return books;
}

@POST
public Response addBook(Book book) {
getCollection().insertOne(book);
getServicedCollection().insertOne(book);
getServiced2Collection().insertOne(book);
return Response.accepted().build();
}

@GET
@Path("/{author}")
public List<Book> getBooksByAuthor(@PathParam("author") String author) {
getServicedCollection().find(eq("author", author));
getServiced2Collection().find(eq("author", author));
FindIterable<Book> iterable = getCollection().find(eq("author", author));
List<Book> books = new ArrayList<>();
for (Book doc : iterable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
quarkus.mongodb.connection-string=mongodb://localhost:27017
quarkus.mongodb.write-concern.journal=false
quarkus.mongodb.parameter-injection.connection-string=mongodb://localhost:27017
quarkus.mongodb.parameter-injection.write-concern.journal=false
quarkus.mongodb.parameter-injection.write-concern.journal=true

quarkus.mongodb.dev-services.write-concern.journal=false
quarkus.mongodb.dev-services2.write-concern.journal=false

0 comments on commit f150b14

Please sign in to comment.