tmf: Disable NLS warnings in tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfExperimentCheckpointIndexTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 * Alexandre Montplaisir - Port to JUnit4
12 * Patrick Tasse - Updated for ranks in experiment location
13 *******************************************************************************/
14
15 package org.eclipse.linuxtools.tmf.core.tests.trace;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertTrue;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.net.URISyntaxException;
23 import java.net.URL;
24 import java.util.List;
25
26 import org.eclipse.core.runtime.FileLocator;
27 import org.eclipse.core.runtime.Path;
28 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
29 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
30 import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
31 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
32 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
33 import org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint;
34 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
35 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
36 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
37 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub;
38 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42
43 /**
44 * Test suite for the TmfCheckpointIndexTest class.
45 */
46 @SuppressWarnings("javadoc")
47 public class TmfExperimentCheckpointIndexTest {
48
49 // ------------------------------------------------------------------------
50 // Attributes
51 // ------------------------------------------------------------------------
52
53 private static final String DIRECTORY = "testfiles";
54 private static final String TEST_STREAM1 = "O-Test-10K";
55 private static final String TEST_STREAM2 = "E-Test-10K";
56 private static final String EXPERIMENT = "MyExperiment";
57 private static int NB_EVENTS = 20000;
58 private static int BLOCK_SIZE = 1000;
59
60 private static ITmfTrace[] fTestTraces;
61 private static TmfExperimentStub fExperiment;
62
63 // ------------------------------------------------------------------------
64 // Housekeeping
65 // ------------------------------------------------------------------------
66
67 @Before
68 public void setUp() {
69 setupTraces();
70 fExperiment = new TmfExperimentStub(EXPERIMENT, fTestTraces, BLOCK_SIZE);
71 fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
72 }
73
74 @After
75 public void tearDown() {
76 fExperiment.dispose();
77 fExperiment = null;
78 for (ITmfTrace trace : fTestTraces) {
79 trace.dispose();
80 }
81 fTestTraces = null;
82 }
83
84 private static void setupTraces() {
85 final String path1 = DIRECTORY + File.separator + TEST_STREAM1;
86 final String path2 = DIRECTORY + File.separator + TEST_STREAM2;
87
88 fTestTraces = new ITmfTrace[2];
89 try {
90 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null);
91 File test = new File(FileLocator.toFileURL(location).toURI());
92 final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true);
93 fTestTraces[0] = trace1;
94 location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null);
95 test = new File(FileLocator.toFileURL(location).toURI());
96 final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true);
97 fTestTraces[1] = trace2;
98 } catch (final TmfTraceException e) {
99 e.printStackTrace();
100 } catch (final URISyntaxException e) {
101 e.printStackTrace();
102 } catch (final IOException e) {
103 e.printStackTrace();
104 }
105 }
106
107 // ------------------------------------------------------------------------
108 // Verify checkpoints
109 // ------------------------------------------------------------------------
110
111 @Test
112 @SuppressWarnings("null")
113 public void testTmfTraceIndexing() {
114 assertEquals("getCacheSize", BLOCK_SIZE, fExperiment.getCacheSize());
115 assertEquals("getTraceSize", NB_EVENTS, fExperiment.getNbEvents());
116 assertEquals("getRange-start", 1, fExperiment.getTimeRange().getStartTime().getValue());
117 assertEquals("getRange-end", NB_EVENTS, fExperiment.getTimeRange().getEndTime().getValue());
118 assertEquals("getStartTime", 1, fExperiment.getStartTime().getValue());
119 assertEquals("getEndTime", NB_EVENTS, fExperiment.getEndTime().getValue());
120
121 List<ITmfCheckpoint> checkpoints = fExperiment.getIndexer().getCheckpoints();
122 int pageSize = fExperiment.getCacheSize();
123 assertTrue("Checkpoints exist", checkpoints != null);
124 assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
125
126 // Validate that each checkpoint points to the right event
127 for (int i = 0; i < checkpoints.size(); i++) {
128 ITmfCheckpoint checkpoint = checkpoints.get(i);
129 ITmfLocation location = checkpoint.getLocation();
130 ITmfContext context = fExperiment.seekEvent(location);
131 ITmfEvent event = fExperiment.parseEvent(context);
132 assertTrue(context.getRank() == i * pageSize);
133 assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
134 }
135 }
136
137 // ------------------------------------------------------------------------
138 // Streaming
139 // ------------------------------------------------------------------------
140
141 @Test
142 @SuppressWarnings("null")
143 public void testGrowingIndex() {
144 ITmfTrace[] testTraces = new TmfTraceStub[2];
145 try {
146 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM1), null);
147 File test = new File(FileLocator.toFileURL(location).toURI());
148 final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, false);
149 testTraces[0] = trace1;
150 location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM2), null);
151 test = new File(FileLocator.toFileURL(location).toURI());
152 final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, false);
153 testTraces[1] = trace2;
154 } catch (final TmfTraceException e) {
155 e.printStackTrace();
156 } catch (final URISyntaxException e) {
157 e.printStackTrace();
158 } catch (final IOException e) {
159 e.printStackTrace();
160 }
161
162 TmfExperimentStub experiment = new TmfExperimentStub(EXPERIMENT, testTraces, BLOCK_SIZE);
163 int pageSize = experiment.getCacheSize();
164
165 // Build the first half of the index
166 TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(1, -3), new TmfTimestamp(NB_EVENTS / 2 - 1, -3));
167 experiment.getIndexer().buildIndex(0, range, true);
168
169 // Validate that each checkpoint points to the right event
170 List<ITmfCheckpoint> checkpoints = experiment.getIndexer().getCheckpoints();
171 assertTrue("Checkpoints exist", checkpoints != null);
172 assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE / 2, checkpoints.size());
173
174 // Build the second half of the index
175 experiment.getIndexer().buildIndex(NB_EVENTS / 2, TmfTimeRange.ETERNITY, true);
176
177 // Validate that each checkpoint points to the right event
178 assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
179 for (int i = 0; i < checkpoints.size(); i++) {
180 ITmfCheckpoint checkpoint = checkpoints.get(i);
181 ITmfLocation location = checkpoint.getLocation();
182 ITmfContext context = experiment.seekEvent(location);
183 ITmfEvent event = experiment.parseEvent(context);
184 assertTrue(context.getRank() == i * pageSize);
185 assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
186 assertEquals("Checkpoint value", i * pageSize + 1, checkpoint.getTimestamp().getValue());
187 }
188
189 /* Clean up (since we didn't use the class-specific fixtures) */
190 experiment.dispose();
191 for (ITmfTrace trace : testTraces) {
192 trace.dispose();
193 }
194 }
195
196 }
This page took 0.036663 seconds and 5 git commands to generate.