/** * 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())); }
/** * 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 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 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 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 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()); }
/** * Test operations are actually transformed. */ public void testOpsAreTransformed() throws TransformException { queue = new OperationQueue(); DeltaTestUtil bob = new DeltaTestUtil(BOB); DeltaTestUtil jim = new DeltaTestUtil(JIM); // Do bob client op 1 queue.add(bob.insert(1, "a", 1, null)); // Get delta 1 from jim queue.transform(Arrays.asList(jim.insert(1, "j", 1, null))); // Do bob client op 2 queue.add(bob.insert(1, "b", 3, null)); // Get delta 2 from jim queue.transform(Arrays.asList(jim.insert(1, "i", 2, null))); // check ops are transformed assertEquals(list(bob.insert(1, "ba", 3, null)), copyList(queue.take())); assertQueueIsEmpty(); }
/** * Test operations are actually transformed. */ public void testOpsAreTransformed() throws TransformException { queue = new OperationQueue(); DeltaTestUtil bob = new DeltaTestUtil(BOB); DeltaTestUtil jim = new DeltaTestUtil(JIM); // Do bob client op 1 queue.add(bob.insert(1, "a", 1, null)); // Get delta 1 from jim queue.transform(Arrays.asList(jim.insert(1, "j", 1, null))); // Do bob client op 2 queue.add(bob.insert(1, "b", 3, null)); // Get delta 2 from jim queue.transform(Arrays.asList(jim.insert(1, "i", 2, null))); // check ops are transformed assertEquals(list(bob.insert(1, "ba", 3, null)), 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(); }
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(); }