1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.statesystem
.core
.tests
.backend
.historytree
;
12 import static org
.junit
.Assert
.fail
;
15 import java
.io
.IOException
;
16 import java
.util
.Arrays
;
18 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
19 import org
.eclipse
.tracecompass
.internal
.statesystem
.core
.backend
.historytree
.HTInterval
;
20 import org
.eclipse
.tracecompass
.internal
.statesystem
.core
.backend
.historytree
.HTNode
;
21 import org
.eclipse
.tracecompass
.internal
.statesystem
.core
.backend
.historytree
.HistoryTreeBackend
;
22 import org
.eclipse
.tracecompass
.internal
.statesystem
.core
.backend
.historytree
.IHistoryTree
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.tests
.stubs
.backend
.HistoryTreeBackendStub
;
25 import org
.eclipse
.tracecompass
.statesystem
.core
.tests
.stubs
.backend
.HistoryTreeBackendStub
.HistoryTreeType
;
26 import org
.junit
.Test
;
27 import org
.junit
.runner
.RunWith
;
28 import org
.junit
.runners
.Parameterized
;
29 import org
.junit
.runners
.Parameterized
.Parameters
;
32 * Test the {@link HistoryTreeBackend}-specific behavior and its interactions
33 * with the {@link IHistoryTree} classes.
35 * @author Geneviève Bastien
37 @RunWith(Parameterized
.class)
38 public class HistoryTreeWithBackendTest
{
40 /** State system ID */
41 private static final String SSID
= "test";
42 /** Provider version */
43 private static final int PROVIDER_VERSION
= 0;
45 /** Default maximum number of children nodes */
46 private static final int MAX_CHILDREN
= 3;
47 /** Default block size */
48 private static final int BLOCK_SIZE
= 4096;
50 private final HistoryTreeType fHtType
;
53 * @return The arrays of parameters
55 @Parameters(name
= "{0}")
56 public static Iterable
<Object
[]> getParameters() {
57 return Arrays
.asList(new Object
[][] {
58 { HistoryTreeType
.CLASSIC
}
66 * The type of history tree to use
68 public HistoryTreeWithBackendTest(HistoryTreeType htType
) {
73 * Test the behavior of the history tree after at least a depth of 3
76 public void testFillNodes() {
78 // Test case parameters
80 final int depthToRead
= 3;
83 File historyTreeFile
= NonNullUtils
.checkNotNull(File
.createTempFile("HistoryTreeBackendTest", ".ht"));
84 HistoryTreeBackendStub
.setTreeType(fHtType
);
85 HistoryTreeBackendStub backend
= new HistoryTreeBackendStub(SSID
, historyTreeFile
, PROVIDER_VERSION
, startTime
, BLOCK_SIZE
, MAX_CHILDREN
);
87 int duration
= nbAttr
;
88 int quarkTest
= nbAttr
;
89 long time
= startTime
+ duration
;
91 HTInterval interval
= new HTInterval(startTime
, time
, quarkTest
, TmfStateValue
.newValueLong(time
));
92 // Insert a first interval for the test attribute
93 backend
.insertPastState(interval
.getStartTime(), interval
.getEndTime(), interval
.getAttribute(), interval
.getStateValue());
96 * insert cascading intervals to fill 2 levels of history tree, so
97 * that we start another branch
99 while (backend
.getHistoryTree().getDepth() < depthToRead
) {
100 backend
.insertPastState(
101 Math
.max(startTime
, time
- duration
),
104 TmfStateValue
.newValueLong(time
));
108 // entirely fill the latest leaf with cascading intervals
109 HTNode latestLeaf
= backend
.getHistoryTree().getLatestLeaf();
111 * Add an interval while there is still room for it or make sure the
112 * node does not get written on disk in the meantime.
114 while (interval
.getSizeOnDisk() <= latestLeaf
.getNodeFreeSpace() || latestLeaf
.isOnDisk()) {
115 backend
.insertPastState(
116 Math
.max(startTime
, time
- duration
),
119 TmfStateValue
.newValueLong(time
));
123 // Add an interval that does not fit in latest leaf, but starts
124 // before the current branch
125 backend
.insertPastState(interval
.getEndTime() + 1, time
, quarkTest
, TmfStateValue
.newValueLong(time
));
127 backend
.getHistoryTree().assertIntegrity();
129 } catch (IOException e
) {
130 fail(e
.getMessage());