@Test public void testGenerateLocalInsertString() throws IncorrectTraceException { int siteId = 0; TTFMergeAlgorithm merger = new TTFMergeAlgorithm(siteId); List<Operation> ops = merger.localInsert(insert(0, "abc")); assertEquals(3, ops.size()); OTMessage<TTFOperation> opg = ((TTFSequenceMessage) ops.get(0)).getSoct2Message(); assertEquals(OpType.insert, opg.getOperation().getType()); assertEquals('a', opg.getOperation().getContent()); assertEquals(0, opg.getOperation().getPosition()); assertEquals("[<0,1>]", vcToString(opg.getClock())); opg = ((TTFSequenceMessage) ops.get(1)).getSoct2Message(); assertEquals('b', opg.getOperation().getContent()); assertEquals(1, opg.getOperation().getPosition()); assertEquals("[<0,2>]", vcToString(opg.getClock())); opg = ((TTFSequenceMessage) ops.get(2)).getSoct2Message(); assertEquals('c', opg.getOperation().getContent()); assertEquals("[<0,3>]", vcToString(opg.getClock())); assertEquals(2, opg.getOperation().getPosition()); assertEquals("abc", merger.lookup()); }
@Test public void testGenerateLocalDeleteString() throws IncorrectTraceException { int siteId = 0; TTFMergeAlgorithm merger = new TTFMergeAlgorithm(siteId); merger.localInsert(insert(0, "abcd")); // remove "abcd" List<Operation> ops = merger.localDelete(delete(0, 4)); assertEquals(4, ops.size()); OTMessage<TTFOperation> opg = ((TTFSequenceMessage) ops.get(0)).getSoct2Message(); assertEquals(OpType.delete, opg.getOperation().getType()); assertEquals(0, opg.getOperation().getPosition()); assertEquals("[<0,5>]", vcToString(opg.getClock())); opg = ((TTFSequenceMessage) ops.get(1)).getSoct2Message(); assertEquals(OpType.delete, opg.getOperation().getType()); assertEquals(1, opg.getOperation().getPosition()); assertEquals("[<0,6>]", vcToString(opg.getClock())); opg = ((TTFSequenceMessage) ops.get(2)).getSoct2Message(); assertEquals(OpType.delete, opg.getOperation().getType()); assertEquals(2, opg.getOperation().getPosition()); assertEquals("[<0,7>]", vcToString(opg.getClock())); opg = ((TTFSequenceMessage) ops.get(3)).getSoct2Message(); assertEquals(OpType.delete, opg.getOperation().getType()); assertEquals(3, opg.getOperation().getPosition()); assertEquals("[<0,8>]", vcToString(opg.getClock())); assertEquals("", merger.lookup()); }
@Test public void testVectorClockEvolution() throws IncorrectTraceException { int siteId = 0; TTFMergeAlgorithm merger = new TTFMergeAlgorithm(siteId); assertEquals(vc(0), merger.getClock()); OTMessage op1 = ((TTFSequenceMessage) merger.localInsert(insert(0, "a")).get(0)).getSoct2Message(); assertEquals(vc(1), merger.getClock()); OTMessage op2 = ((TTFSequenceMessage) merger.localInsert(insert(1, "b")).get(0)).getSoct2Message(); assertEquals(vc(2), merger.getClock()); assertEquals(vc(1), op1.getClock()); assertEquals(vc(2), op2.getClock()); }