Fix a pile of Javadoc warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfCheckpointIndexTest.java
CommitLineData
13cb5f43 1/*******************************************************************************
0316808c 2 * Copyright (c) 2009, 2010, 2012 Ericsson
13cb5f43
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
11 * Francois Chouinard - Adapted for TMF Trace Model 1.0
12 *******************************************************************************/
13
14package org.eclipse.linuxtools.tmf.core.tests.trace;
15
16import java.io.File;
13cb5f43
FC
17import java.io.IOException;
18import java.net.URISyntaxException;
19import java.net.URL;
0316808c 20import java.util.List;
13cb5f43
FC
21
22import junit.framework.TestCase;
23
24import org.eclipse.core.runtime.FileLocator;
25import org.eclipse.core.runtime.Path;
26import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
b75d6b65 27import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
b4f71e4a 28import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
13cb5f43 29import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
3427112b 30import org.eclipse.linuxtools.tmf.core.trace.ITmfCheckpoint;
13cb5f43 31import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
13cb5f43
FC
32import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
33import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
b75d6b65 34import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfEmptyTraceStub;
13cb5f43
FC
35import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
36
37/**
0316808c 38 * Test suite for the TmfCheckpointIndexTest class.
13cb5f43
FC
39 */
40@SuppressWarnings("nls")
41public class TmfCheckpointIndexTest extends TestCase {
42
43 // ------------------------------------------------------------------------
44 // Variables
45 // ------------------------------------------------------------------------
46
b75d6b65
FC
47 private static final String DIRECTORY = "testfiles";
48 private static final String TEST_STREAM = "A-Test-10K";
49 private static final int BLOCK_SIZE = 100;
50 private static final int NB_EVENTS = 10000;
51 private static TestTrace fTrace = null;
52 private static EmptyTestTrace fEmptyTrace = null;
13cb5f43
FC
53
54 // ------------------------------------------------------------------------
55 // Housekeeping
56 // ------------------------------------------------------------------------
57
58 public TmfCheckpointIndexTest(final String name) throws Exception {
59 super(name);
60 }
61
62 @Override
63 protected void setUp() throws Exception {
64 super.setUp();
b75d6b65 65 setupTrace(DIRECTORY + File.separator + TEST_STREAM);
13cb5f43
FC
66 }
67
68 @Override
69 protected void tearDown() throws Exception {
70 super.tearDown();
71 fTrace.dispose();
72 fTrace = null;
b75d6b65
FC
73 fEmptyTrace.dispose();
74 fEmptyTrace = null;
13cb5f43
FC
75 }
76
77 // ------------------------------------------------------------------------
78 // Helper classes
79 // ------------------------------------------------------------------------
80
0879b6b9 81 private static class TestIndexer extends TmfCheckpointIndexer<ITmfTrace<ITmfEvent>> {
13cb5f43
FC
82 @SuppressWarnings({ "unchecked", "rawtypes" })
83 public TestIndexer(TestTrace testTrace) {
07671572 84 super((ITmfTrace) testTrace, BLOCK_SIZE);
13cb5f43 85 }
b75d6b65
FC
86 @SuppressWarnings({ "unchecked", "rawtypes" })
87 public TestIndexer(EmptyTestTrace testTrace) {
88 super((ITmfTrace) testTrace, BLOCK_SIZE);
89 }
3427112b 90 public List<ITmfCheckpoint> getCheckpoints() {
0316808c 91 return getTraceIndex();
13cb5f43
FC
92 }
93 }
94
95 private class TestTrace extends TmfTraceStub {
b4f71e4a 96 public TestTrace(String path, int blockSize) throws TmfTraceException {
13cb5f43 97 super(path, blockSize);
0316808c 98 setIndexer(new TestIndexer(this));
13cb5f43 99 }
0316808c 100 @Override
13cb5f43 101 public TestIndexer getIndexer() {
0316808c 102 return (TestIndexer) super.getIndexer();
13cb5f43
FC
103 }
104 }
105
b75d6b65
FC
106 private class EmptyTestTrace extends TmfEmptyTraceStub {
107 public EmptyTestTrace() {
108 super();
109 setIndexer(new TestIndexer(this));
110 }
111 @Override
112 public TestIndexer getIndexer() {
113 return (TestIndexer) super.getIndexer();
114 }
115 }
116
13cb5f43
FC
117 // ------------------------------------------------------------------------
118 // Helper functions
119 // ------------------------------------------------------------------------
120
b75d6b65 121 private synchronized void setupTrace(final String path) {
13cb5f43
FC
122 if (fTrace == null) {
123 try {
124 final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
125 final File test = new File(FileLocator.toFileURL(location).toURI());
126 fTrace = new TestTrace(test.toURI().getPath(), BLOCK_SIZE);
127 fTrace.indexTrace();
b4f71e4a
FC
128 } catch (final TmfTraceException e) {
129 e.printStackTrace();
13cb5f43
FC
130 } catch (final URISyntaxException e) {
131 e.printStackTrace();
132 } catch (final IOException e) {
133 e.printStackTrace();
134 }
135 }
b75d6b65
FC
136
137 if (fEmptyTrace == null) {
138 fEmptyTrace = new EmptyTestTrace();
139 fEmptyTrace.indexTrace();
140 }
13cb5f43
FC
141 }
142
143 // ------------------------------------------------------------------------
144 // Verify checkpoints
145 // ------------------------------------------------------------------------
146
147 public void testTmfTraceIndexing() throws Exception {
148 assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize());
149 assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents());
150 assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
151 assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue());
152 assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
153 assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue());
154
3427112b 155 List<ITmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
13cb5f43
FC
156 int pageSize = fTrace.getCacheSize();
157 assertTrue("Checkpoints exist", checkpoints != null);
07671572 158 assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE, checkpoints.size());
13cb5f43
FC
159
160 // Validate that each checkpoint points to the right event
161 for (int i = 0; i < checkpoints.size(); i++) {
3427112b 162 ITmfCheckpoint checkpoint = checkpoints.get(i);
13cb5f43
FC
163 TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
164 ITmfEvent event = fTrace.parseEvent(context);
165 assertTrue(context.getRank() == i * pageSize);
166 assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
167 }
168 }
169
b75d6b65
FC
170 public void testEmptyTmfTraceIndexing() throws Exception {
171 assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, fEmptyTrace.getCacheSize());
172 assertEquals("getTraceSize", 0, fEmptyTrace.getNbEvents());
173 assertEquals("getRange-start", TmfTimestamp.BIG_CRUNCH, fEmptyTrace.getTimeRange().getStartTime());
174 assertEquals("getRange-end", TmfTimestamp.BIG_BANG, fEmptyTrace.getTimeRange().getEndTime());
175 assertEquals("getStartTime", TmfTimestamp.BIG_CRUNCH, fEmptyTrace.getStartTime());
176 assertEquals("getEndTime", TmfTimestamp.BIG_BANG, fEmptyTrace.getEndTime());
177
3427112b 178 List<ITmfCheckpoint> checkpoints = fEmptyTrace.getIndexer().getCheckpoints();
b75d6b65
FC
179 int pageSize = fEmptyTrace.getCacheSize();
180 assertTrue("Checkpoints exist", checkpoints != null);
181 assertEquals("Checkpoints size", 0, checkpoints.size());
182
183 // Validate that each checkpoint points to the right event
184 for (int i = 0; i < checkpoints.size(); i++) {
3427112b 185 ITmfCheckpoint checkpoint = checkpoints.get(i);
b75d6b65
FC
186 TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
187 ITmfEvent event = fEmptyTrace.parseEvent(context);
188 assertTrue(context.getRank() == i * pageSize);
189 assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
190 }
191 }
192
13cb5f43 193}
This page took 0.037982 seconds and 5 git commands to generate.