1 | /** |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one |
---|
3 | * or more contributor license agreements. See the NOTICE file |
---|
4 | * distributed with this work for additional information |
---|
5 | * regarding copyright ownership. The ASF licenses this file |
---|
6 | * to you under the Apache License, Version 2.0 (the |
---|
7 | * "License"); you may not use this file except in compliance |
---|
8 | * with the License. You may obtain a copy of the License at |
---|
9 | * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
11 | * |
---|
12 | * Unless required by applicable law or agreed to in writing, software |
---|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
15 | * See the License for the specific language governing permissions and |
---|
16 | * limitations under the License. |
---|
17 | */ |
---|
18 | |
---|
19 | package org.apache.hadoop.hdfs; |
---|
20 | |
---|
21 | import junit.framework.TestCase; |
---|
22 | |
---|
23 | import org.apache.hadoop.conf.Configuration; |
---|
24 | import org.apache.hadoop.fs.FileStatus; |
---|
25 | import org.apache.hadoop.fs.FileSystem; |
---|
26 | import org.apache.hadoop.fs.Path; |
---|
27 | |
---|
28 | /** |
---|
29 | * A JUnit test for checking if restarting DFS preserves integrity. |
---|
30 | */ |
---|
31 | public class TestRestartDFS extends TestCase { |
---|
32 | /** check if DFS remains in proper condition after a restart */ |
---|
33 | public void testRestartDFS() throws Exception { |
---|
34 | final Configuration conf = new Configuration(); |
---|
35 | MiniDFSCluster cluster = null; |
---|
36 | DFSTestUtil files = new DFSTestUtil("TestRestartDFS", 20, 3, 8*1024); |
---|
37 | |
---|
38 | final String dir = "/srcdat"; |
---|
39 | final Path rootpath = new Path("/"); |
---|
40 | final Path dirpath = new Path(dir); |
---|
41 | |
---|
42 | long rootmtime; |
---|
43 | FileStatus rootstatus; |
---|
44 | FileStatus dirstatus; |
---|
45 | |
---|
46 | try { |
---|
47 | cluster = new MiniDFSCluster(conf, 4, true, null); |
---|
48 | FileSystem fs = cluster.getFileSystem(); |
---|
49 | files.createFiles(fs, dir); |
---|
50 | |
---|
51 | rootmtime = fs.getFileStatus(rootpath).getModificationTime(); |
---|
52 | rootstatus = fs.getFileStatus(dirpath); |
---|
53 | dirstatus = fs.getFileStatus(dirpath); |
---|
54 | |
---|
55 | fs.setOwner(rootpath, rootstatus.getOwner() + "_XXX", null); |
---|
56 | fs.setOwner(dirpath, null, dirstatus.getGroup() + "_XXX"); |
---|
57 | } finally { |
---|
58 | if (cluster != null) { cluster.shutdown(); } |
---|
59 | } |
---|
60 | try { |
---|
61 | // Here we restart the MiniDFScluster without formatting namenode |
---|
62 | cluster = new MiniDFSCluster(conf, 4, false, null); |
---|
63 | FileSystem fs = cluster.getFileSystem(); |
---|
64 | assertTrue("Filesystem corrupted after restart.", |
---|
65 | files.checkFiles(fs, dir)); |
---|
66 | |
---|
67 | final FileStatus newrootstatus = fs.getFileStatus(rootpath); |
---|
68 | assertEquals(rootmtime, newrootstatus.getModificationTime()); |
---|
69 | assertEquals(rootstatus.getOwner() + "_XXX", newrootstatus.getOwner()); |
---|
70 | assertEquals(rootstatus.getGroup(), newrootstatus.getGroup()); |
---|
71 | |
---|
72 | final FileStatus newdirstatus = fs.getFileStatus(dirpath); |
---|
73 | assertEquals(dirstatus.getOwner(), newdirstatus.getOwner()); |
---|
74 | assertEquals(dirstatus.getGroup() + "_XXX", newdirstatus.getGroup()); |
---|
75 | |
---|
76 | files.cleanup(fs, dir); |
---|
77 | } finally { |
---|
78 | if (cluster != null) { cluster.shutdown(); } |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|