source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/hdfs/TestSetrepIncreasing.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: 2.8 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.hdfs;
19
20import junit.framework.TestCase;
21import java.io.*;
22
23import org.apache.hadoop.conf.Configuration;
24import org.apache.hadoop.fs.*;
25import org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset;
26
27public class TestSetrepIncreasing extends TestCase {
28  static void setrep(int fromREP, int toREP, boolean simulatedStorage) throws IOException {
29    Configuration conf = new Configuration();
30    if (simulatedStorage) {
31      conf.setBoolean(SimulatedFSDataset.CONFIG_PROPERTY_SIMULATED, true);
32    }
33    conf.set("dfs.replication", "" + fromREP);
34    conf.setLong("dfs.blockreport.intervalMsec", 1000L);
35    conf.set("dfs.replication.pending.timeout.sec", Integer.toString(2));
36    MiniDFSCluster cluster = new MiniDFSCluster(conf, 10, true, null);
37    FileSystem fs = cluster.getFileSystem();
38    assertTrue("Not a HDFS: "+fs.getUri(), fs instanceof DistributedFileSystem);
39
40    try {
41      Path root = TestDFSShell.mkdir(fs, 
42          new Path("/test/setrep" + fromREP + "-" + toREP));
43      Path f = TestDFSShell.writeFile(fs, new Path(root, "foo"));
44     
45      // Verify setrep for changing replication
46      {
47        String[] args = {"-setrep", "-w", "" + toREP, "" + f};
48        FsShell shell = new FsShell();
49        shell.setConf(conf);
50        try {
51          assertEquals(0, shell.run(args));
52        } catch (Exception e) {
53          assertTrue("-setrep " + e, false);
54        }
55      }
56
57      //get fs again since the old one may be closed
58      fs = cluster.getFileSystem();
59      FileStatus file = fs.getFileStatus(f);
60      long len = file.getLen();
61      for(BlockLocation locations : fs.getFileBlockLocations(file, 0, len)) {
62        assertTrue(locations.getHosts().length == toREP);
63      }
64      TestDFSShell.show("done setrep waiting: " + root);
65    } finally {
66      try {fs.close();} catch (Exception e) {}
67      cluster.shutdown();
68    }
69  }
70
71  public void testSetrepIncreasing() throws IOException {
72    setrep(3, 7, false);
73  }
74  public void testSetrepIncreasingSimulatedStorage() throws IOException {
75    setrep(3, 7, true);
76  }
77}
Note: See TracBrowser for help on using the repository browser.