1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson, EfficiOS Inc. and others
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
;
13 import java
.io
.IOException
;
14 import java
.util
.Arrays
;
15 import java
.util
.Collection
;
16 import java
.util
.HashMap
;
17 import java
.util
.HashSet
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
22 import org
.eclipse
.tracecompass
.internal
.statesystem
.core
.backend
.historytree
.HistoryTreeBackend
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.backend
.IStateHistoryBackend
;
24 import org
.junit
.After
;
25 import org
.junit
.runner
.RunWith
;
26 import org
.junit
.runners
.Parameterized
;
27 import org
.junit
.runners
.Parameterized
.Parameters
;
30 * Test the {@link HistoryTreeBackend} class.
32 * @author Patrick Tasse
33 * @author Alexandre Montplaisir
35 @RunWith(Parameterized
.class)
36 public class HistoryTreeBackendTest
extends StateHistoryBackendTestBase
{
38 /** State system ID */
39 protected static final @NonNull String SSID
= "test";
40 /** Provider version */
41 protected static final int PROVIDER_VERSION
= 0;
43 /** Default maximum number of children nodes */
44 protected static final int MAX_CHILDREN
= 2;
45 /** Default block size */
46 protected static final int BLOCK_SIZE
= 4096;
48 /** ReOpen test parameter */
49 protected final boolean fReOpen
;
51 /** Set of created history tree files */
52 protected Set
<File
> fHistoryTreeFiles
= new HashSet
<>();
53 /** Map of backends to history tree file */
54 protected Map
<IStateHistoryBackend
, File
> fBackendMap
= new HashMap
<>();
55 /** Maximum number of children nodes */
56 protected int fMaxChildren
= MAX_CHILDREN
;
58 protected int fBlockSize
= BLOCK_SIZE
;
61 * @return the test parameters
63 @Parameters(name
= "ReOpen={0}")
64 public static Collection
<Boolean
> parameters() {
65 return Arrays
.asList(Boolean
.FALSE
, Boolean
.TRUE
);
72 * True if the backend should be disposed and re-opened as a new
73 * backend from the file, or false to use the backend as-is
75 public HistoryTreeBackendTest(Boolean reOpen
) {
83 public void teardown() {
84 for (IStateHistoryBackend backend
: fBackendMap
.keySet()) {
87 for (File historyTreeFile
: fHistoryTreeFiles
) {
88 historyTreeFile
.delete();
93 protected IStateHistoryBackend
getBackendForBuilding(long startTime
) throws IOException
{
94 File historyTreeFile
= File
.createTempFile("HistoryTreeBackendTest", ".ht");
95 fHistoryTreeFiles
.add(historyTreeFile
);
96 HistoryTreeBackend backend
= new HistoryTreeBackend(SSID
, historyTreeFile
, PROVIDER_VERSION
, startTime
, fBlockSize
, fMaxChildren
);
97 fBackendMap
.put(backend
, historyTreeFile
);
102 protected IStateHistoryBackend
getBackendForQuerying(IStateHistoryBackend backend
) throws IOException
{
106 File historyTreeFile
= fBackendMap
.remove(backend
);
108 HistoryTreeBackend reOpenedBackend
= new HistoryTreeBackend(SSID
, historyTreeFile
, PROVIDER_VERSION
);
109 fBackendMap
.put(reOpenedBackend
, historyTreeFile
);
110 return reOpenedBackend
;