1 /*******************************************************************************
2 * Copyright (c) 2013 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Geneviève Bastien - Initial implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.synchronization
;
15 import static org
.junit
.Assert
.assertEquals
;
17 import java
.util
.Collection
;
18 import java
.util
.LinkedList
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.matching
.TmfEventDependency
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.ITmfTimestampTransform
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.SyncAlgorithmFullyIncremental
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.SynchronizationAlgorithm
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.TimestampTransformFactory
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.SynchronizationAlgorithm
.SyncQuality
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.event
.TmfSyncEventStub
;
29 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
30 import org
.junit
.Before
;
31 import org
.junit
.Test
;
34 * Tests for {@link SynchronizationAlgorithm} and its descendants
36 * @author Geneviève Bastien
38 @SuppressWarnings("nls")
39 public class SyncTest
{
41 private TmfTraceStub t1
, t2
;
42 private Collection
<ITmfTrace
> fTraces
;
45 * Initializing the traces
49 t1
= new TmfTraceStub();
51 t2
= new TmfTraceStub();
54 Collection
<ITmfTrace
> traces
= new LinkedList
<>();
61 * Testing fully incremental algorithm with communication between the two
65 public void testFullyIncremental() {
67 SynchronizationAlgorithm syncAlgo
= new SyncAlgorithmFullyIncremental();
69 syncAlgo
.init(fTraces
);
71 assertEquals(SyncQuality
.ABSENT
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
73 new TmfEventDependency(new TmfSyncEventStub(t2
, new TmfTimestamp(1)),
74 new TmfSyncEventStub(t1
, new TmfTimestamp(1))
76 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo
.toString());
77 assertEquals(SyncQuality
.INCOMPLETE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
80 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(1)),
81 new TmfSyncEventStub(t2
, new TmfTimestamp(3))
83 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo
.toString());
84 assertEquals(SyncQuality
.INCOMPLETE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
87 new TmfEventDependency(new TmfSyncEventStub(t2
, new TmfTimestamp(2)),
88 new TmfSyncEventStub(t1
, new TmfTimestamp(3))
90 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0.5 ]]", syncAlgo
.toString());
91 assertEquals(SyncQuality
.APPROXIMATE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
94 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(3)),
95 new TmfSyncEventStub(t2
, new TmfTimestamp(5))
97 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.75 beta 1.25 ]]", syncAlgo
.toString());
98 assertEquals(SyncQuality
.ACCURATE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
101 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(4)),
102 new TmfSyncEventStub(t2
, new TmfTimestamp(8))
104 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.75 beta 1.25 ]]", syncAlgo
.toString());
105 assertEquals(SyncQuality
.ACCURATE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
108 new TmfEventDependency(new TmfSyncEventStub(t2
, new TmfTimestamp(4)),
109 new TmfSyncEventStub(t1
, new TmfTimestamp(5))
111 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1.125 beta 0.875 ]]", syncAlgo
.toString());
112 assertEquals(SyncQuality
.ACCURATE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
115 new TmfEventDependency(new TmfSyncEventStub(t2
, new TmfTimestamp(4)),
116 new TmfSyncEventStub(t1
, new TmfTimestamp(6))
118 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1.125 beta 0.875 ]]", syncAlgo
.toString());
119 assertEquals(SyncQuality
.ACCURATE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
122 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(6)),
123 new TmfSyncEventStub(t2
, new TmfTimestamp(7))
125 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 0.725 beta 1.275 ]]", syncAlgo
.toString());
126 assertEquals(SyncQuality
.ACCURATE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
128 ITmfTimestampTransform tt2
= syncAlgo
.getTimestampTransform(t2
);
129 ITmfTimestampTransform tt1
= syncAlgo
.getTimestampTransform(t1
);
131 assertEquals(syncAlgo
.getTimestampTransform(t1
.getHostId()), tt1
);
132 assertEquals(TimestampTransformFactory
.getDefaultTransform(), tt1
);
133 assertEquals(syncAlgo
.getTimestampTransform(t2
.getHostId()), tt2
);
135 /* Make the two hulls intersect */
137 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(7)),
138 new TmfSyncEventStub(t2
, new TmfTimestamp(4))
141 new TmfEventDependency(new TmfSyncEventStub(t2
, new TmfTimestamp(7)),
142 new TmfSyncEventStub(t1
, new TmfTimestamp(3))
144 assertEquals(SyncQuality
.FAIL
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
148 * Testing the fully incremental synchronization algorithm when
149 * communication goes in only one direction
152 public void testOneHull() {
154 SynchronizationAlgorithm syncAlgo
= new SyncAlgorithmFullyIncremental();
156 syncAlgo
.init(fTraces
);
158 assertEquals(SyncQuality
.ABSENT
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
161 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(1)),
162 new TmfSyncEventStub(t2
, new TmfTimestamp(3)))
164 assertEquals(SyncQuality
.INCOMPLETE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
167 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(2)),
168 new TmfSyncEventStub(t2
, new TmfTimestamp(5)))
171 assertEquals(SyncQuality
.INCOMPLETE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
174 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(3)),
175 new TmfSyncEventStub(t2
, new TmfTimestamp(5)))
177 assertEquals(SyncQuality
.INCOMPLETE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
180 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(4)),
181 new TmfSyncEventStub(t2
, new TmfTimestamp(7)))
183 assertEquals(SyncQuality
.INCOMPLETE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
184 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo
.toString());
189 * Testing the fully incremental synchronization algorithm when all
190 * communication from trace1 to trace2 happens before all communication from
194 public void testDisjoint() {
196 SynchronizationAlgorithm syncAlgo
= new SyncAlgorithmFullyIncremental();
198 syncAlgo
.init(fTraces
);
200 assertEquals(SyncQuality
.ABSENT
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
203 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(1)),
204 new TmfSyncEventStub(t2
, new TmfTimestamp(3)))
206 assertEquals(SyncQuality
.INCOMPLETE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
209 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(2)),
210 new TmfSyncEventStub(t2
, new TmfTimestamp(5)))
213 assertEquals(SyncQuality
.INCOMPLETE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
216 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(3)),
217 new TmfSyncEventStub(t2
, new TmfTimestamp(5)))
219 assertEquals(SyncQuality
.INCOMPLETE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
222 new TmfEventDependency(new TmfSyncEventStub(t1
, new TmfTimestamp(4)),
223 new TmfSyncEventStub(t2
, new TmfTimestamp(7)))
225 assertEquals(SyncQuality
.INCOMPLETE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
226 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 0 ]]", syncAlgo
.toString());
229 new TmfEventDependency(new TmfSyncEventStub(t2
, new TmfTimestamp(7)),
230 new TmfSyncEventStub(t1
, new TmfTimestamp(6)))
232 assertEquals(SyncQuality
.APPROXIMATE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
235 new TmfEventDependency(new TmfSyncEventStub(t2
, new TmfTimestamp(8)),
236 new TmfSyncEventStub(t1
, new TmfTimestamp(6)))
238 assertEquals(SyncQuality
.APPROXIMATE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
241 new TmfEventDependency(new TmfSyncEventStub(t2
, new TmfTimestamp(10)),
242 new TmfSyncEventStub(t1
, new TmfTimestamp(8)))
244 assertEquals(SyncQuality
.APPROXIMATE
, syncAlgo
.getSynchronizationQuality(t1
, t2
));
245 assertEquals("SyncAlgorithmFullyIncremental [Between t1 and t2 [ alpha 1 beta 2.5 ]]", syncAlgo
.toString());