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
.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
.BTree
;
20 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.trace
.indexer
.BTreeCheckpointVisitor
;
21 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.trace
.indexer
.IBTreeVisitor
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.indexer
.ITmfPersistentlyIndexable
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.indexer
.checkpoint
.ITmfCheckpoint
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.indexer
.checkpoint
.TmfCheckpoint
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.TmfLongLocation
;
27 import org
.junit
.Test
;
30 * Tests for the BTree class
32 * @author Marc-Andre Laperle
34 public class BTreeTest
extends AbstractCheckpointCollectionTest
{
36 private final int DEGREE
= 15;
40 protected BTree
createCollection() {
41 fCheckpointCollection
= fBTree
= new BTree(DEGREE
, getFile(), (ITmfPersistentlyIndexable
) getTrace());
46 public boolean isPersistableCollection() {
51 * Tests that accepts find the correct checkpoint and ends with a perfect
55 public void testAccept() {
56 for (int i
= 0; i
< CHECKPOINTS_INSERT_NUM
; i
++) {
57 TmfCheckpoint checkpoint
= new TmfCheckpoint(new TmfTimestamp(i
), new TmfLongLocation(i
), 0);
58 fBTree
.insert(checkpoint
);
61 final TmfCheckpoint checkpoint
= new TmfCheckpoint(new TmfTimestamp(123), new TmfLongLocation(123L), 0);
63 class TestVisitor
implements IBTreeVisitor
{
64 public int fLastCompare
= 0;
65 ITmfCheckpoint fFoundCheckpoint
;
68 public int compare(ITmfCheckpoint checkRec
) {
69 fLastCompare
= checkRec
.compareTo(checkpoint
);
70 if (fLastCompare
== 0) {
71 fFoundCheckpoint
= checkRec
;
76 final TestVisitor t
= new TestVisitor();
80 assertEquals(checkpoint
, t
.fFoundCheckpoint
);
81 assertEquals(0, t
.fLastCompare
);
85 * Test many checkpoint insertions. Make sure they can be found after
89 public void testInsertAlotCheckEquals() {
90 ArrayList
<Integer
> list
= insertAlot();
92 fBTree
= createCollection();
94 for (int i
= 0; i
< CHECKPOINTS_INSERT_NUM
; i
++) {
95 Integer checkpointIndex
= list
.get(i
);
96 TmfCheckpoint checkpoint
= new TmfCheckpoint(new TmfTimestamp(12345 + checkpointIndex
), new TmfLongLocation(123456L + checkpointIndex
), 0);
97 BTreeCheckpointVisitor treeVisitor
= new BTreeCheckpointVisitor(checkpoint
);
98 fBTree
.accept(treeVisitor
);
99 assertEquals(checkpoint
, treeVisitor
.getCheckpoint());
108 public void testSetGetSize() {
109 assertEquals(0, fBTree
.size());
110 int expected
= CHECKPOINTS_INSERT_NUM
;
111 for (int i
= 0; i
< expected
; ++i
) {
112 fBTree
.insert(new TmfCheckpoint(new TmfTimestamp(0), new TmfLongLocation(0L), 0));
113 fBTree
.setSize(fBTree
.size() + 1);
115 assertEquals(expected
, fBTree
.size());