1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 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
.IOException
;
18 import java
.net
.URISyntaxException
;
20 import java
.util
.List
;
22 import junit
.framework
.TestCase
;
24 import org
.eclipse
.core
.runtime
.FileLocator
;
25 import org
.eclipse
.core
.runtime
.Path
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
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 * Test suite for the TmfCheckpointIndexTest class.
38 @SuppressWarnings("nls")
39 public class TmfCheckpointIndexTest
extends TestCase
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 private static final String DIRECTORY
= "testfiles";
46 private static final String TEST_STREAM
= "A-Test-10K";
47 private static final int BLOCK_SIZE
= 100;
48 private static final int NB_EVENTS
= 10000;
49 private static TestTrace fTrace
= null;
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 public TmfCheckpointIndexTest(final String name
) throws Exception
{
60 protected void setUp() throws Exception
{
62 fTrace
= setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
66 protected void tearDown() throws Exception
{
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
76 private class TestIndexer
extends TmfCheckpointIndexer
<ITmfTrace
<ITmfEvent
>> {
77 @SuppressWarnings({ "unchecked", "rawtypes" })
78 public TestIndexer(TestTrace testTrace
) {
79 super((ITmfTrace
) testTrace
, BLOCK_SIZE
);
81 public List
<TmfCheckpoint
> getCheckpoints() {
82 return getTraceIndex();
86 private class TestTrace
extends TmfTraceStub
{
87 public TestTrace(String path
, int blockSize
) throws TmfTraceException
{
88 super(path
, blockSize
);
89 setIndexer(new TestIndexer(this));
92 public TestIndexer
getIndexer() {
93 return (TestIndexer
) super.getIndexer();
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
101 private TestTrace
setupTrace(final String path
) {
102 if (fTrace
== null) {
104 final URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(path
), null);
105 final File test
= new File(FileLocator
.toFileURL(location
).toURI());
106 fTrace
= new TestTrace(test
.toURI().getPath(), BLOCK_SIZE
);
108 } catch (final TmfTraceException e
) {
110 } catch (final URISyntaxException e
) {
112 } catch (final IOException e
) {
119 // ------------------------------------------------------------------------
120 // Verify checkpoints
121 // ------------------------------------------------------------------------
123 public void testTmfTraceIndexing() throws Exception
{
124 assertEquals("getCacheSize", BLOCK_SIZE
, fTrace
.getCacheSize());
125 assertEquals("getTraceSize", NB_EVENTS
, fTrace
.getNbEvents());
126 assertEquals("getRange-start", 1, fTrace
.getTimeRange().getStartTime().getValue());
127 assertEquals("getRange-end", NB_EVENTS
, fTrace
.getTimeRange().getEndTime().getValue());
128 assertEquals("getStartTime", 1, fTrace
.getStartTime().getValue());
129 assertEquals("getEndTime", NB_EVENTS
, fTrace
.getEndTime().getValue());
131 List
<TmfCheckpoint
> checkpoints
= fTrace
.getIndexer().getCheckpoints();
132 int pageSize
= fTrace
.getCacheSize();
133 assertTrue("Checkpoints exist", checkpoints
!= null);
134 assertEquals("Checkpoints size", NB_EVENTS
/ BLOCK_SIZE
, checkpoints
.size());
136 // Validate that each checkpoint points to the right event
137 for (int i
= 0; i
< checkpoints
.size(); i
++) {
138 TmfCheckpoint checkpoint
= checkpoints
.get(i
);
139 TmfContext context
= new TmfContext(checkpoint
.getLocation(), i
* pageSize
);
140 ITmfEvent event
= fTrace
.parseEvent(context
);
141 assertTrue(context
.getRank() == i
* pageSize
);
142 assertTrue((checkpoint
.getTimestamp().compareTo(event
.getTimestamp(), false) == 0));
This page took 0.035562 seconds and 6 git commands to generate.