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
.tracecompass
.internal
.statesystem
.core
.backend
.historytree
.HistoryTreeBackend
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.backend
.IStateHistoryBackend
;
23 import org
.junit
.After
;
24 import org
.junit
.runner
.RunWith
;
25 import org
.junit
.runners
.Parameterized
;
26 import org
.junit
.runners
.Parameterized
.Parameters
;
29 * Test the {@link HistoryTreeBackend} class.
31 * @author Patrick Tasse
32 * @author Alexandre Montplaisir
34 @RunWith(Parameterized
.class)
35 public class HistoryTreeBackendTest
extends StateHistoryBackendTestBase
{
37 /** State system ID */
38 protected static final String SSID
= "test";
39 /** Provider version */
40 protected static final int PROVIDER_VERSION
= 0;
42 /** Default maximum number of children nodes */
43 protected static final int MAX_CHILDREN
= 2;
44 /** Default block size */
45 protected static final int BLOCK_SIZE
= 4096;
47 /** ReOpen test parameter */
48 protected final boolean fReOpen
;
50 /** Set of created history tree files */
51 protected Set
<File
> fHistoryTreeFiles
= new HashSet
<>();
52 /** Map of backends to history tree file */
53 protected Map
<IStateHistoryBackend
, File
> fBackendMap
= new HashMap
<>();
54 /** Maximum number of children nodes */
55 protected int fMaxChildren
= MAX_CHILDREN
;
57 protected int fBlockSize
= BLOCK_SIZE
;
60 * @return the test parameters
62 @Parameters(name
= "ReOpen={0}")
63 public static Collection
<Boolean
> parameters() {
64 return Arrays
.asList(Boolean
.FALSE
, Boolean
.TRUE
);
71 * True if the backend should be disposed and re-opened as a new
72 * backend from the file, or false to use the backend as-is
74 public HistoryTreeBackendTest(Boolean reOpen
) {
82 public void teardown() {
83 for (IStateHistoryBackend backend
: fBackendMap
.keySet()) {
86 for (File historyTreeFile
: fHistoryTreeFiles
) {
87 historyTreeFile
.delete();
92 protected IStateHistoryBackend
getBackendForBuilding(long startTime
) throws IOException
{
93 File historyTreeFile
= File
.createTempFile("HistoryTreeBackendTest", ".ht");
94 fHistoryTreeFiles
.add(historyTreeFile
);
95 HistoryTreeBackend backend
= new HistoryTreeBackend(SSID
, historyTreeFile
, PROVIDER_VERSION
, startTime
, fBlockSize
, fMaxChildren
);
96 fBackendMap
.put(backend
, historyTreeFile
);
101 protected IStateHistoryBackend
getBackendForQuerying(IStateHistoryBackend backend
) throws IOException
{
105 File historyTreeFile
= fBackendMap
.remove(backend
);
107 HistoryTreeBackend reOpenedBackend
= new HistoryTreeBackend(SSID
, historyTreeFile
, PROVIDER_VERSION
);
108 fBackendMap
.put(reOpenedBackend
, historyTreeFile
);
109 return reOpenedBackend
;