-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test Collection API on deleted database #114
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs some cleanup. Couple specific requests here; overview in Slack
@Test | ||
fun testAddChangeListenerToCollectionInDeletedDatabase() { | ||
deleteDb(baseTestDb) | ||
testCollection.addChangeListener(testSerialExecutor) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prolly leave the explicit executor out. I think it is irrelevant...
// Test that addDocumentChangeListener to a collection in a deleted database doesn't throw an exception | ||
@Test | ||
fun testAddDocumentChangeListenerToCollectionInDeletedDatabase() { | ||
val docID = "testDoc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to save a doc, here? .... or specify an executor? KIS (just one 'S'!!!)
} | ||
|
||
try { | ||
testCollection.save(MutableDocument(doc1Id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again... I don't think these documents add anything. You are just testing the deleted database. I think there's way to much code here...
deleteDb(baseTestDb) | ||
assertEquals(0, testCollection.count) | ||
} | ||
|
||
// Test getting doc count from a collection deleted in a different database instance returns 0 | ||
@Test | ||
fun testGetDocFromCollectionDeletedInADifferentDBInstance() { | ||
val otherDatabase = duplicateDb(baseTestDb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw, here, you could just say:
duplicateDb(baseTestDb).use { ... }
val doc = MutableDocument(docID) | ||
saveDocInTestCollection(doc) | ||
otherDatabase.use { | ||
val docID = "doc1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could do this outside the use
. It doesn't have anything to do with the db.
val docID = "doc1" | ||
val doc = MutableDocument(docID) | ||
saveDocInTestCollection(doc) | ||
otherDatabase.deleteCollection(testCollection.name, testCollection.scope.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside the use
block, otherDatabase is called "it"
|
||
testCollection.delete(doc) | ||
otherDb.use { | ||
val doc = createSingleDocInCollectionWithId("doc") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think creating the doc can come out of the use
testCollection.createIndex("index1", ValueIndexConfiguration("firstName", "lastName")) | ||
assertEquals(1, testCollection.indexes.size) | ||
// Delete collection | ||
otherDb.deleteCollection(testCollection.name, testCollection.scope.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a look at Kotlin "scoping functions". Again... otherDb should be called 'it' here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jut a few things....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... Looks much better. Thanks!
@@ -97,7 +96,15 @@ class CollectionTest : BaseCollectionTest() { | |||
@Test(expected = CouchbaseLiteException::class) | |||
fun testGetDocFromCollectionInClosedDB() { | |||
createSingleDocInCollectionWithId("doc_id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be named createSingleDocInTestCollection
?
// Test getting doc count from a collection in a deleted database returns 0 | ||
@Test | ||
fun testGetDocCountFromCollectionInDeletedDatabase() { | ||
val docID = "doc_id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to use saveSingleDocInCollectionWithID (or, the renamed version) here?
and some refactoring to safely close db.