/** Tests that newly created queues are empty. */ public void testQueueStartsEmpty() { assertQueueIsEmpty(); }
/** Tests that newly created queues are empty. */ public void testQueueStartsEmpty() { 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 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 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 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 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())); }
/** * 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 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(); }
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 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(); }