Package org.apache.hadoop.hdfs.server.namenode

Source Code of org.apache.hadoop.hdfs.server.namenode.TestEmptyAbandonBlock

package org.apache.hadoop.hdfs.server.namenode;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.protocol.LocatedBlock;

import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Test;

public class TestEmptyAbandonBlock {

  private static MiniDFSCluster cluster;
  private static Configuration conf;

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    conf = new Configuration();
    cluster = new MiniDFSCluster(conf, 3, true, null);
  }

  @AfterClass
  public static void tearDownAfterClass() throws Exception {
    cluster.shutdown();
  }

  @Test
  public void testAbandon() throws Exception {
    NameNode nn = cluster.getNameNode();
    DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
    String fileName = "/testAbandon";
    fs.create(new Path(fileName));
    LocatedBlock lbk = nn.addBlock(fileName, fs.getClient().getClientName());
    INodeFileUnderConstruction cons = (INodeFileUnderConstruction) nn.namesystem.dir
        .getInode(fileName);
    cons.setTargets(null);
    nn.abandonBlock(lbk.getBlock(), fileName, fs.getClient().getClientName());
    assertEquals(0, nn.getBlockLocations(fileName, 0, Long.MAX_VALUE)
        .locatedBlockCount());
  }

}
TOP

Related Classes of org.apache.hadoop.hdfs.server.namenode.TestEmptyAbandonBlock

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.