source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/mapred/TestMapredSystemDir.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 4.0 KB
Line 
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 */
18package org.apache.hadoop.mapred;
19
20import junit.framework.TestCase;
21
22import org.apache.commons.logging.Log;
23import org.apache.commons.logging.LogFactory;
24import org.apache.hadoop.conf.Configuration;
25import org.apache.hadoop.fs.permission.FsPermission;
26import org.apache.hadoop.hdfs.MiniDFSCluster;
27import org.apache.hadoop.fs.FileSystem;
28import org.apache.hadoop.fs.Path;
29import org.apache.hadoop.security.*;
30
31/**
32 * Test if JobTracker is resilient to garbage in mapred.system.dir.
33 */
34public class TestMapredSystemDir extends TestCase {
35  private static final Log LOG = LogFactory.getLog(TestMapredSystemDir.class);
36 
37  // dfs ugi
38  private static final UnixUserGroupInformation DFS_UGI = 
39    TestMiniMRWithDFSWithDistinctUsers.createUGI("dfs", true);
40  // mapred ugi
41  private static final UnixUserGroupInformation MR_UGI = 
42    TestMiniMRWithDFSWithDistinctUsers.createUGI("mr", false);
43  private static final FsPermission SYSTEM_DIR_PERMISSION =
44    FsPermission.createImmutable((short) 0733); // rwx-wx-wx
45 
46  public void testGarbledMapredSystemDir() throws Exception {
47    MiniDFSCluster dfs = null;
48    MiniMRCluster mr = null;
49    try {
50      // start dfs
51      Configuration conf = new Configuration();
52      conf.set("dfs.permissions.supergroup", "supergroup");
53      UnixUserGroupInformation.saveToConf(conf,
54          UnixUserGroupInformation.UGI_PROPERTY_NAME, DFS_UGI);
55      dfs = new MiniDFSCluster(conf, 1, true, null);
56      FileSystem fs = dfs.getFileSystem();
57     
58      // create mapred.system.dir
59      Path mapredSysDir = new Path("/mapred");
60      fs.mkdirs(mapredSysDir);
61      fs.setPermission(mapredSysDir, new FsPermission(SYSTEM_DIR_PERMISSION));
62      fs.setOwner(mapredSysDir, "mr", "mrgroup");
63
64      // start mr (i.e jobtracker)
65      Configuration mrConf = new Configuration();
66      UnixUserGroupInformation.saveToConf(mrConf,
67          UnixUserGroupInformation.UGI_PROPERTY_NAME, MR_UGI);
68      mr = new MiniMRCluster(0, 0, 0, dfs.getFileSystem().getUri().toString(),
69                             1, null, null, MR_UGI, new JobConf(mrConf));
70      JobTracker jobtracker = mr.getJobTrackerRunner().getJobTracker();
71     
72      // add garbage to mapred.system.dir
73      Path garbage = new Path(jobtracker.getSystemDir(), "garbage");
74      fs.mkdirs(garbage);
75      fs.setPermission(garbage, new FsPermission(SYSTEM_DIR_PERMISSION));
76      fs.setOwner(garbage, "test", "test-group");
77     
78      // stop the jobtracker
79      mr.stopJobTracker();
80      mr.getJobTrackerConf().setBoolean("mapred.jobtracker.restart.recover", 
81                                        false);
82      // start jobtracker but dont wait for it to be up
83      mr.startJobTracker(false);
84
85      // check 5 times .. each time wait for 2 secs to check if the jobtracker
86      // has crashed or not.
87      for (int i = 0; i < 5; ++i) {
88        LOG.info("Check #" + i);
89        if (!mr.getJobTrackerRunner().isActive()) {
90          return;
91        }
92        UtilsForTests.waitFor(2000);
93      }
94
95      assertFalse("JobTracker did not bail out (waited for 10 secs)", 
96                  mr.getJobTrackerRunner().isActive());
97    } finally {
98      if (dfs != null) { dfs.shutdown(); }
99      if (mr != null) { mr.shutdown();}
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.