/** * Push all deltas at startResend and after back into clientOperationQueue, * discarding their ack info. * * @param startMerge The starting index to the delta in the * {@link #inferredServerPath} to start to merge into clientOperationQueue. */ private void mergeToClientQueue(int startMerge) { List<WaveletDelta> deltas = CollectionUtils.newArrayList(); // Use the version at the resend if (startMerge < inferredServerPath.size()) { Iterator<AckedDelta> iter = inferredServerPath.listIterator(startMerge); while (iter.hasNext()) { deltas.add(iter.next().delta); iter.remove(); } } if (unacknowledged != null) { deltas.add(unacknowledged); unacknowledged = null; } Collections.reverse(deltas); for (WaveletDelta delta : deltas) { clientOperationQueue.insertHead(delta); } }
/** * Tests that inserting a new head delta into an empty queue makes the queue * non-empty if and only if the delta has ops in it. */ public void testQueueNonemptyAfterInsertingNonemptyHead() { queue.insertHead(new MergingSequence()); assertQueueIsEmpty(); MergingSequence head = new MergingSequence(); head.add(BOB_A); queue.insertHead(head); assertQueueSize(1); }
/** * Tests that inserting a new head delta into an empty queue makes the queue * non-empty if and only if the delta has ops in it. */ public void testQueueNonemptyAfterInsertingNonemptyHead() { queue.insertHead(new MergingSequence()); assertQueueIsEmpty(); MergingSequence head = new MergingSequence(); head.add(BOB_A); queue.insertHead(head); assertQueueSize(1); }
/** * Tests that a new head delta which is being inserted does not merge with the * existing head if the creators do not match, hence the old head is moved to * be the second delta but otherwise remains unmodified. */ public void testInsertHeadMakesNewDeltaIfCreatorDiffersFromExistingHead() { queue.add(BOB_C); MergingSequence head = new MergingSequence(); head.add(JIM_A); head.add(JIM_B); queue.insertHead(head); assertEquals(list(JIM_A, JIM_B), copyList(queue.take())); assertEquals(list(BOB_C), copyList(queue.take())); assertTrue(queue.isEmpty()); }
/** * Tests that a new head delta which is being inserted does not merge with the * existing head if the creators do not match, hence the old head is moved to * be the second delta but otherwise remains unmodified. */ public void testInsertHeadMakesNewDeltaIfCreatorDiffersFromExistingHead() { queue.add(BOB_C); MergingSequence head = new MergingSequence(); head.add(JIM_A); head.add(JIM_B); queue.insertHead(head); assertEquals(list(JIM_A, JIM_B), copyList(queue.take())); assertEquals(list(BOB_C), copyList(queue.take())); assertTrue(queue.isEmpty()); }
/** * Tests that a new head delta can be inserted in at the start of an empty * queue. Future adds of ops by the same creator do not merge with it. */ public void testHeadInsertedIntoEmptyQueueAllowsFutureMerging() { MergingSequence head = new MergingSequence(); head.add(BOB_A); head.add(BOB_B); queue.insertHead(head); queue.add(BOB_C); assertQueueSizeBetween(1, 3); // Delta pushed to head is not mergable to a single delta. assertEquals(list(BOB_A, BOB_B), copyList(queue.take())); assertEquals(list(BOB_C), copyList(queue.take())); assertTrue(queue.isEmpty()); }
/** * Tests that a new head delta can be inserted in at the start of an empty * queue. Future adds of ops by the same creator do not merge with it. */ public void testHeadInsertedIntoEmptyQueueAllowsFutureMerging() { MergingSequence head = new MergingSequence(); head.add(BOB_A); head.add(BOB_B); queue.insertHead(head); queue.add(BOB_C); assertQueueSizeBetween(1, 3); // Delta pushed to head is not mergable to a single delta. assertEquals(list(BOB_A, BOB_B), copyList(queue.take())); assertEquals(list(BOB_C), copyList(queue.take())); assertTrue(queue.isEmpty()); }
/** * Tests that a new head delta can be inserted in a non-empty queue. * It does not merge with the existing head. */ public void testInsertHeadMergesIfSameCreatorAsExistingHead() { queue.add(BOB_C); MergingSequence head = new MergingSequence(); head.add(BOB_A); head.add(BOB_B); queue.insertHead(head); assertQueueSizeBetween(1, 3); // Delta pushed to head is not mergable to a single delta. assertEquals(list(BOB_A, BOB_B), copyList(queue.take())); assertEquals(list(BOB_C), copyList(queue.take())); assertTrue(queue.isEmpty()); }
/** * Tests that a new head delta can be inserted in a non-empty queue. * It does not merge with the existing head. */ public void testInsertHeadMergesIfSameCreatorAsExistingHead() { queue.add(BOB_C); MergingSequence head = new MergingSequence(); head.add(BOB_A); head.add(BOB_B); queue.insertHead(head); assertQueueSizeBetween(1, 3); // Delta pushed to head is not mergable to a single delta. assertEquals(list(BOB_A, BOB_B), copyList(queue.take())); assertEquals(list(BOB_C), copyList(queue.take())); assertTrue(queue.isEmpty()); }
/** * Since transform and compose doesn't commute, test we don't compose operations after * we've sent the operation. So when we push to head, we shouldn't merge sent deltas. */ public void testNoCompositionWithInsertHead() throws TransformException { DeltaTestUtil util = new DeltaTestUtil(BOB); // Do 1 client op queue.add(util.noOpDocOp("blipA")); // Pushing an op to the head should never merge queue.insertHead(Arrays.asList(util.noOpDocOp("blipA"))); // Get a server op transformer.expect(util.noOpDocOp("blipA")).echo(); transformer.expect(util.noOpDocOp("blipA")).echo(); assertEquals(transformer.getOutputServerDelta(), // \u2620 queue.transform(transformer.getInputServerDelta())); // Should be 2 deltas a the first one is not mergable assertQueueSizeBetween(1, 2); assertEquals(list(util.noOpDocOp("blipA")), copyList(queue.take())); assertEquals(list(util.noOpDocOp("blipA")), copyList(queue.take())); assertQueueIsEmpty(); }
/** * Since transform and compose doesn't commute, test we don't compose operations after * we've sent the operation. So when we push to head, we shouldn't merge sent deltas. */ public void testNoCompositionWithInsertHead() throws TransformException { DeltaTestUtil util = new DeltaTestUtil(BOB); // Do 1 client op queue.add(util.noOpDocOp("blipA")); // Pushing an op to the head should never merge queue.insertHead(Arrays.asList(util.noOpDocOp("blipA"))); // Get a server op transformer.expect(util.noOpDocOp("blipA")).echo(); transformer.expect(util.noOpDocOp("blipA")).echo(); assertEquals(transformer.getOutputServerDelta(), // \u2620 queue.transform(transformer.getInputServerDelta())); // Should be 2 deltas a the first one is not mergable assertQueueSizeBetween(1, 2); assertEquals(list(util.noOpDocOp("blipA")), copyList(queue.take())); assertEquals(list(util.noOpDocOp("blipA")), copyList(queue.take())); assertQueueIsEmpty(); }