Skip to content

Commit

Permalink
STITCH-2911 - staging for release
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaminsky committed May 6, 2019
1 parent 6a56afc commit 7c1c7f8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -919,167 +919,6 @@ class RemoteMongoClientIntTests : BaseStitchAndroidIntTest() {
}
}

@Test
fun testWatchCompactBsonValueIDs() {
val coll = getTestColl()
assertEquals(0, Tasks.await(coll.count()))

val rawDoc1 = Document()
rawDoc1["_id"] = 1
rawDoc1["hello"] = "world"
rawDoc1["__stitch_sync_version"] = Document()
.append("spv", 1)
.append("id", ObjectId().toHexString())
.append("v", 5L)

val rawDoc2 = Document()
rawDoc2["_id"] = "foo"
rawDoc2["happy"] = "day"

Tasks.await(coll.insertOne(rawDoc1))
assertEquals(1, Tasks.await(coll.count()))

val streamTask = coll.watchCompact(BsonInt32(1), BsonString("foo"))
val stream = Tasks.await(streamTask)

try {
Tasks.await(coll.insertOne(rawDoc2))
assertEquals(2, Tasks.await(coll.count()))
Tasks.await(coll.updateMany(BsonDocument(), Document().append("\$set",
Document().append("new", "field"))))

val insertEvent = Tasks.await(stream.nextEvent())
assertEquals(OperationType.INSERT, insertEvent.operationType)
assertEquals(rawDoc2, insertEvent.fullDocument)
val updateEvent1 = Tasks.await(stream.nextEvent())
val updateEvent2 = Tasks.await(stream.nextEvent())

assertNotNull(updateEvent1)
assertNotNull(updateEvent2)

assertEquals(OperationType.UPDATE, updateEvent1.operationType)
assertEquals(
updateEvent1.updateDescription!!.updatedFields["new"],
BsonString("field")
)
assertNull(updateEvent1.fullDocument)
assertEquals(
updateEvent1.stitchDocumentVersion!!.toBsonDocument(),
rawDoc1.toBsonDocument(Document::class.java, BsonUtils.DEFAULT_CODEC_REGISTRY)
.getDocument("__stitch_sync_version")
)

rawDoc1.remove("__stitch_sync_version")
rawDoc1.append("new", "field")
assertEquals(
updateEvent1.stitchDocumentHash,
HashUtils.hash(rawDoc1.toBsonDocument(
Document::class.java,
BsonUtils.DEFAULT_CODEC_REGISTRY
))
)

assertEquals(OperationType.UPDATE, updateEvent2.operationType)
assertEquals(
updateEvent1.updateDescription!!.updatedFields["new"],
BsonString("field")
)
assertNull(updateEvent2.stitchDocumentVersion)

rawDoc2.append("new", "field")
assertEquals(
updateEvent2.stitchDocumentHash,
HashUtils.hash(rawDoc2.toBsonDocument(
Document::class.java,
BsonUtils.DEFAULT_CODEC_REGISTRY
))
)
} finally {
stream.close()
}
}

@Test
fun testWatchCompactObjectIdIDs() {
val coll = getTestColl()
assertEquals(0, Tasks.await(coll.count()))

val objectId1 = ObjectId()
val objectId2 = ObjectId()

val rawDoc1 = Document()
rawDoc1["_id"] = objectId1
rawDoc1["hello"] = "world"
rawDoc1["__stitch_sync_version"] = Document()
.append("spv", 1)
.append("id", ObjectId().toHexString())
.append("v", 5L)

val rawDoc2 = Document()
rawDoc2["_id"] = objectId2
rawDoc2["happy"] = "day"

Tasks.await(coll.insertOne(rawDoc1))
assertEquals(1, Tasks.await(coll.count()))

val streamTask = coll.watchCompact(objectId1, objectId2)
val stream = Tasks.await(streamTask)

try {
Tasks.await(coll.insertOne(rawDoc2))
assertEquals(2, Tasks.await(coll.count()))
Tasks.await(coll.updateMany(BsonDocument(), Document().append("\$set",
Document().append("new", "field"))))

val insertEvent = Tasks.await(stream.nextEvent())
assertEquals(OperationType.INSERT, insertEvent.operationType)
assertEquals(rawDoc2, insertEvent.fullDocument)
val updateEvent1 = Tasks.await(stream.nextEvent())
val updateEvent2 = Tasks.await(stream.nextEvent())

assertNotNull(updateEvent1)
assertNotNull(updateEvent2)

assertEquals(OperationType.UPDATE, updateEvent1.operationType)
assertEquals(
updateEvent1.updateDescription!!.updatedFields["new"],
BsonString("field")
)
assertNull(updateEvent1.fullDocument)
assertEquals(
updateEvent1.stitchDocumentVersion!!.toBsonDocument(),
rawDoc1.toBsonDocument(Document::class.java, BsonUtils.DEFAULT_CODEC_REGISTRY)
.getDocument("__stitch_sync_version")
)

rawDoc1.remove("__stitch_sync_version")
rawDoc1.append("new", "field")
assertEquals(
updateEvent1.stitchDocumentHash,
HashUtils.hash(rawDoc1.toBsonDocument(
Document::class.java, BsonUtils.DEFAULT_CODEC_REGISTRY
))
)

assertEquals(OperationType.UPDATE, updateEvent2.operationType)
assertEquals(
updateEvent1.updateDescription!!.updatedFields["new"],
BsonString("field")
)
assertNull(updateEvent2.stitchDocumentVersion)

rawDoc2.append("new", "field")
assertEquals(
updateEvent2.stitchDocumentHash,
HashUtils.hash(rawDoc2.toBsonDocument(
Document::class.java, BsonUtils.DEFAULT_CODEC_REGISTRY
))
)
} finally {
stream.close()
}
}

private fun withoutIds(documents: Collection<Document>): Collection<Document> {
val list = ArrayList<Document>(documents.size)
documents.forEach { list.add(withoutId(it)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,14 @@ class SyncIntTestProxy(private val syncTestRunner: SyncIntTestRunner) {
// reconfigure sync and the same way. do a sync pass.
powerCycleDevice()
coll.configure(DefaultSyncConflictResolvers.localWins(), null, null)
val sem = watchForEvents(syncTestRunner.namespace)
//val sem = watchForEvents(syncTestRunner.namespace)
streamAndSync()

// update the document remotely. assert the update is reflected remotely.
// reload our configuration again. reconfigure Sync again.
val expectedDocument = Document(doc)
var result = remoteColl.updateOne(doc1Filter, withNewSyncVersionSet(Document("\$inc", Document("foo", 2))))
assertTrue(sem.tryAcquire(10, TimeUnit.SECONDS))
//assertTrue(sem.tryAcquire(10, TimeUnit.SECONDS))
assertEquals(1, result.matchedCount)
expectedDocument["foo"] = 3
assertEquals(expectedDocument, withoutSyncVersion(remoteColl.find(doc1Filter).first()!!))
Expand Down Expand Up @@ -1189,7 +1189,6 @@ class SyncIntTestProxy(private val syncTestRunner: SyncIntTestRunner) {
Assert.assertNotNull(coll.find(doc1Filter).firstOrNull())

assertEquals(1, remoteColl.deleteOne(doc1Filter).deletedCount)
powerCycleDevice()
coll.configure(ConflictHandler { _: BsonValue, _: ChangeEvent<Document>, _: ChangeEvent<Document> ->
throw IllegalStateException("failure")
}, null, null)
Expand Down

0 comments on commit 7c1c7f8

Please sign in to comment.