/** * Constructs a delta from another delta's operations. Does not copy any * version or signature information. */ public MergingSequence(Iterable<WaveletOperation> ops) { for (WaveletOperation op : ops) { add(op); } }
/** * Adds the given operation to the tail of the operation queue. Merges with * the delta at the tail if the creators match, otherwise creates a new tail * delta. */ public void add(WaveletOperation op) { ParticipantId creator = op.getContext().getCreator(); if (queue.isEmpty() || !creator.equals(tailCreator) || (queue.getLast().state != ItemState.NONE)) { queue.addLast(new Item(new MergingSequence(), ItemState.NONE)); tailCreator = creator; } queue.getLast().opSequence.add(op); }
composeDocOps(this, currentId, lastOperationContext, docOps); add(waveletOp);
/** * 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 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()); }