Skip to content
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

Merged
merged 4 commits into from
Aug 19, 2022

Conversation

LaurenNguyen14
Copy link
Contributor

and some refactoring to safely close db.

Copy link
Contributor

@bmeike bmeike left a 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) {}
Copy link
Contributor

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"
Copy link
Contributor

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))
Copy link
Contributor

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)
Copy link
Contributor

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"
Copy link
Contributor

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)
Copy link
Contributor

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")
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor

@bmeike bmeike left a 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....

Copy link
Contributor

@bmeike bmeike left a 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")
Copy link
Contributor

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"
Copy link
Contributor

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?

@LaurenNguyen14 LaurenNguyen14 merged commit 5f9e36e into master Aug 19, 2022
@LaurenNguyen14 LaurenNguyen14 deleted the feature/CBL-3540-2-ver2 branch August 19, 2022 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants