tmf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / indexer / FlatArrayTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
17 import java.util.ArrayList;
18
19 import org.eclipse.linuxtools.internal.tmf.core.trace.indexer.FlatArray;
20 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
21 import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
22 import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
23 import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpoint;
24 import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
25 import org.junit.Test;
26
27 /**
28 * Tests for the FlatArray class
29 *
30 * @author Marc-Andre Laperle
31 */
32 public class FlatArrayTest extends AbstractCheckpointCollectionTest {
33
34 private FlatArray fFlatArray;
35
36 @Override
37 protected FlatArray createCollection() {
38 fCheckpointCollection = fFlatArray = new FlatArray(getFile(), (ITmfPersistentlyIndexable) getTrace());
39 return fFlatArray;
40 }
41
42 @Override
43 public boolean isPersistableCollection() {
44 return true;
45 }
46
47 /**
48 * Tests that binarySearch find the correct checkpoint and ends with a
49 * perfect match
50 */
51 @Test
52 public void testBinarySearch() {
53 for (long i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
54 TmfCheckpoint checkpoint = new TmfCheckpoint(new TmfTimestamp(i), new TmfLongLocation(i), 0);
55 fFlatArray.insert(checkpoint);
56 }
57
58 TmfCheckpoint expectedCheckpoint = new TmfCheckpoint(new TmfTimestamp(122), new TmfLongLocation(122L), 0);
59 int expectedRank = 122;
60
61 long rank = fFlatArray.binarySearch(expectedCheckpoint);
62 ITmfCheckpoint found = fFlatArray.get(rank);
63
64 assertEquals(expectedRank, rank);
65 assertEquals(found, expectedCheckpoint);
66 }
67
68 /**
69 * Test many checkpoint insertions. Make sure they can be found after
70 * re-opening the file
71 */
72 @Test
73 public void testInsertAlotCheckEquals() {
74 ArrayList<Integer> list = insertAlot();
75
76 fFlatArray = createCollection();
77
78 for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
79 int checkpointIndex = list.get(i);
80 TmfCheckpoint checkpoint = new TmfCheckpoint(new TmfTimestamp(12345 + checkpointIndex),
81 new TmfLongLocation(123456L + checkpointIndex), checkpointIndex);
82 ITmfCheckpoint found = fFlatArray.get(checkpointIndex);
83 assertEquals(checkpoint, found);
84 }
85 }
86
87 }
This page took 0.033037 seconds and 5 git commands to generate.