/** * 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); }
public void testOptimiseEmptyDoesNothing() { MergingSequence delta = new MergingSequence(); delta.optimise(); assertEquals(0, delta.size()); }
/** 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()); }
/** 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())); }
/** * 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(); }
/** * 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); }
/** * Pretend we are reconnecting to the server. * @throws OperationException * @throws TransformException */ public TestConfig reconnectToServer() throws Exception { serverConnectionMock.setOpen(true); serverConnectionMock.reconnect(clientMock.getReconnectionVersions()); return this; }
/** * Gets the operations from concurrency control. */ public void receiveServerOperations() { WaveletOperation op; while ((op = cc.receive()) != null) { onServerOperation(op); } }
@Override protected void setUp() { transformer = new MockDeltaTransformer(); queue = new OperationQueue(transformer); }
/** * Server open the connection at the given version and tells of the last version. */ public TestConfig serverDoOpen(int startVersion, int endVersion) throws ChannelException { serverConnectionMock.triggerOnOpen(genSignature(startVersion), genSignature(endVersion)); return this; }
/** * 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); }
public void testOptimiseEmptyDoesNothing() { MergingSequence delta = new MergingSequence(); delta.optimise(); assertEquals(0, delta.size()); }
/** 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 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 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 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 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(); }