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
;
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
33 @RunWith(Parameterized
.class)
34 public class HistoryTreeBackendTest
extends StateHistoryBackendTestBase
{
36 /** State system ID */
37 protected static final String SSID
= "test";
38 /** Provider version */
39 protected static final int PROVIDER_VERSION
= 0;
41 /** Default maximum number of children nodes */
42 protected static final int MAX_CHILDREN
= 2;
43 /** Default block size */
44 protected static final int BLOCK_SIZE
= 4096;
46 /** ReOpen test parameter */
47 protected final boolean fReOpen
;
49 /** Set of created history tree files */
50 protected Set
<File
> fHistoryTreeFiles
= new HashSet
<>();
51 /** Map of backends to history tree file */
52 protected Map
<IStateHistoryBackend
, File
> fBackendMap
= new HashMap
<>();
53 /** Maximum number of children nodes */
54 protected int fMaxChildren
= MAX_CHILDREN
;
56 protected int fBlockSize
= BLOCK_SIZE
;
59 * @return the test parameters
61 @Parameters(name
= "ReOpen={0}")
62 public static Collection
<Boolean
> parameters() {
63 return Arrays
.asList(Boolean
.FALSE
, Boolean
.TRUE
);
70 * True if the backend should be disposed and re-opened as a new
71 * backend from the file, or false to use the backend as-is
73 public HistoryTreeBackendTest(Boolean reOpen
) {
81 public void teardown() {
82 for (IStateHistoryBackend backend
: fBackendMap
.keySet()) {
85 for (File historyTreeFile
: fHistoryTreeFiles
) {
86 historyTreeFile
.delete();
91 protected IStateHistoryBackend
getBackendForBuilding(long startTime
) throws IOException
{
92 File historyTreeFile
= File
.createTempFile("HistoryTreeBackendTest", ".ht");
93 fHistoryTreeFiles
.add(historyTreeFile
);
94 HistoryTreeBackend backend
= new HistoryTreeBackend(SSID
, historyTreeFile
, PROVIDER_VERSION
, startTime
, fBlockSize
, fMaxChildren
);
95 fBackendMap
.put(backend
, historyTreeFile
);
100 protected IStateHistoryBackend
getBackendForQuerying(IStateHistoryBackend backend
) throws IOException
{
104 File historyTreeFile
= fBackendMap
.remove(backend
);
106 HistoryTreeBackend reOpenedBackend
= new HistoryTreeBackend(SSID
, historyTreeFile
, PROVIDER_VERSION
);
107 fBackendMap
.put(reOpenedBackend
, historyTreeFile
);
108 return reOpenedBackend
;