1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson 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
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
15 import java
.io
.IOException
;
16 import java
.util
.Arrays
;
17 import java
.util
.Collection
;
18 import java
.util
.HashMap
;
19 import java
.util
.HashSet
;
23 import org
.eclipse
.tracecompass
.internal
.statesystem
.core
.backend
.historytree
.HistoryTreeBackend
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.backend
.IStateHistoryBackend
;
25 import org
.junit
.After
;
26 import org
.junit
.runner
.RunWith
;
27 import org
.junit
.runners
.Parameterized
;
28 import org
.junit
.runners
.Parameterized
.Parameters
;
31 * Test the {@link HistoryTreeBackend} class.
33 * @author Patrick Tasse
35 @RunWith(Parameterized
.class)
36 public class HistoryTreeBackendTest
extends StateHistoryBackendTestBase
{
38 /** State system ID */
39 protected static final 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
= checkNotNull(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
{
107 File historyTreeFile
= fBackendMap
.remove(backend
);
109 if (historyTreeFile
== null) {
110 throw new IllegalStateException();
114 HistoryTreeBackend reOpenedBackend
= new HistoryTreeBackend(SSID
, historyTreeFile
, PROVIDER_VERSION
);
115 fBackendMap
.put(reOpenedBackend
, historyTreeFile
);
116 return reOpenedBackend
;