matrei commented on code in PR #16357:
URL: https://github.com/apache/grails-core/pull/16357#discussion_r4062203504


##########
grails-data-mongodb/core/src/test/groovy/org/apache/grails/data/mongo/core/GrailsDataMongoTckManager.groovy:
##########
@@ -168,6 +177,26 @@ class GrailsDataMongoTckManager extends 
GrailsDataTckManager {
         super.destroy()
     }
 
+    /**
+     * Removes the documents but keeps the collections and their indexes. The 
datastore of the next feature
+     * finds them in place, whereas dropping the database makes it create 
every collection and index again,
+     * and WiredTiger keeps the files of the dropped ones open until its next 
checkpoint.
+     */
+    private void clearDatabase(MongoDatabase database) {
+        for (String collectionName in database.listCollectionNames()) {
+            if (collectionName.startsWith('system.')) {
+                continue
+            }
+            try {
+                database.getCollection(collectionName).deleteMany(new 
Document())
+            }
+            catch (ignored) {
+                // e.g. capped collections do not support deletes
+                database.getCollection(collectionName).drop()

Review Comment:
   Covered in 467f3901b0, with one correction: capped collections never reach 
the fallback. They accept deletes since MongoDB 5.0, and a test that created 
one showed `deleteMany` succeeding on the `mongo:7.0.19` image used here. Views 
do reject deletes, so the comment now names them and the new feature `cleanup 
drops collections that do not support deletes` creates a view, runs 
`cleanup()`, and verifies the view is dropped while the `book` collection is 
kept and emptied.



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to