]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | * Permission is hereby granted, free of charge, to any person obtaining a | |
3 | * copy of this software and associated documentation files (the "Software"), | |
4 | * to deal in the Software without restriction, including without limitation | |
5 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
6 | * and/or sell copies of the Software, and to permit persons to whom the | |
7 | * Software is furnished to do so, subject to the following conditions: | |
8 | * | |
9 | * The above copyright notice and this permission notice shall be included in | |
10 | * all copies or substantial portions of the Software. | |
11 | * | |
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
18 | * DEALINGS IN THE SOFTWARE. | |
19 | */ | |
20 | package com.ceph.fs; | |
21 | ||
22 | import java.io.FileNotFoundException; | |
23 | import org.junit.*; | |
24 | import java.util.UUID; | |
25 | import static org.junit.Assert.*; | |
26 | ||
27 | /* | |
28 | * This tests the mount root dir functionality. It creates an empty | |
29 | * directory in the real root, then it re-mounts the file system | |
30 | * with the empty directory specified as the root. Assertions are | |
31 | * that the "/" in the normal mount is non-empty, and that "/" is | |
32 | * empty in the mount with the empty directory as the root. | |
33 | */ | |
34 | public class CephMountCreateTest { | |
35 | ||
36 | private static String conf_file; | |
37 | ||
38 | @BeforeClass | |
39 | public static void class_setup() throws Exception { | |
40 | conf_file = System.getProperty("CEPH_CONF_FILE"); | |
41 | } | |
42 | ||
43 | private CephMount setupMount(String root) throws Exception { | |
44 | CephMount mount = new CephMount("admin"); | |
45 | if (conf_file != null) | |
46 | mount.conf_read_file(conf_file); | |
47 | mount.conf_set("client_permissions", "0"); | |
48 | mount.mount(root); | |
49 | return mount; | |
50 | } | |
51 | ||
52 | @Test | |
53 | public void test_CephMountCreate() throws Exception { | |
54 | CephMount mount; | |
55 | boolean found; | |
56 | ||
57 | String dir = "libcephfs_junit_" + UUID.randomUUID(); | |
58 | ||
59 | /* root dir has more than one dir */ | |
60 | mount = setupMount("/"); | |
61 | ||
62 | try { | |
63 | mount.rmdir("/" + dir); | |
64 | } catch (FileNotFoundException e) {} | |
65 | mount.mkdirs("/" + dir, 777); | |
66 | String[] subdirs = mount.listdir("/"); | |
67 | found = false; | |
68 | for (String d : subdirs) { | |
69 | if (d.compareTo(dir) == 0) | |
70 | found = true; | |
71 | } | |
72 | assertTrue(found); | |
73 | mount.unmount(); | |
74 | ||
75 | /* changing root to empty dir */ | |
76 | mount = setupMount("/" + dir); | |
77 | ||
78 | subdirs = mount.listdir("/"); | |
79 | found = false; | |
80 | for (String d : subdirs) { | |
81 | found = true; | |
82 | } | |
83 | assertFalse(found); | |
84 | mount.unmount(); | |
85 | ||
86 | /* cleanup */ | |
87 | mount = setupMount("/"); | |
88 | mount.rmdir("/" + dir); | |
89 | mount.unmount(); | |
90 | } | |
91 | } |