1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 20112 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Adapted for TMF Trace Model 1.0
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.trace
;
17 import java
.io
.FileNotFoundException
;
18 import java
.io
.IOException
;
19 import java
.net
.URISyntaxException
;
21 import java
.util
.Vector
;
23 import junit
.framework
.TestCase
;
25 import org
.eclipse
.core
.runtime
.FileLocator
;
26 import org
.eclipse
.core
.runtime
.Path
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.TmfCoreTestPlugin
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfCheckpoint
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfCheckpointIndexer
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
33 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
36 * <b><u>TmfTraceTest</u></b>
38 * Test suite for the TmfTrace class.
40 @SuppressWarnings("nls")
41 public class TmfCheckpointIndexTest
extends TestCase
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 private static final String DIRECTORY
= "testfiles";
48 private static final String TEST_STREAM
= "A-Test-10K";
49 private static final int BLOCK_SIZE
= 500;
50 private static final int NB_EVENTS
= 10000;
51 private static TestTrace fTrace
= null;
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 public TmfCheckpointIndexTest(final String name
) throws Exception
{
62 protected void setUp() throws Exception
{
64 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
68 protected void tearDown() throws Exception
{
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
78 private class TestIndexer
extends TmfCheckpointIndexer
<ITmfTrace
<ITmfEvent
>> {
79 @SuppressWarnings({ "unchecked", "rawtypes" })
80 public TestIndexer(TestTrace testTrace
) {
81 super((ITmfTrace
) testTrace
);
83 public Vector
<TmfCheckpoint
> getCheckpoints() {
88 private class TestTrace
extends TmfTraceStub
{
89 public TestTrace(String path
, int blockSize
) throws FileNotFoundException
{
90 super(path
, blockSize
);
91 fIndexer
= new TestIndexer(this);
93 public TestIndexer
getIndexer() {
94 return (TestIndexer
) fIndexer
;
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
102 private TestTrace
setupTrace(final String path
) {
103 if (fTrace
== null) {
105 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
106 final File test
= new File(FileLocator
.toFileURL(location
).toURI());
107 fTrace
= new TestTrace(test
.toURI().getPath(), BLOCK_SIZE
);
109 } catch (final URISyntaxException e
) {
111 } catch (final IOException e
) {
118 // ------------------------------------------------------------------------
119 // Verify checkpoints
120 // ------------------------------------------------------------------------
122 public void testTmfTraceIndexing() throws Exception
{
123 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
124 assertEquals("getTraceSize", NB_EVENTS
, fTrace
.getNbEvents());
125 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
126 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
127 assertEquals("getStartTime", 1, fTrace
.getStartTime().getValue());
128 assertEquals("getEndTime", NB_EVENTS
, fTrace
.getEndTime().getValue());
130 Vector
<TmfCheckpoint
> checkpoints
= fTrace
.getIndexer().getCheckpoints();
131 int pageSize
= fTrace
.getCacheSize();
132 assertTrue("Checkpoints exist", checkpoints
!= null);
134 // Validate that each checkpoint points to the right event
135 for (int i
= 0; i
< checkpoints
.size(); i
++) {
136 TmfCheckpoint checkpoint
= checkpoints
.get(i
);
137 TmfContext context
= new TmfContext(checkpoint
.getLocation(), i
* pageSize
);
138 ITmfEvent event
= fTrace
.parseEvent(context
);
139 assertTrue(context
.getRank() == i
* pageSize
);
140 assertTrue((checkpoint
.getTimestamp().compareTo(event
.getTimestamp(), false) == 0));
This page took 0.035217 seconds and 5 git commands to generate.