source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/hdfs/server/namenode/TestUnderReplicatedBlocks.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: 1.7 KB
Line 
1package org.apache.hadoop.hdfs.server.namenode;
2
3import org.apache.hadoop.conf.Configuration;
4import org.apache.hadoop.fs.FileSystem;
5import org.apache.hadoop.fs.FsShell;
6import org.apache.hadoop.fs.Path;
7import org.apache.hadoop.hdfs.DFSTestUtil;
8import org.apache.hadoop.hdfs.MiniDFSCluster;
9import org.apache.hadoop.hdfs.protocol.Block;
10
11import junit.framework.TestCase;
12
13public class TestUnderReplicatedBlocks extends TestCase {
14  public void testSetrepIncWithUnderReplicatedBlocks() throws Exception {
15    Configuration conf = new Configuration();
16    final short REPLICATION_FACTOR = 2;
17    final String FILE_NAME = "/testFile";
18    final Path FILE_PATH = new Path(FILE_NAME);
19    MiniDFSCluster cluster = new MiniDFSCluster(conf, REPLICATION_FACTOR+1, true, null);
20    try {
21      // create a file with one block with a replication factor of 2
22      final FileSystem fs = cluster.getFileSystem();
23      DFSTestUtil.createFile(fs, FILE_PATH, 1L, REPLICATION_FACTOR, 1L);
24      DFSTestUtil.waitReplication(fs, FILE_PATH, REPLICATION_FACTOR);
25     
26      // remove one replica from the blocksMap so block becomes under-replicated
27      // but the block does not get put into the under-replicated blocks queue
28      FSNamesystem namesystem = cluster.getNameNode().namesystem;
29      Block b = DFSTestUtil.getFirstBlock(fs, FILE_PATH);
30      DatanodeDescriptor dn = namesystem.blocksMap.nodeIterator(b).next();
31      namesystem.addToInvalidates(b, dn);
32      namesystem.blocksMap.removeNode(b, dn);
33     
34      // increment this file's replication factor
35      FsShell shell = new FsShell(conf);
36      assertEquals(0, shell.run(new String[]{
37          "-setrep", "-w", Integer.toString(1+REPLICATION_FACTOR), FILE_NAME}));
38    } finally {
39      cluster.shutdown();
40    }
41   
42  }
43
44}
Note: See TracBrowser for help on using the repository browser.