1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.tests
.trace
.indexer
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertTrue
;
18 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.trace
.indexer
.TmfMemoryIndex
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.indexer
.checkpoint
.ITmfCheckpoint
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.indexer
.checkpoint
.TmfCheckpoint
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.TmfLongLocation
;
23 import org
.junit
.Test
;
26 * Test for the TmfMemoryIndex class
28 * @author Marc-Andre Laperle
30 public class TmfMemoryIndexTest
extends AbstractCheckpointCollectionTest
{
32 private TmfMemoryIndex fMemoryIndex
;
35 protected TmfMemoryIndex
createCollection() {
36 fCheckpointCollection
= fMemoryIndex
= new TmfMemoryIndex(getTrace());
41 * Test a single insertion
45 public void testInsert() {
46 TmfCheckpoint checkpoint
= new TmfCheckpoint(new TmfTimestamp(12345), new TmfLongLocation(123456L), 0);
47 fMemoryIndex
.insert(checkpoint
);
49 ITmfCheckpoint indexCheckpoint
= fMemoryIndex
.get(0);
50 assertEquals(checkpoint
, indexCheckpoint
);
52 long found
= fMemoryIndex
.binarySearch(checkpoint
);
53 assertEquals(0, found
);
57 * Tests that binarySearch find the correct checkpoint and ends with a perfect match
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
);
66 TmfCheckpoint expectedCheckpoint
= new TmfCheckpoint(new TmfTimestamp(122), new TmfLongLocation(122L), 0);
67 int expectedRank
= 122;
69 long rank
= fMemoryIndex
.binarySearch(expectedCheckpoint
);
70 ITmfCheckpoint found
= fMemoryIndex
.get(rank
);
72 assertEquals(expectedRank
, rank
);
73 assertEquals(found
, expectedCheckpoint
);
80 public void testDispose() {
81 fMemoryIndex
.dispose();
82 assertTrue(fMemoryIndex
.isEmpty());