0d3b59eb3313fb6d16ea027674b1d709c088290a
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core.tests / src / org / eclipse / tracecompass / statesystem / core / tests / backend / HistoryTreeBackendTest.java
1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson and others
3 *
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 *******************************************************************************/
9
10 package org.eclipse.tracecompass.statesystem.core.tests.backend;
11
12 import java.io.File;
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;
18 import java.util.Map;
19 import java.util.Set;
20
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;
27
28 /**
29 * Test the {@link HistoryTreeBackend} class.
30 *
31 * @author Patrick Tasse
32 */
33 @RunWith(Parameterized.class)
34 public class HistoryTreeBackendTest extends StateHistoryBackendTestBase {
35
36 /** State system ID */
37 protected static final String SSID = "test";
38 /** Provider version */
39 protected static final int PROVIDER_VERSION = 0;
40
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;
45
46 /** ReOpen test parameter */
47 protected final boolean fReOpen;
48
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;
55 /** Block size */
56 protected int fBlockSize = BLOCK_SIZE;
57
58 /**
59 * @return the test parameters
60 */
61 @Parameters(name = "ReOpen={0}")
62 public static Collection<Boolean> parameters() {
63 return Arrays.asList(Boolean.FALSE, Boolean.TRUE);
64 }
65
66 /**
67 * Constructor
68 *
69 * @param reOpen
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
72 */
73 public HistoryTreeBackendTest(Boolean reOpen) {
74 fReOpen = reOpen;
75 }
76
77 /**
78 * Test cleanup
79 */
80 @After
81 public void teardown() {
82 for (IStateHistoryBackend backend : fBackendMap.keySet()) {
83 backend.dispose();
84 }
85 for (File historyTreeFile : fHistoryTreeFiles) {
86 historyTreeFile.delete();
87 }
88 }
89
90 @Override
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);
96 return backend;
97 }
98
99 @Override
100 protected IStateHistoryBackend getBackendForQuerying(IStateHistoryBackend backend) throws IOException {
101 if (!fReOpen) {
102 return backend;
103 }
104 File historyTreeFile = fBackendMap.remove(backend);
105 backend.dispose();
106 HistoryTreeBackend reOpenedBackend = new HistoryTreeBackend(SSID, historyTreeFile, PROVIDER_VERSION);
107 fBackendMap.put(reOpenedBackend, historyTreeFile);
108 return reOpenedBackend;
109 }
110 }
This page took 0.033659 seconds and 4 git commands to generate.