/** * 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 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 operations by different authors are not merged. */ public void testDoesNotMergeOperationsDividedByOtherAuthor() { queue.add(BOB_A); queue.add(JIM_B); assertQueueSizeBetween(1, 2); assertEquals(list(BOB_A), copyList(queue.take())); assertEquals(list(JIM_B), copyList(queue.take())); }
/** Tests that operations by different authors are not merged. */ public void testDoesNotMergeOperationsDividedByOtherAuthor() { queue.add(BOB_A); queue.add(JIM_B); assertQueueSizeBetween(1, 2); assertEquals(list(BOB_A), copyList(queue.take())); assertEquals(list(JIM_B), copyList(queue.take())); }
/** * 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 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 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()); }
/** * 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 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(); }
/** * 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(); }
/** * Tests that deltas which are transformed make their way back into the queue, * replacing the untransformed versions and being sent out of take(). */ public void testTransformedDeltasReplaceOriginals() throws TransformException { queue.add(BOB_A); queue.add(BOB_B); queue.add(JIM_C); transformer.expect(BOB_A, BOB_B).transformTo(BOB_A); transformer.expect(JIM_C).echo(); assertEquals(transformer.getOutputServerDelta(), // \u2620 queue.transform(transformer.getInputServerDelta())); transformer.checkDone(); assertQueueSizeBetween(1, 2); assertEquals(list(BOB_A), copyList(queue.take())); assertEquals(list(JIM_C), copyList(queue.take())); assertQueueIsEmpty(); }
/** * Tests that deltas which are transformed make their way back into the queue, * replacing the untransformed versions and being sent out of take(). */ public void testTransformedDeltasReplaceOriginals() throws TransformException { queue.add(BOB_A); queue.add(BOB_B); queue.add(JIM_C); transformer.expect(BOB_A, BOB_B).transformTo(BOB_A); transformer.expect(JIM_C).echo(); assertEquals(transformer.getOutputServerDelta(), // \u2620 queue.transform(transformer.getInputServerDelta())); transformer.checkDone(); assertQueueSizeBetween(1, 2); assertEquals(list(BOB_A), copyList(queue.take())); assertEquals(list(JIM_C), copyList(queue.take())); assertQueueIsEmpty(); }
/** * Test we still compose operations after we've transformed. */ public void testComposistionAfterTransform() 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())); // Adding one more operation after that should not merge into previously // transformed client op queue.add(util.noOpDocOp("blipA")); // This operation should merge into the previous op as the previous op is not // yet transformed queue.add(util.noOpDocOp("blipA")); // Should get 1 op, the result of merging and composing the two deltas. assertQueueSizeBetween(1, 3); assertEquals(list(util.noOpDocOp("blipA")), copyList(queue.take())); assertQueueIsEmpty(); }
/** * Test we still compose operations after we've transformed. */ public void testComposistionAfterTransform() 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())); // Adding one more operation after that should not merge into previously // transformed client op queue.add(util.noOpDocOp("blipA")); // This operation should merge into the previous op as the previous op is not // yet transformed queue.add(util.noOpDocOp("blipA")); // Should get 1 op, the result of merging and composing the two deltas. assertQueueSizeBetween(1, 3); assertEquals(list(util.noOpDocOp("blipA")), copyList(queue.take())); assertQueueIsEmpty(); }
/** * Test we compose operations after we've transformed. However, we should get several * transformed client operations out in the same delta if they don't compose. */ public void testGettingSeveralOpsInOneDelta() throws TransformException { DeltaTestUtil util = new DeltaTestUtil(BOB); // Do 1 client op queue.add(util.noOpDocOp("blipA")); // Get a server op transformer.expect(util.noOpDocOp("blipA")).echo(); assertEquals(transformer.getOutputServerDelta(), // \u2620 queue.transform(transformer.getInputServerDelta())); // Do another client op queue.add(util.noOpDocOp("blipB")); // Get a server op transformer.expect(util.noOpDocOp("blipA"), util.noOpDocOp("blipB")).echo(); assertEquals(transformer.getOutputServerDelta(), // \u2620 queue.transform(transformer.getInputServerDelta())); // Should get 2 ops in the same delta assertQueueSizeBetween(1, 2); assertEquals(list(util.noOpDocOp("blipA"), util.noOpDocOp("blipB")), copyList(queue.take())); assertQueueIsEmpty(); }
/** * Tests that deltas which become empty due to a transform are discarded from * the queue. */ public void testDeltasEmptyAfterTransformAreDiscarded() throws TransformException { queue.add(BOB_A); queue.add(JIM_A); queue.add(BOB_B); queue.add(TOM_B); queue.add(BOB_C); transformer.expect(BOB_A).kill(); transformer.expect(JIM_A).echo(); transformer.expect(BOB_B).kill(); transformer.expect(TOM_B).echo(); transformer.expect(BOB_C).kill(); assertEquals(transformer.getOutputServerDelta(), // \u2620 queue.transform(transformer.getInputServerDelta())); transformer.checkDone(); assertQueueSizeBetween(1, 2); assertEquals(list(JIM_A), copyList(queue.take())); assertEquals(list(TOM_B), copyList(queue.take())); assertQueueIsEmpty(); }