1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
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
.tmf
.ctf
.core
.tests
.temp
.tracemanager
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertFalse
;
14 import static org
.junit
.Assert
.assertNotNull
;
15 import static org
.junit
.Assert
.assertTrue
;
16 import static org
.junit
.Assert
.fail
;
19 import java
.io
.IOException
;
20 import java
.nio
.file
.DirectoryStream
;
21 import java
.nio
.file
.Files
;
22 import java
.nio
.file
.Path
;
23 import java
.nio
.file
.Paths
;
25 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
28 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
29 import org
.junit
.AfterClass
;
30 import org
.junit
.Before
;
31 import org
.junit
.Test
;
34 * Tests for the utility methods in {@link TmfTraceManager}.
36 * @author Alexandre Montplaisir
38 public class TmfTraceManagerUtilityTest
{
40 private ITmfTrace fTrace
;
47 fTrace
= CtfTmfTestTraceUtils
.getTrace(CtfTestTrace
.TRACE2
);
48 fTrace
.indexTrace(true);
55 public static void teardown() {
56 CtfTmfTestTraceUtils
.dispose(CtfTestTrace
.TRACE2
);
60 * Test the {@link TmfTraceManager#getSupplementaryFileDir} method.
63 public void testSupplementaryFileDir() {
64 final ITmfTrace trace
= fTrace
;
66 String name1
= trace
.getName();
67 String basePath
= TmfTraceManager
.getTemporaryDirPath() + File
.separator
;
69 String expected
= basePath
+ name1
+ File
.separator
;
70 assertEquals(expected
, TmfTraceManager
.getSupplementaryFileDir(trace
));
74 * Test the {@link TmfTraceManager#deleteSupplementaryFiles} method.
77 public void testDeleteSupplementaryFiles() {
78 ITmfTrace trace
= fTrace
;
81 String suppFilesPath
= TmfTraceManager
.getSupplementaryFileDir(trace
);
84 * Initializing/indexing the trace should have produced some
85 * supplementary files already.
87 assertFalse(isDirectoryEmpty(suppFilesPath
));
89 TmfTraceManager
.deleteSupplementaryFiles(trace
);
90 assertTrue(isDirectoryEmpty(suppFilesPath
));
92 } catch (IOException e
) {
97 private static boolean isDirectoryEmpty(String dirPath
) throws IOException
{
98 Path path
= Paths
.get(dirPath
);
99 try (DirectoryStream
<Path
> stream
= Files
.newDirectoryStream(path
)) {
100 return !stream
.iterator().hasNext();