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