Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,59 @@ public void testMergeLocalChangesWithUpdatedGhost()
assertEquals("Line 1\nLine 2\nLine 3\n", note.getContent());
}

/**
* If two different notes are both saved and then both deleted, they should both be missing from persistent store
* but present in the backup store.
*
* This also checks that the backup store isn't being cleared before the Channel has a chance to retrieve a backup
* object and send it.
*/
public void testConsecutiveSaveDeleteObjects() {
Note note1 = mBucket.newObject();
note1.setTitle("Hello World");

Note note2 = mBucket.newObject();
note2.setTitle("Hello Again World");

note1.save();
note2.save();

note1.delete();
note2.delete();

// Test retrieving notes from persistent store
BucketObjectMissingException note1MissingException = null;
BucketObjectMissingException note2MissingException = null;
try {
mBucket.getObject(note1.getSimperiumKey());
} catch (BucketObjectMissingException e) {
note1MissingException = e;
}
try {
mBucket.getObject(note2.getSimperiumKey());
} catch (BucketObjectMissingException e) {
note2MissingException = e;
}
// Retrieval from persistent store should fail
assertNotNull(note1MissingException);
assertNotNull(note2MissingException);

// Test retrieving notes from backup store
note1MissingException = null;
note2MissingException = null;
try {
mBucket.getObjectOrBackup(note1.getSimperiumKey());
} catch (BucketObjectMissingException e) {
note1MissingException = e;
}
try {
mBucket.getObjectOrBackup(note2.getSimperiumKey());
} catch (BucketObjectMissingException e) {
note2MissingException = e;
}
// Retrieval from backup store should succeed
assertNull(note1MissingException);
assertNull(note2MissingException);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected void tearDown() throws Exception {
* Some objects require a certain state before they can be deleted from a bucket so this ensures
* the object is at the desired state before the delete operation is sent.
*/
public void testSendFinalModificationBeforeDeleteOperation() throws Exception {
public void testQueueFinalModificationBeforeDeleteOperation() throws Exception {

mListener.autoAcknowledge = true;

Expand Down Expand Up @@ -135,6 +135,40 @@ public void testSendFinalModificationBeforeDeleteOperation() throws Exception {

}

/**
* See https://github.com/Simperium/simperium-android/issues/159
* Ensures that the channel is able to send out final modification operations for an object even if
* the object has since been removed from the local persistent store.
*/
public void testSendFinalModificationBeforeDeleteOperation() throws Exception {

startWithEmptyIndex();

String key = "test-modify-before-delete-object";
Note note = mBucket.newObject(key);
note.setTitle("Bonjour le monde!");

note.save();

// Queue a deletion and remove the object from the local persistent store before the modification has been sent
note.delete();

clearMessages();
waitForMessage();

// Message should be a change message "c:{}"
assertMatchesRegex("^c:\\{.*\\}$", mListener.lastMessage.toString());

// First change has been sent and it's a modification
assertEquals(1, mChannelSerializer.queue.pending.size());
assertTrue(mChannelSerializer.queue.pending.get(key).isModifyOperation());

// Second change is queued and it's a deletion
assertEquals(1, mChannelSerializer.queue.queued.size());
assertTrue(mChannelSerializer.queue.queued.get(0).isRemoveOperation());

}

/**
* Testing the receipt of cv:? from the server when using api 1.1
*/
Expand Down
Loading