/** * 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(); }
/** * Asserts that the queue is not empty and the size estimate is within * expected bounds (inclusive). */ private void assertQueueSizeBetween(int minSize, int maxSize) { assertFalse("Expected non-empty queue", queue.isEmpty()); int estimate = queue.estimateSize(); assertTrue("Expected queue size >= " + minSize + ", was " + estimate, estimate >= minSize); assertTrue("Expected queue size <= " + maxSize + ", was " + estimate, estimate <= maxSize); }
/** * 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 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(); }
/** Asserts that the queue is empty and size estimate is zero. */ private void assertQueueIsEmpty() { assertTrue("Expected empty queue", queue.isEmpty()); assertEquals("Expected queue size zero", 0, queue.estimateSize()); }
/** * Asserts that the queue is not empty and the size estimate is as expected. */ private void assertQueueSize(int size) { assertFalse("Expected non-empty queue", queue.isEmpty()); int estimate = queue.estimateSize(); assertEquals("Expected queue size " + size + ", was " + estimate, size, estimate); }
/** * Tests that attempting to take a delta from an empty queue results in a * {@link NoSuchElementException} being thrown. */ public void testThrowsExceptionTakingFromEmptyQueue() { try { queue.take(); fail("take() from empty queue should fail"); } catch (NoSuchElementException expected) { } }
/** Tests that newly created queues are empty. */ public void testQueueStartsEmpty() { assertQueueIsEmpty(); }
/** * 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 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(); }
/** Asserts that the queue is empty and size estimate is zero. */ private void assertQueueIsEmpty() { assertTrue("Expected empty queue", queue.isEmpty()); assertEquals("Expected queue size zero", 0, queue.estimateSize()); }
/** * Asserts that the queue is not empty and the size estimate is as expected. */ private void assertQueueSize(int size) { assertFalse("Expected non-empty queue", queue.isEmpty()); int estimate = queue.estimateSize(); assertEquals("Expected queue size " + size + ", was " + estimate, size, estimate); }
/** * Tests that attempting to take a delta from an empty queue results in a * {@link NoSuchElementException} being thrown. */ public void testThrowsExceptionTakingFromEmptyQueue() { try { queue.take(); fail("take() from empty queue should fail"); } catch (NoSuchElementException expected) { } }
/** Tests that newly created queues are empty. */ public void testQueueStartsEmpty() { assertQueueIsEmpty(); }
/** * 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 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 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(); }
/** * Asserts that the queue is not empty and the size estimate is within * expected bounds (inclusive). */ private void assertQueueSizeBetween(int minSize, int maxSize) { assertFalse("Expected non-empty queue", queue.isEmpty()); int estimate = queue.estimateSize(); assertTrue("Expected queue size >= " + minSize + ", was " + estimate, estimate >= minSize); assertTrue("Expected queue size <= " + maxSize + ", was " + estimate, estimate <= maxSize); }
/** * 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 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); }