4a65cf04b4070a63c1cf849c921c25a2ec2c5831
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core.tests / src / org / eclipse / tracecompass / lttng2 / kernel / core / tests / event / matchandsync / ExperimentSyncTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
3 *
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
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.lttng2.kernel.core.tests.event.matchandsync;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assume.assumeTrue;
17
18 import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpEventMatching;
19 import org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
20 import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching;
21 import org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform;
22 import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm;
23 import org.eclipse.tracecompass.tmf.core.synchronization.TimestampTransformFactory;
24 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
25 import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
26 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
27 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30
31 /**
32 * Tests for experiment syncing
33 *
34 * @author Geneviève Bastien
35 */
36 @SuppressWarnings("nls")
37 public class ExperimentSyncTest {
38
39 private static final String EXPERIMENT = "MyExperiment";
40 private static int BLOCK_SIZE = 1000;
41
42 /**
43 * Initialize some data
44 */
45 @BeforeClass
46 public static void setUp() {
47 TmfEventMatching.registerMatchObject(new TcpEventMatching());
48 TmfEventMatching.registerMatchObject(new TcpLttngEventMatching());
49 }
50
51 /**
52 * Testing experiment synchronization
53 */
54 @Test
55 public void testExperimentSync() {
56 assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
57 assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
58 try (CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace();
59 CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace();) {
60
61 ITmfTrace[] traces = { trace1, trace2 };
62 TmfExperiment experiment = new TmfExperiment(traces[0].getEventType(), EXPERIMENT, traces, BLOCK_SIZE, null);
63
64 SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
65
66 ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(trace1);
67 ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(trace2);
68
69 trace1.setTimestampTransform(tt1);
70 trace2.setTimestampTransform(tt2);
71
72 assertEquals("TmfTimestampTransformLinearFast [ slope = 0.9999413783703139011056845831168394, offset = 79796507913179.33347660124688298171 ]", tt1.toString());
73 assertEquals(TimestampTransformFactory.getDefaultTransform(), tt2);
74
75 assertEquals(syncAlgo.getTimestampTransform(trace1.getHostId()), trace1.getTimestampTransform());
76 assertEquals(syncAlgo.getTimestampTransform(trace2.getHostId()), trace2.getTimestampTransform());
77
78 }
79 }
80
81 /**
82 * Testing synchronization with 3 traces, one of which synchronizes with
83 * both other
84 */
85 @Test
86 public void testDjangoExperimentSync() {
87 assumeTrue(CtfTmfTestTrace.DJANGO_CLIENT.exists());
88 assumeTrue(CtfTmfTestTrace.DJANGO_DB.exists());
89 assumeTrue(CtfTmfTestTrace.DJANGO_HTTPD.exists());
90 try (CtfTmfTrace trace1 = CtfTmfTestTrace.DJANGO_CLIENT.getTrace();
91 CtfTmfTrace trace2 = CtfTmfTestTrace.DJANGO_DB.getTrace();
92 CtfTmfTrace trace3 = CtfTmfTestTrace.DJANGO_HTTPD.getTrace();) {
93 ITmfTrace[] traces = { trace1, trace2, trace3 };
94 TmfExperiment experiment = new TmfExperiment(traces[0].getEventType(), EXPERIMENT, traces, BLOCK_SIZE, null);
95
96 SynchronizationAlgorithm syncAlgo = experiment.synchronizeTraces(true);
97
98 ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(trace1);
99 ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(trace2);
100 ITmfTimestampTransform tt3 = syncAlgo.getTimestampTransform(trace3);
101
102 trace1.setTimestampTransform(tt1);
103 trace2.setTimestampTransform(tt2);
104 trace3.setTimestampTransform(tt3);
105
106 assertEquals(TimestampTransformFactory.getDefaultTransform(), tt1);
107 assertEquals("TmfTimestampTransformLinearFast [ slope = 0.9999996313017589597204633828681240, offset = 498490309972.0038068817738527724192 ]", tt2.toString());
108 assertEquals("TmfTimestampTransformLinearFast [ slope = 1.000000119014882262265342419815932, offset = -166652893534.6189900382736187431134 ]", tt3.toString());
109
110 }
111 }
112 }
This page took 0.033385 seconds and 4 git commands to generate.