1 /*******************************************************************************
2 * Copyright (c) 2013 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
.linuxtools
.tmf
.core
.tests
.trace
.indexer
;
15 import static org
.junit
.Assert
.assertEquals
;
17 import java
.util
.ArrayList
;
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
;
28 * Tests for the FlatArray class
30 * @author Marc-Andre Laperle
32 public class FlatArrayTest
extends AbstractCheckpointCollectionTest
{
34 private FlatArray fFlatArray
;
37 protected FlatArray
createCollection() {
38 fFlatArray
= new FlatArray(getFile(), (ITmfPersistentlyIndexable
) getTrace());
43 public boolean isPersistableCollection() {
48 * Tests that binarySearch find the correct checkpoint and ends with a
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
);
58 TmfCheckpoint expectedCheckpoint
= new TmfCheckpoint(new TmfTimestamp(122), new TmfLongLocation(122L), 0);
59 int expectedRank
= 122;
61 long rank
= fFlatArray
.binarySearch(expectedCheckpoint
);
62 ITmfCheckpoint found
= fFlatArray
.get(rank
);
64 assertEquals(expectedRank
, rank
);
65 assertEquals(found
, expectedCheckpoint
);
69 * Test many checkpoint insertions. Make sure they can be found after
73 public void testInsertAlotCheckEquals() {
74 ArrayList
<Integer
> list
= insertAlot();
76 fFlatArray
= createCollection();
78 for (int i
= 0; i
< CHECKPOINTS_INSERT_NUM
; i
++) {
79 Integer checkpointIndex
= list
.get(i
);
80 TmfCheckpoint checkpoint
= new TmfCheckpoint(new TmfTimestamp(12345 + checkpointIndex
), new TmfLongLocation(123456L + checkpointIndex
), checkpointIndex
);
81 ITmfCheckpoint found
= fFlatArray
.get(checkpointIndex
);
82 assertEquals(checkpoint
, found
);