bito-code-review[bot] commented on PR #16357:
URL: https://github.com/apache/grails-core/pull/16357#issuecomment-5760020663

   <!-- Bito Reply -->
   To test the fallback mechanism for capped collections, you can add a test 
case to `GrailsDataMongoTckManagerSpec.groovy` that explicitly creates a capped 
collection, populates it, and then triggers the cleanup process. This ensures 
that the `clearDatabase` method correctly handles the `deleteMany` failure by 
falling back to `drop()` for the capped collection while allowing standard 
collections to be cleared via `deleteMany`.
   
   Here is a suggested test snippet to add to your specification:
   
   ```groovy
   def "cleanup should drop capped collections"() {
       given:
       def db = mongoDatastore.mongoClient.getDatabase("testDb")
       db.createCollection("cappedCollection", new 
com.mongodb.client.model.CreateCollectionOptions().capped(true).sizeInBytes(1024))
       db.getCollection("normalCollection").insertOne(new Document("key", 
"value"))
   
       when:
       // Trigger the cleanup logic defined in GrailsDataMongoTckManager
       tckManager.clearDatabase(db)
   
       then:
       !db.listCollectionNames().contains("cappedCollection")
       db.getCollection("normalCollection").countDocuments() == 0
   }
   ```
   
   
**grails-data-mongodb/core/src/test/groovy/org/apache/grails/data/mongo/core/GrailsDataMongoTckManagerSpec.groovy**
   ```
   def "cleanup should drop capped collections"() {
           given:
           def db = mongoDatastore.mongoClient.getDatabase("testDb")
           db.createCollection("cappedCollection", new 
com.mongodb.client.model.CreateCollectionOptions().capped(true).sizeInBytes(1024))
           db.getCollection("normalCollection").insertOne(new Document("key", 
"value"))
   
           when:
           tckManager.clearDatabase(db)
   
           then:
           !db.listCollectionNames().contains("cappedCollection")
           db.getCollection("normalCollection").countDocuments() == 0
       }
   ```


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