ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / indexer / TmfMemoryIndexTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.tests.trace.indexer;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertTrue;
17
18 import org.eclipse.linuxtools.internal.tmf.core.trace.indexer.TmfMemoryIndex;
19 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
20 import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
21 import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpoint;
22 import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
23 import org.junit.Test;
24
25 /**
26 * Test for the TmfMemoryIndex class
27 *
28 * @author Marc-Andre Laperle
29 */
30 public class TmfMemoryIndexTest extends AbstractCheckpointCollectionTest {
31
32 private TmfMemoryIndex fMemoryIndex;
33
34 @Override
35 protected TmfMemoryIndex createCollection() {
36 fCheckpointCollection = fMemoryIndex = new TmfMemoryIndex(getTrace());
37 return fMemoryIndex;
38 }
39
40 /**
41 * Test a single insertion
42 */
43 @Override
44 @Test
45 public void testInsert() {
46 TmfCheckpoint checkpoint = new TmfCheckpoint(new TmfTimestamp(12345), new TmfLongLocation(123456L), 0);
47 fMemoryIndex.insert(checkpoint);
48
49 ITmfCheckpoint indexCheckpoint = fMemoryIndex.get(0);
50 assertEquals(checkpoint, indexCheckpoint);
51
52 long found = fMemoryIndex.binarySearch(checkpoint);
53 assertEquals(0, found);
54 }
55
56 /**
57 * Tests that binarySearch find the correct checkpoint and ends with a perfect match
58 */
59 @Test
60 public void testBinarySearch() {
61 for (long i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
62 TmfCheckpoint checkpoint = new TmfCheckpoint(new TmfTimestamp(i), new TmfLongLocation(i), 0);
63 fMemoryIndex.insert(checkpoint);
64 }
65
66 TmfCheckpoint expectedCheckpoint = new TmfCheckpoint(new TmfTimestamp(122), new TmfLongLocation(122L), 0);
67 int expectedRank = 122;
68
69 long rank = fMemoryIndex.binarySearch(expectedCheckpoint);
70 ITmfCheckpoint found = fMemoryIndex.get(rank);
71
72 assertEquals(expectedRank, rank);
73 assertEquals(found, expectedCheckpoint);
74 }
75
76 /**
77 * Test dispose
78 */
79 @Test
80 public void testDispose() {
81 fMemoryIndex.dispose();
82 assertTrue(fMemoryIndex.isEmpty());
83 }
84 }
This page took 0.033724 seconds and 5 git commands to generate.