Fix another pile of Javadoc warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfExperimentCheckpointIndexTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.tests.trace;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.net.URL;
19 import java.util.List;
20
21 import junit.framework.TestCase;
22
23 import org.eclipse.core.runtime.FileLocator;
24 import org.eclipse.core.runtime.Path;
25 import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext;
26 import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation;
27 import org.eclipse.linuxtools.internal.tmf.core.trace.TmfLocationArray;
28 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
29 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
30 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
31 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
32 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
33 import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
34 import org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint;
35 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
36 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
37 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
38 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub;
39 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
40
41 /**
42 * Test suite for the TmfCheckpointIndexTest class.
43 */
44 @SuppressWarnings({"nls","javadoc"})
45 public class TmfExperimentCheckpointIndexTest extends TestCase {
46
47 // ------------------------------------------------------------------------
48 // Attributes
49 // ------------------------------------------------------------------------
50
51 private static final String DIRECTORY = "testfiles";
52 private static final String TEST_STREAM1 = "O-Test-10K";
53 private static final String TEST_STREAM2 = "E-Test-10K";
54 private static final String EXPERIMENT = "MyExperiment";
55 private static int NB_EVENTS = 20000;
56 private static int BLOCK_SIZE = 1000;
57
58 private static ITmfTrace<TmfEvent>[] fTestTraces;
59 private static TmfExperimentStub<TmfEvent> fExperiment;
60
61 // ------------------------------------------------------------------------
62 // Housekeeping
63 // ------------------------------------------------------------------------
64
65 /**
66 * @param name the test name
67 */
68 public TmfExperimentCheckpointIndexTest(final String name) {
69 super(name);
70 }
71
72 @Override
73 protected synchronized void setUp() throws Exception {
74 super.setUp();
75 if (fExperiment == null) {
76 setupTrace(DIRECTORY + File.separator + TEST_STREAM1, DIRECTORY + File.separator + TEST_STREAM2);
77 fExperiment = new TmfExperimentStub<TmfEvent>(EXPERIMENT, fTestTraces, BLOCK_SIZE);
78 fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
79 }
80 }
81
82 @Override
83 protected void tearDown() throws Exception {
84 super.tearDown();
85 fExperiment.dispose();
86 fExperiment = null;
87 fTestTraces = null;
88 }
89
90 @SuppressWarnings("unchecked")
91 private synchronized static ITmfTrace<?>[] setupTrace(final String path1, final String path2) {
92 if (fTestTraces == null) {
93 fTestTraces = new ITmfTrace[2];
94 try {
95 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null);
96 File test = new File(FileLocator.toFileURL(location).toURI());
97 final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true);
98 fTestTraces[0] = trace1;
99 location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null);
100 test = new File(FileLocator.toFileURL(location).toURI());
101 final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true);
102 fTestTraces[1] = trace2;
103 } catch (final TmfTraceException e) {
104 e.printStackTrace();
105 } catch (final URISyntaxException e) {
106 e.printStackTrace();
107 } catch (final IOException e) {
108 e.printStackTrace();
109 }
110 }
111 return fTestTraces;
112 }
113
114 // ------------------------------------------------------------------------
115 // Verify checkpoints
116 // ------------------------------------------------------------------------
117
118 @SuppressWarnings("null")
119 public void testTmfTraceIndexing() {
120 assertEquals("getCacheSize", BLOCK_SIZE, fExperiment.getCacheSize());
121 assertEquals("getTraceSize", NB_EVENTS, fExperiment.getNbEvents());
122 assertEquals("getRange-start", 1, fExperiment.getTimeRange().getStartTime().getValue());
123 assertEquals("getRange-end", NB_EVENTS, fExperiment.getTimeRange().getEndTime().getValue());
124 assertEquals("getStartTime", 1, fExperiment.getStartTime().getValue());
125 assertEquals("getEndTime", NB_EVENTS, fExperiment.getEndTime().getValue());
126
127 List<ITmfCheckpoint> checkpoints = fExperiment.getIndexer().getCheckpoints();
128 int pageSize = fExperiment.getCacheSize();
129 assertTrue("Checkpoints exist", checkpoints != null);
130 assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
131
132 // Validate that each checkpoint points to the right event
133 for (int i = 0; i < checkpoints.size(); i++) {
134 ITmfCheckpoint checkpoint = checkpoints.get(i);
135 TmfExperimentLocation expLocation = (TmfExperimentLocation) checkpoint.getLocation();
136 TmfLocationArray locations = expLocation.getLocation();
137 ITmfContext[] trcContexts = new ITmfContext[2];
138 trcContexts[0] = new TmfContext(locations.getLocations()[0], (i * pageSize) / 2);
139 trcContexts[1] = new TmfContext(locations.getLocations()[1], (i * pageSize) / 2);
140 TmfExperimentContext expContext = new TmfExperimentContext(trcContexts);
141 expContext.getEvents()[0] = fTestTraces[0].getNext(fTestTraces[0].seekEvent((i * pageSize) / 2));
142 expContext.getEvents()[1] = fTestTraces[1].getNext(fTestTraces[1].seekEvent((i * pageSize) / 2));
143 ITmfEvent event = fExperiment.parseEvent(expContext);
144 assertTrue(expContext.getRank() == i * pageSize);
145 assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
146 }
147 }
148
149 // ------------------------------------------------------------------------
150 // Streaming
151 // ------------------------------------------------------------------------
152
153 @SuppressWarnings("null")
154 public void testGrowingIndex() {
155
156 ITmfTrace<TmfEvent>[] testTraces = new TmfTraceStub[2];
157 try {
158 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM1), null);
159 File test = new File(FileLocator.toFileURL(location).toURI());
160 final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, false);
161 testTraces[0] = trace1;
162 location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM2), null);
163 test = new File(FileLocator.toFileURL(location).toURI());
164 final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, false);
165 testTraces[1] = trace2;
166 } catch (final TmfTraceException e) {
167 e.printStackTrace();
168 } catch (final URISyntaxException e) {
169 e.printStackTrace();
170 } catch (final IOException e) {
171 e.printStackTrace();
172 }
173
174 TmfExperimentStub<TmfEvent> experiment = new TmfExperimentStub<TmfEvent>(EXPERIMENT, testTraces, BLOCK_SIZE);
175 int pageSize = experiment.getCacheSize();
176
177 // Build the first half of the index
178 TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(1, -3), new TmfTimestamp(NB_EVENTS / 2 - 1, -3));
179 experiment.getIndexer().buildIndex(0, range, true);
180
181 // Validate that each checkpoint points to the right event
182 List<ITmfCheckpoint> checkpoints = experiment.getIndexer().getCheckpoints();
183 assertTrue("Checkpoints exist", checkpoints != null);
184 assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE / 2, checkpoints.size());
185
186 // Build the second half of the index
187 experiment.getIndexer().buildIndex(NB_EVENTS / 2, TmfTimeRange.ETERNITY, true);
188
189 // Validate that each checkpoint points to the right event
190 assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
191 for (int i = 0; i < checkpoints.size(); i++) {
192 ITmfCheckpoint checkpoint = checkpoints.get(i);
193 TmfExperimentLocation expLocation = (TmfExperimentLocation) checkpoint.getLocation();
194 TmfLocationArray locations = expLocation.getLocation();
195 ITmfContext[] trcContexts = new ITmfContext[2];
196 trcContexts[0] = new TmfContext(locations.getLocations()[0], (i * pageSize) / 2);
197 trcContexts[1] = new TmfContext(locations.getLocations()[1], (i * pageSize) / 2);
198 TmfExperimentContext expContext = new TmfExperimentContext(trcContexts);
199 expContext.getEvents()[0] = testTraces[0].getNext(testTraces[0].seekEvent((i * pageSize) / 2));
200 expContext.getEvents()[1] = testTraces[1].getNext(testTraces[1].seekEvent((i * pageSize) / 2));
201 ITmfEvent event = experiment.parseEvent(expContext);
202 assertTrue(expContext.getRank() == i * pageSize);
203 assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
204 assertEquals("Checkpoint value", i * pageSize + 1, checkpoint.getTimestamp().getValue());
205 }
206 }
207
208 }
This page took 0.035651 seconds and 5 git commands to generate.