View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.rolling.helper;
15  
16  import ch.qos.logback.core.rolling.RolloverFailure;
17  import ch.qos.logback.core.testUtil.CoreTestConstants;
18  import ch.qos.logback.core.testUtil.RandomUtil;
19  import ch.qos.logback.core.util.EnvUtil;
20  import ch.qos.logback.core.util.FileUtil;
21  import org.junit.Ignore;
22  import org.junit.Test;
23  
24  import java.io.File;
25  import java.io.IOException;
26  
27  import static org.junit.Assert.assertFalse;
28  import static org.junit.Assert.assertTrue;
29  
30  public class FileStoreUtilTest {
31  
32      int diff = RandomUtil.getPositiveInt();
33      String pathPrefix = CoreTestConstants.OUTPUT_DIR_PREFIX + "fs" + diff + "/";
34  
35      @Test
36      public void filesOnSameFolderShouldBeOnTheSameFileStore() throws RolloverFailure, IOException {
37          if (!EnvUtil.isJDK7OrHigher())
38              return;
39  
40          File parent = new File(pathPrefix);
41          File file = new File(pathPrefix + "filesOnSameFolderShouldBeOnTheSameFileStore");
42          FileUtil.createMissingParentDirectories(file);
43          file.createNewFile();
44          assertTrue(FileStoreUtil.areOnSameFileStore(parent, file));
45      }
46  
47      // test should be run manually
48      @Ignore
49      @Test
50      public void manual_filesOnDifferentVolumesShouldBeDetectedAsSuch() throws RolloverFailure {
51          if (!EnvUtil.isJDK7OrHigher())
52              return;
53  
54          // author's computer has two volumes
55          File c = new File("c:/tmp/");
56          File d = new File("d:/");
57          assertFalse(FileStoreUtil.areOnSameFileStore(c, d));
58      }
59  }