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; | |
21924e03 MAL |
59 | private static int LAST_EVENT_RANK = NB_EVENTS - 1; |
60 | private static int LAST_CHECKPOINT_RANK = LAST_EVENT_RANK / BLOCK_SIZE; | |
61 | private static int NB_CHECKPOINTS = LAST_CHECKPOINT_RANK + 1; | |
07671572 | 62 | |
6256d8ad AM |
63 | private static ITmfTrace[] fTestTraces; |
64 | private static TmfExperimentStub fExperiment; | |
07671572 FC |
65 | |
66 | // ------------------------------------------------------------------------ | |
67 | // Housekeeping | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
6e1886bc AM |
70 | @Before |
71 | public void setUp() { | |
72 | setupTraces(); | |
73 | fExperiment = new TmfExperimentStub(EXPERIMENT, fTestTraces, BLOCK_SIZE); | |
74 | fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true); | |
07671572 FC |
75 | } |
76 | ||
6e1886bc AM |
77 | @After |
78 | public void tearDown() { | |
07671572 FC |
79 | fExperiment.dispose(); |
80 | fExperiment = null; | |
6e1886bc AM |
81 | for (ITmfTrace trace : fTestTraces) { |
82 | trace.dispose(); | |
83 | } | |
3427112b | 84 | fTestTraces = null; |
07671572 FC |
85 | } |
86 | ||
6e1886bc | 87 | private static void setupTraces() { |
6e1886bc AM |
88 | |
89 | fTestTraces = new ITmfTrace[2]; | |
90 | try { | |
9c4d52ee | 91 | URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE1.getFullPath()), null); |
6e1886bc | 92 | File test = new File(FileLocator.toFileURL(location).toURI()); |
ab186fbb | 93 | final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true, null); |
6e1886bc | 94 | fTestTraces[0] = trace1; |
9c4d52ee | 95 | location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE2.getFullPath()), null); |
6e1886bc | 96 | test = new File(FileLocator.toFileURL(location).toURI()); |
ab186fbb | 97 | final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true, null); |
6e1886bc AM |
98 | fTestTraces[1] = trace2; |
99 | } catch (final TmfTraceException e) { | |
100 | e.printStackTrace(); | |
101 | } catch (final URISyntaxException e) { | |
102 | e.printStackTrace(); | |
103 | } catch (final IOException e) { | |
104 | e.printStackTrace(); | |
07671572 | 105 | } |
07671572 FC |
106 | } |
107 | ||
108 | // ------------------------------------------------------------------------ | |
109 | // Verify checkpoints | |
110 | // ------------------------------------------------------------------------ | |
111 | ||
6e1886bc | 112 | @Test |
54a7a54c | 113 | public void testTmfTraceIndexing() { |
07671572 FC |
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 | ||
032ecd45 | 121 | ITmfCheckpointIndex checkpoints = fExperiment.getIndexer().getCheckpoints(); |
07671572 FC |
122 | int pageSize = fExperiment.getCacheSize(); |
123 | assertTrue("Checkpoints exist", checkpoints != null); | |
21924e03 | 124 | assertEquals("Checkpoints size", NB_CHECKPOINTS, checkpoints.size()); |
07671572 FC |
125 | |
126 | // Validate that each checkpoint points to the right event | |
127 | for (int i = 0; i < checkpoints.size(); i++) { | |
3427112b | 128 | ITmfCheckpoint checkpoint = checkpoints.get(i); |
ea271da6 PT |
129 | ITmfLocation location = checkpoint.getLocation(); |
130 | ITmfContext context = fExperiment.seekEvent(location); | |
131 | ITmfEvent event = fExperiment.parseEvent(context); | |
132 | assertTrue(context.getRank() == i * pageSize); | |
065cc19b | 133 | assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp()) == 0)); |
07671572 FC |
134 | } |
135 | } | |
136 | ||
3427112b FC |
137 | // ------------------------------------------------------------------------ |
138 | // Streaming | |
139 | // ------------------------------------------------------------------------ | |
140 | ||
6e1886bc | 141 | @Test |
54a7a54c | 142 | public void testGrowingIndex() { |
6256d8ad | 143 | ITmfTrace[] testTraces = new TmfTraceStub[2]; |
3427112b | 144 | try { |
9c4d52ee | 145 | URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE1.getFullPath()), null); |
3427112b | 146 | File test = new File(FileLocator.toFileURL(location).toURI()); |
ab186fbb | 147 | final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, false, null); |
3427112b | 148 | testTraces[0] = trace1; |
9c4d52ee | 149 | location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE2.getFullPath()), null); |
3427112b | 150 | test = new File(FileLocator.toFileURL(location).toURI()); |
ab186fbb | 151 | final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, false, null); |
3427112b FC |
152 | testTraces[1] = trace2; |
153 | } catch (final TmfTraceException e) { | |
154 | e.printStackTrace(); | |
155 | } catch (final URISyntaxException e) { | |
156 | e.printStackTrace(); | |
157 | } catch (final IOException e) { | |
158 | e.printStackTrace(); | |
159 | } | |
160 | ||
6256d8ad | 161 | TmfExperimentStub experiment = new TmfExperimentStub(EXPERIMENT, testTraces, BLOCK_SIZE); |
3427112b FC |
162 | int pageSize = experiment.getCacheSize(); |
163 | ||
164 | // Build the first half of the index | |
165 | TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(1, -3), new TmfTimestamp(NB_EVENTS / 2 - 1, -3)); | |
166 | experiment.getIndexer().buildIndex(0, range, true); | |
167 | ||
168 | // Validate that each checkpoint points to the right event | |
032ecd45 | 169 | ITmfCheckpointIndex checkpoints = experiment.getIndexer().getCheckpoints(); |
3427112b | 170 | assertTrue("Checkpoints exist", checkpoints != null); |
21924e03 | 171 | assertEquals("Checkpoints size", NB_CHECKPOINTS / 2, checkpoints.size()); |
3427112b FC |
172 | |
173 | // Build the second half of the index | |
174 | experiment.getIndexer().buildIndex(NB_EVENTS / 2, TmfTimeRange.ETERNITY, true); | |
175 | ||
176 | // Validate that each checkpoint points to the right event | |
21924e03 | 177 | assertEquals("Checkpoints size", NB_CHECKPOINTS, checkpoints.size()); |
3427112b FC |
178 | for (int i = 0; i < checkpoints.size(); i++) { |
179 | ITmfCheckpoint checkpoint = checkpoints.get(i); | |
ea271da6 PT |
180 | ITmfLocation location = checkpoint.getLocation(); |
181 | ITmfContext context = experiment.seekEvent(location); | |
182 | ITmfEvent event = experiment.parseEvent(context); | |
183 | assertTrue(context.getRank() == i * pageSize); | |
065cc19b | 184 | assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp()) == 0)); |
3427112b FC |
185 | assertEquals("Checkpoint value", i * pageSize + 1, checkpoint.getTimestamp().getValue()); |
186 | } | |
6e1886bc AM |
187 | |
188 | /* Clean up (since we didn't use the class-specific fixtures) */ | |
189 | experiment.dispose(); | |
190 | for (ITmfTrace trace : testTraces) { | |
191 | trace.dispose(); | |
192 | } | |
3427112b FC |
193 | } |
194 | ||
07671572 | 195 | } |