Commit | Line | Data |
---|---|---|
60cabb56 | 1 | /******************************************************************************* |
b9d50127 | 2 | * Copyright (c) 2016 Ericsson and others |
60cabb56 PT |
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 | ||
6305377c JR |
12 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
13 | ||
60cabb56 PT |
14 | import java.io.File; |
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; | |
20 | import java.util.Map; | |
21 | import java.util.Set; | |
22 | ||
cf8efcef | 23 | import org.eclipse.tracecompass.internal.provisional.datastore.core.exceptions.RangeException; |
60cabb56 PT |
24 | import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HistoryTreeBackend; |
25 | import org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend; | |
26 | import org.junit.After; | |
cf8efcef | 27 | import org.junit.Test; |
60cabb56 PT |
28 | import org.junit.runner.RunWith; |
29 | import org.junit.runners.Parameterized; | |
30 | import org.junit.runners.Parameterized.Parameters; | |
31 | ||
32 | /** | |
33 | * Test the {@link HistoryTreeBackend} class. | |
34 | * | |
35 | * @author Patrick Tasse | |
60cabb56 PT |
36 | */ |
37 | @RunWith(Parameterized.class) | |
38 | public class HistoryTreeBackendTest extends StateHistoryBackendTestBase { | |
39 | ||
40 | /** State system ID */ | |
d844f14b | 41 | protected static final String SSID = "test"; |
60cabb56 PT |
42 | /** Provider version */ |
43 | protected static final int PROVIDER_VERSION = 0; | |
44 | ||
45 | /** Default maximum number of children nodes */ | |
46 | protected static final int MAX_CHILDREN = 2; | |
47 | /** Default block size */ | |
48 | protected static final int BLOCK_SIZE = 4096; | |
49 | ||
50 | /** ReOpen test parameter */ | |
51 | protected final boolean fReOpen; | |
52 | ||
53 | /** Set of created history tree files */ | |
54 | protected Set<File> fHistoryTreeFiles = new HashSet<>(); | |
55 | /** Map of backends to history tree file */ | |
56 | protected Map<IStateHistoryBackend, File> fBackendMap = new HashMap<>(); | |
57 | /** Maximum number of children nodes */ | |
58 | protected int fMaxChildren = MAX_CHILDREN; | |
59 | /** Block size */ | |
60 | protected int fBlockSize = BLOCK_SIZE; | |
61 | ||
62 | /** | |
63 | * @return the test parameters | |
64 | */ | |
65 | @Parameters(name = "ReOpen={0}") | |
66 | public static Collection<Boolean> parameters() { | |
67 | return Arrays.asList(Boolean.FALSE, Boolean.TRUE); | |
68 | } | |
69 | ||
70 | /** | |
71 | * Constructor | |
72 | * | |
73 | * @param reOpen | |
74 | * True if the backend should be disposed and re-opened as a new | |
75 | * backend from the file, or false to use the backend as-is | |
76 | */ | |
77 | public HistoryTreeBackendTest(Boolean reOpen) { | |
78 | fReOpen = reOpen; | |
79 | } | |
80 | ||
81 | /** | |
82 | * Test cleanup | |
83 | */ | |
84 | @After | |
85 | public void teardown() { | |
86 | for (IStateHistoryBackend backend : fBackendMap.keySet()) { | |
87 | backend.dispose(); | |
88 | } | |
89 | for (File historyTreeFile : fHistoryTreeFiles) { | |
90 | historyTreeFile.delete(); | |
91 | } | |
92 | } | |
93 | ||
94 | @Override | |
95 | protected IStateHistoryBackend getBackendForBuilding(long startTime) throws IOException { | |
6305377c | 96 | File historyTreeFile = checkNotNull(File.createTempFile("HistoryTreeBackendTest", ".ht")); |
60cabb56 PT |
97 | fHistoryTreeFiles.add(historyTreeFile); |
98 | HistoryTreeBackend backend = new HistoryTreeBackend(SSID, historyTreeFile, PROVIDER_VERSION, startTime, fBlockSize, fMaxChildren); | |
99 | fBackendMap.put(backend, historyTreeFile); | |
100 | return backend; | |
101 | } | |
102 | ||
103 | @Override | |
104 | protected IStateHistoryBackend getBackendForQuerying(IStateHistoryBackend backend) throws IOException { | |
105 | if (!fReOpen) { | |
106 | return backend; | |
107 | } | |
6305377c | 108 | |
60cabb56 | 109 | File historyTreeFile = fBackendMap.remove(backend); |
6305377c JR |
110 | |
111 | if (historyTreeFile == null) { | |
112 | throw new IllegalStateException(); | |
113 | } | |
114 | ||
60cabb56 PT |
115 | backend.dispose(); |
116 | HistoryTreeBackend reOpenedBackend = new HistoryTreeBackend(SSID, historyTreeFile, PROVIDER_VERSION); | |
117 | fBackendMap.put(reOpenedBackend, historyTreeFile); | |
118 | return reOpenedBackend; | |
119 | } | |
cf8efcef AM |
120 | |
121 | /** | |
122 | * This backend throws a different exception. | |
123 | */ | |
124 | @Override | |
125 | @Test(expected = RangeException.class) | |
126 | public void testIntervalBeforeStart() { | |
127 | super.testIntervalBeforeStart(); | |
128 | } | |
60cabb56 | 129 | } |