=== EDIT ===
在编辑内容之前,让我告诉您这个问题与Trying to create a mongodb collection in grails using mongodb plugin完全相同。但是,给出的解决方案对我不起作用,我工作的环境可能不同。所以,这个问题。
==========
我在通过mongo运行上限集合的测试时遇到以下上限集合相关错误。以下是我正在使用的软件版本:
==== EDIT =====
我有一个课程CappedCollectionCreator
如下:
class CappedCollectionCreator {
public void createCappedPublishedCollection(DBApiLayer db, String publishedCollectionName, String archiveCollectionName, int size, int max) {
if (db.collectionExists(publishedCollectionName)) {
def publishedCollection = db.getCollection(publishedCollectionName)
if (!publishedCollection.getStats().get("capped")) {
if (!db.collectionExists(archiveCollectionName)) {
def documents = publishedCollection.find().toArray()
if (documents.size() > 0) {
def archiveCollection = db.createCollection(archiveCollectionName, null)
archiveCollection.insert(publishedCollection.find().toArray())
}
}
def firstDocumentInserted = publishedCollection.find().sort(new BasicDBObject("createdOn", 1)).limit(1).toArray()
publishedCollection.drop()
db.createCollection(publishedCollectionName, BasicDBObjectBuilder.start().add("capped", true).add("size", size).add("max", max).get())
publishedCollection = db.getCollection(publishedCollectionName)
publishedCollection.insert(firstDocumentInserted)
}
} else {
db.createCollection(publishedCollectionName, BasicDBObjectBuilder.start().add("capped", true).add("size", size).add("max", max).get())
}
}
}
我遇到问题的代码位于以下代码段中:
@TestMixin(GroovyTestCase)
class CappedCollectionCreatorTests {
def mongo
def db
def mongoCollectionProcessor
def collectionName = "cappedCollectionTest"
def archiveName = "cappedCollectionTestArchive"
def collection, archiveCollection
@Before
void setUp() {
mongo = mongo.getMongo()
db = mongo.getDB("test")
mongoCollectionProcessor = new CappedCollectionCreator()
if (db.collectionExists(collectionName)) {
collection = db.getCollection(collectionName);
collection.drop();
}
if (db.collectionExists(archiveName)) {
archiveCollection = db.getCollection(archiveName);
archiveCollection.drop();
}
}
@Test
public void testShouldCreateCappedCollectionWhenDoesNotExist() {
mongoCollectionProcessor.createCappedPublishedCollection(db, collectionName, archiveName, 1000, 1)
assert db.collectionExists(collectionName) == true
assert db.collectionExists(archiveName) == false
assert db.getCollection(collectionName).isCapped() == true
}
}
==========
我通过互联网搜索并尝试大多数首次搜索,例如使用DBObject和Map可互换地将DBObject转换为Map等但似乎没有任何效果。
| Running 339 integration tests... 245 of 339
| Running 339 integration tests... 246 of 339
| Failure: testShouldCreateCappedCollectionWhenDoesNotExist(uk.co.o2.pm.manager.infrastructure.CappedCollectionCreatorTests)
| groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method com.mongodb.DBApiLayer#createCollection.
Cannot resolve which method to invoke for [class java.lang.String, class com.mongodb.BasicDBObject] due to overlapping prototypes between:
[class java.lang.String, interface com.mongodb.DBObject]
[class java.lang.String, interface java.util.Map]
at uk.co.o2.pm.manager.infrastructure.CappedCollectionCreator.createCappedPublishedCollection(CappedCollectionCreator.groovy:34)
at uk.co.o2.pm.manager.infrastructure.CappedCollectionCreatorTests.testShouldCreateCappedCollectionWhenDoesNotExist(CappedCollectionCreatorTests.groovy:43)
| Running 339 integration tests... 247 of 339
| Failure: testShouldNotCreateCappedCollectionWhenExists(uk.co.o2.pm.manager.infrastructure.CappedCollectionCreatorTests)
| groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method com.mongodb.DBApiLayer#createCollection.
Cannot resolve which method to invoke for [class java.lang.String, class com.mongodb.BasicDBObject] due to overlapping prototypes between:
[class java.lang.String, interface com.mongodb.DBObject]
[class java.lang.String, interface java.util.Map]
at uk.co.o2.pm.manager.infrastructure.CappedCollectionCreatorTests.testShouldNotCreateCappedCollectionWhenExists(CappedCollectionCreatorTests.groovy:54)
| Running 339 integration tests... 248 of 339
| Failure: testShouldCreateCappedCollectionAndArchiveWhenExistsNoCappedCollection(uk.co.o2.pm.manager.infrastructure.CappedCollectionCreatorTests)
| groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method com.mongodb.DBApiLayer#createCollection.
Cannot resolve which method to invoke for [class java.lang.String, null] due to overlapping prototypes between:
[class java.lang.String, interface com.mongodb.DBObject]
[class java.lang.String, interface java.util.Map]
at uk.co.o2.pm.manager.infrastructure.CappedCollectionCreatorTests.testShouldCreateCappedCollectionAndArchiveWhenExistsNoCappedCollection(CappedCollectionCreatorTests.groovy:70)
| Running 339 integration tests... 249 of 339
| Failure: testShouldCreateCappedCollectionAndNoArchiveWhenExistsEmptyNoCappedCollection(uk.co.o2.pm.manager.infrastructure.CappedCollectionCreatorTests)
| groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method com.mongodb.DBApiLayer#createCollection.
Cannot resolve which method to invoke for [class java.lang.String, null] due to overlapping prototypes between:
[class java.lang.String, interface com.mongodb.DBObject]
[class java.lang.String, interface java.util.Map]
at uk.co.o2.pm.manager.infrastructure.CappedCollectionCreatorTests.testShouldCreateCappedCollectionAndNoArchiveWhenExistsEmptyNoCappedCollection(CappedCollectionCreatorTests.groovy:90)
| Running 339 integration tests... 250 of 339
| Failure: testShouldCreateCappedCollectionAndNoArchiveWhenExistsNoCappedCollectionAndArchiveCollection(uk.co.o2.pm.manager.infrastructure.CappedCollectionCreatorTests)
| groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method com.mongodb.DBApiLayer#createCollection.
Cannot resolve which method to invoke for [class java.lang.String, null] due to overlapping prototypes between:
[class java.lang.String, interface com.mongodb.DBObject]
[class java.lang.String, interface java.util.Map]
at uk.co.o2.pm.manager.infrastructure.CappedCollectionCreatorTests.testShouldCreateCappedCollectionAndNoArchiveWhenExistsNoCappedCollectionAndArchiveCollection(CappedCollectionCreatorTests.groovy:103)
| Running 339 integration tests... 251 of 339
| Running 339 integration tests... 252 of 339
任何帮助都将不胜感激。
似乎是Mongo Groovy驱动程序无法动态制作方法签名的问题。有什么想法吗?