/** * Removes a thread from the manifest, as though a remote client had done so. */ private void remoteRemoveThread(WaveletBasedConversationThread thread) { ManifestBlip parentBlip = thread.getParentBlip().getManifestBlip(); ManifestThread manifestThread = thread.getManifestThread(); parentBlip.removeReply(manifestThread); }
/** * Removes a blip from the manifest, as though a remote client had done so. */ private void remoteRemoveBlip(WaveletBasedConversationBlip blip) { ManifestThread parentThread = blip.getThread().getManifestThread(); ManifestBlip manifestBlip = blip.getManifestBlip(); parentThread.removeBlip(manifestBlip); }
/** * Removes a thread from the manifest, as though a remote client had done so. */ private void remoteRemoveThread(WaveletBasedConversationThread thread) { ManifestBlip parentBlip = thread.getParentBlip().getManifestBlip(); ManifestThread manifestThread = thread.getManifestThread(); parentBlip.removeReply(manifestThread); }
/** * Removes a blip from the manifest, as though a remote client had done so. */ private void remoteRemoveBlip(WaveletBasedConversationBlip blip) { ManifestThread parentThread = blip.getThread().getManifestThread(); ManifestBlip manifestBlip = blip.getManifestBlip(); parentThread.removeBlip(manifestBlip); }
/** * Deletes a blip from this thread, deleting that blip's replies. */ void deleteBlip(WaveletBasedConversationBlip blipToDelete, boolean shouldDeleteSelfIfEmpty) { Preconditions.checkArgument(blips.containsKey(blipToDelete.getId()), "Can't delete blip not from this thread"); blipToDelete.deleteThreads(); manifestThread.removeBlip(blipToDelete.getManifestBlip()); blipToDelete.clearContent(); if (shouldDeleteSelfIfEmpty) { deleteSelfIfEmpty(); } }
@Override public WaveletBasedConversationBlip insertBlip(ConversationBlip successor) { checkIsUsable(); if (!blips.containsKey(successor.getId())) { Preconditions.illegalArgument( "Can't insert blip before blip " + successor + " not from this thread"); } WaveletBasedConversationBlip insertBefore = (WaveletBasedConversationBlip) successor; int index = manifestThread.indexOf(insertBefore.getManifestBlip()); Blip blip = helper.createBlip(null); String blipId = blip.getId(); manifestThread.insertBlip(index, blipId); return blips.get(blipId); }
public void testConcrrentDeletionOfFinalBlipsLeavesEmptyThread() { WaveletBasedConversationBlip first = target.getRootThread().appendBlip(); WaveletBasedConversationThread replyThread = first.addReplyThread(); WaveletBasedConversationBlip b1 = replyThread.appendBlip(); WaveletBasedConversationBlip b2 = replyThread.appendBlip(); // Locally delete b1, remotely delete b2. b1.delete(); replyThread.addListener(threadListener); b2.addListener(blipListener); target.addListener(convListener); remoteRemoveBlip(b2); // Expect blip deletion events and it to be invalid. verify(blipListener).onDeleted(); verify(convListener).onBlipDeleted(b2); assertBlipInvalid(b2); assertThreadValid(replyThread); assertEquals(Arrays.asList(replyThread), CollectionUtils.newArrayList(first.getReplyThreads())); // The manifest now has a thread with no blips. assertEquals(1, first.getManifestBlip().numReplies()); assertEquals(0, first.getManifestBlip().getReply(0).numBlips()); // Still there after the next mutation. ObservableConversationBlip second = target.getRootThread().appendBlip(); assertThreadValid(replyThread); assertEquals(Arrays.asList(replyThread), CollectionUtils.newArrayList(first.getReplyThreads())); verify(convListener).onBlipAdded(second); verifyNoMoreInteractions(blipListener, threadListener, convListener); }
public void testConcrrentDeletionOfFinalBlipsLeavesEmptyThread() { WaveletBasedConversationBlip first = target.getRootThread().appendBlip(); WaveletBasedConversationThread replyThread = first.addReplyThread(); WaveletBasedConversationBlip b1 = replyThread.appendBlip(); WaveletBasedConversationBlip b2 = replyThread.appendBlip(); // Locally delete b1, remotely delete b2. b1.delete(); replyThread.addListener(threadListener); b2.addListener(blipListener); target.addListener(convListener); remoteRemoveBlip(b2); // Expect blip deletion events and it to be invalid. verify(blipListener).onDeleted(); verify(convListener).onBlipDeleted(b2); assertBlipInvalid(b2); assertThreadValid(replyThread); assertEquals(Arrays.asList(replyThread), CollectionUtils.newArrayList(first.getReplyThreads())); // The manifest now has a thread with no blips. assertEquals(1, first.getManifestBlip().numReplies()); assertEquals(0, first.getManifestBlip().getReply(0).numBlips()); // Still there after the next mutation. ObservableConversationBlip second = target.getRootThread().appendBlip(); assertThreadValid(replyThread); assertEquals(Arrays.asList(replyThread), CollectionUtils.newArrayList(first.getReplyThreads())); verify(convListener).onBlipAdded(second); verifyNoMoreInteractions(blipListener, threadListener, convListener); }
public void testConcurrentDeletionOfFinalThreadsLeavesEmptyBlip() { WaveletBasedConversationBlip first = target.getRootThread().appendBlip(); WaveletBasedConversationThread t1 = first.addReplyThread(); WaveletBasedConversationBlip t1b = t1.appendBlip(); WaveletBasedConversationThread t2 = first.addReplyThread(); WaveletBasedConversationBlip t2b = t2.appendBlip(); // Locally delete t1, remotely delete t2. t1b.delete(); first.addListener(blipListener); t2.addListener(threadListener); target.addListener(convListener); remoteRemoveBlip(t2b); remoteRemoveThread(t2); // Expect thread t2 deletion events and it to be invalid. verify(threadListener).onDeleted(); verify(convListener).onBlipDeleted(t2b); verify(convListener).onThreadDeleted(t2); assertBlipInvalid(t2b); assertThreadInvalid(t2); assertBlipValid(first); assertNotNull(target.getRootThread().getFirstBlip()); // The manifest now has an empty blip. assertEquals(0, first.getManifestBlip().numReplies()); // Still there after next write. WaveletBasedConversationBlip second = target.getRootThread().appendBlip(); assertBlipValid(first); verify(convListener).onBlipAdded(second); verifyNoMoreInteractions(blipListener, threadListener, convListener); }
public void testConcurrentDeletionOfFinalThreadsLeavesEmptyBlip() { WaveletBasedConversationBlip first = target.getRootThread().appendBlip(); WaveletBasedConversationThread t1 = first.addReplyThread(); WaveletBasedConversationBlip t1b = t1.appendBlip(); WaveletBasedConversationThread t2 = first.addReplyThread(); WaveletBasedConversationBlip t2b = t2.appendBlip(); // Locally delete t1, remotely delete t2. t1b.delete(); first.addListener(blipListener); t2.addListener(threadListener); target.addListener(convListener); remoteRemoveBlip(t2b); remoteRemoveThread(t2); // Expect thread t2 deletion events and it to be invalid. verify(threadListener).onDeleted(); verify(convListener).onBlipDeleted(t2b); verify(convListener).onThreadDeleted(t2); assertBlipInvalid(t2b); assertThreadInvalid(t2); assertBlipValid(first); assertNotNull(target.getRootThread().getFirstBlip()); // The manifest now has an empty blip. assertEquals(0, first.getManifestBlip().numReplies()); // Still there after next write. WaveletBasedConversationBlip second = target.getRootThread().appendBlip(); assertBlipValid(first); verify(convListener).onBlipAdded(second); verifyNoMoreInteractions(blipListener, threadListener, convListener); }