segStore: Add unit test for history tree segment store
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.segmentstore.core.tests / stubs / org / eclipse / tracecompass / segmentstore / core / tests / historytree / SegmentHistoryTreeStub.java
1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
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
10 package org.eclipse.tracecompass.segmentstore.core.tests.historytree;
11
12 import java.io.File;
13 import java.io.IOException;
14
15 import org.eclipse.tracecompass.internal.provisional.datastore.core.historytree.IHistoryTree;
16 import org.eclipse.tracecompass.internal.provisional.datastore.core.interval.IHTIntervalReader;
17 import org.eclipse.tracecompass.internal.provisional.segmentstore.core.ISegment2;
18 import org.eclipse.tracecompass.internal.segmentstore.core.segmentHistoryTree.SegmentHistoryTree;
19 import org.eclipse.tracecompass.internal.segmentstore.core.segmentHistoryTree.SegmentTreeNode;
20
21 /**
22 * A stub segment history tree that extends the base segment history tree and
23 * the stub nodes
24 *
25 * @author Geneviève Bastien
26 * @param <E>
27 * The type of segments that goes in this tree
28 */
29 public class SegmentHistoryTreeStub<E extends ISegment2> extends SegmentHistoryTree<E> {
30
31 private int fLastInsertionIndex;
32
33 /**
34 * Minimum size a block of this tree should have
35 */
36 public static final int MINIMUM_BLOCK_SIZE = IHistoryTree.TREE_HEADER_SIZE;
37
38 /**
39 * Constructor
40 *
41 * @param stateHistoryFile
42 * The name of the history file
43 * @param blockSize
44 * The size of each "block" on disk in bytes. One node will
45 * always fit in one block. It should be at least 4096.
46 * @param maxChildren
47 * The maximum number of children allowed per core (non-leaf)
48 * node.
49 * @param providerVersion
50 * The version of the state provider. If a file already exists,
51 * and their versions match, the history file will not be rebuilt
52 * uselessly.
53 * @param treeStart
54 * The start time of the history
55 * @param intervalReader
56 * typed ISegment to allow access to the readSegment methods
57 * @throws IOException
58 * If an error happens trying to open/write to the file
59 * specified in the config
60 */
61 public SegmentHistoryTreeStub(File stateHistoryFile,
62 int blockSize,
63 int maxChildren,
64 int providerVersion,
65 long treeStart,
66 IHTIntervalReader<E> intervalReader) throws IOException {
67
68 super(stateHistoryFile,
69 blockSize,
70 maxChildren,
71 providerVersion,
72 treeStart,
73 intervalReader);
74 }
75
76 /**
77 * "Reader" constructor : instantiate a SHTree from an existing tree file on
78 * disk
79 *
80 * @param existingStateFile
81 * Path/filename of the history-file we are to open
82 * @param expProviderVersion
83 * The expected version of the state provider
84 * @param factory
85 * typed ISegment to allow access to the readSegment methods
86 * @throws IOException
87 * If an error happens reading the file
88 */
89 public SegmentHistoryTreeStub(File existingStateFile, int expProviderVersion, IHTIntervalReader<E> factory) throws IOException {
90 super(existingStateFile, expProviderVersion, factory);
91 }
92
93 @Override
94 protected void informInsertingAtDepth(int depth) {
95 fLastInsertionIndex = depth;
96 }
97
98 /**
99 * Get the index in the current branch where the last element was inserted
100 *
101 * @return The index in the branch of the last insertion
102 */
103 public int getLastInsertionLocation() {
104 return fLastInsertionIndex;
105 }
106
107 @Override
108 public SegmentTreeNode<E> getLatestLeaf() {
109 return super.getLatestLeaf();
110 }
111 }
This page took 0.052559 seconds and 6 git commands to generate.