/** * Tests that the queue's size estimate is at least one per un-mergable delta. * Since it's an underestimate it must be exactly correct if each delta * contains one op. */ public void testQueueSizeEstimateIsAtLeastDeltaSize() { queue.add(BOB_A); queue.add(JIM_A); queue.add(BOB_B); queue.add(JIM_B); queue.add(BOB_C); queue.add(JIM_C); assertEquals(6, queue.estimateSize()); }
/** * Tests that the queue's size estimate is at least one per un-mergable delta. * Since it's an underestimate it must be exactly correct if each delta * contains one op. */ public void testQueueSizeEstimateIsAtLeastDeltaSize() { queue.add(BOB_A); queue.add(JIM_A); queue.add(BOB_B); queue.add(JIM_B); queue.add(BOB_C); queue.add(JIM_C); assertEquals(6, queue.estimateSize()); }
/** * Tests that adding multiple consecutive operations from a single author * results in them being merged into the one delta. */ public void testMergesConsecutiveOperationsWithSameCreator() { queue.add(BOB_A); queue.add(BOB_B); assertQueueSizeBetween(1, 2); assertEquals(list(BOB_A, BOB_B), copyList(queue.take())); // Queue should now be empty, even though we did two adds and only one take assertQueueIsEmpty(); }
/** * Tests that adding operations to an empty queue results in it being * non-empty until those operations are taken out again. */ public void testQueueNonemptyAfterOperationsAddedUntilTaken() { queue.add(BOB_A); assertQueueSize(1); queue.take(); assertQueueIsEmpty(); }
/** * Tests that adding multiple consecutive operations from a single author * results in them being merged into the one delta. */ public void testMergesConsecutiveOperationsWithSameCreator() { queue.add(BOB_A); queue.add(BOB_B); assertQueueSizeBetween(1, 2); assertEquals(list(BOB_A, BOB_B), copyList(queue.take())); // Queue should now be empty, even though we did two adds and only one take assertQueueIsEmpty(); }
/** * Tests that adding operations to an empty queue results in it being * non-empty until those operations are taken out again. */ public void testQueueNonemptyAfterOperationsAddedUntilTaken() { queue.add(BOB_A); assertQueueSize(1); queue.take(); assertQueueIsEmpty(); }
/** * Tests that two operations from a single author that are added one after * another are still merge if the calls to add() are separated by a take() * which extracts previously added operations rather than either of the two * aforementioned operations. */ public void testOperationsMergeDespiteTakeIfQueueNotMadeEmpty() { queue.add(JIM_A); queue.add(BOB_B); assertEquals(list(JIM_A), copyList(queue.take())); assertQueueSize(1); assertQueueSizeBetween(1, 2); queue.add(BOB_C); assertEquals(list(BOB_B, BOB_C), copyList(queue.take())); assertQueueIsEmpty(); }
/** * Tests that two operations from a single author that are added one after * another are not merged if the calls to add() are separated by a take() * which extracts the first operation. */ public void testOperationsNotMergedOverQueueEmptyPoints() { queue.add(BOB_A); assertEquals(list(BOB_A), copyList(queue.take())); assertQueueIsEmpty(); queue.add(BOB_B); assertEquals(list(BOB_B), copyList(queue.take())); }
/** * Tests that two operations from a single author that are added one after * another are not merged if the calls to add() are separated by a take() * which extracts the first operation. */ public void testOperationsNotMergedOverQueueEmptyPoints() { queue.add(BOB_A); assertEquals(list(BOB_A), copyList(queue.take())); assertQueueIsEmpty(); queue.add(BOB_B); assertEquals(list(BOB_B), copyList(queue.take())); }
public void testCompositionBeforeTransform() throws TransformException { DeltaTestUtil util = new DeltaTestUtil(BOB); // 2 ops merged into one. queue.add(util.noOpDocOp("blipA")); queue.add(util.noOpDocOp("blipA")); // Get a server op transformer.expect(util.noOpDocOp("blipA")).echo(); assertEquals(transformer.getOutputServerDelta(), // \u2620 queue.transform(transformer.getInputServerDelta())); // Should get only 1 op assertQueueSize(1); assertEquals(list(util.noOpDocOp("blipA")), copyList(queue.take())); assertQueueIsEmpty(); }
public void testCompositionBeforeTransform() throws TransformException { DeltaTestUtil util = new DeltaTestUtil(BOB); // 2 ops merged into one. queue.add(util.noOpDocOp("blipA")); queue.add(util.noOpDocOp("blipA")); // Get a server op transformer.expect(util.noOpDocOp("blipA")).echo(); assertEquals(transformer.getOutputServerDelta(), // \u2620 queue.transform(transformer.getInputServerDelta())); // Should get only 1 op assertQueueSize(1); assertEquals(list(util.noOpDocOp("blipA")), copyList(queue.take())); assertQueueIsEmpty(); }
/** * Tests that the deltas provided by take() are optimised. Note that this test * makes assumptions about what type of deltas are used by * {@link OperationQueue} and what operations those deltas merge. */ public void testProducesOptimisedDeltas() { queue.add(new WaveletBlipOperation("a", new BlipContentOperation(BOB_A.getContext(), new DocOpBuilder().retain(1).characters("hi").retain(1).build()))); queue.add(new WaveletBlipOperation("a", new BlipContentOperation(BOB_B.getContext(), new DocOpBuilder().retain(1).characters("hi").retain(3).build()))); assertQueueSizeBetween(1, 2); assertEquals(1, queue.take().size()); assertQueueIsEmpty(); }
/** * Tests that the deltas provided by take() are optimised. Note that this test * makes assumptions about what type of deltas are used by * {@link OperationQueue} and what operations those deltas merge. */ public void testProducesOptimisedDeltas() { queue.add(new WaveletBlipOperation("a", new BlipContentOperation(BOB_A.getContext(), new DocOpBuilder().retain(1).characters("hi").retain(1).build()))); queue.add(new WaveletBlipOperation("a", new BlipContentOperation(BOB_B.getContext(), new DocOpBuilder().retain(1).characters("hi").retain(3).build()))); assertQueueSizeBetween(1, 2); assertEquals(1, queue.take().size()); assertQueueIsEmpty(); }
/** * 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 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()); }