JiriOndrusek commented on a change in pull request #2642:
URL: https://github.com/apache/camel-quarkus/pull/2642#discussion_r636765297



##########
File path: 
integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTestResource.java
##########
@@ -55,12 +76,44 @@
         }
     }
 
+    void setUpDb() {
+        final String mongoUrl = "mongodb://" + 
container.getContainerIpAddress() + ":"
+                + container.getMappedPort(MONGODB_PORT).toString();
+
+        if (mongoUrl != null) {
+            mongoClient = MongoClients.create(mongoUrl);
+        }
+        org.junit.Assume.assumeTrue(mongoClient != null);
+
+        db = mongoClient.getDatabase("test");
+        db.createCollection(MongoDbRoute.COLLECTION_TAILING,
+                new 
CreateCollectionOptions().capped(true).sizeInBytes(1000000000).maxDocuments(MongoDbTest.CAP_NUMBER));
+        db.createCollection(MongoDbRoute.COLLECTION_PERSISTENT_TAILING,
+                new 
CreateCollectionOptions().capped(true).sizeInBytes(1000000000).maxDocuments(MongoDbTest.CAP_NUMBER));
+        db.createCollection(MongoDbRoute.COLLECTION_STREAM_CHANGES);
+    }
+
+    private void execScriptInContainer(String script) throws Exception {
+        String cmd = IOUtils.toString(getClass().getResource("/" + script), 
StandardCharsets.UTF_8);
+        String[] cmds = cmd.split("\\n\\n");
+
+        for (int i = 0; i < cmds.length; i++) {
+            Container.ExecResult er = container.execInContainer(new String[] { 
"mongo", "--eval", cmds[i] });
+            if (er.getExitCode() != 0) {
+                throw new IllegalStateException("Exec exit code " + 
er.getExitCode() + ". " + er.getStderr());
+            }
+        }
+    }
+
     @Override
     public void stop() {
         try {
             if (container != null) {
                 container.stop();
             }
+            if (mongoClient != null) {
+                mongoClient.close();

Review comment:
       you are right, there is no need to keep client alive for the whole test




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to