Search in sources :

Example 1 with MLocation

use of org.apache.hadoop.hdfs.server.mover.Mover.MLocation in project hadoop by apache.

the class TestMover method testScheduleSameBlock.

@Test
public void testScheduleSameBlock() throws IOException {
    final Configuration conf = new HdfsConfiguration();
    final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
    try {
        cluster.waitActive();
        final DistributedFileSystem dfs = cluster.getFileSystem();
        final String file = "/testScheduleSameBlock/file";
        {
            final FSDataOutputStream out = dfs.create(new Path(file));
            out.writeChars("testScheduleSameBlock");
            out.close();
        }
        final Mover mover = newMover(conf);
        mover.init();
        final Mover.Processor processor = mover.new Processor();
        final LocatedBlock lb = dfs.getClient().getLocatedBlocks(file, 0).get(0);
        final List<MLocation> locations = MLocation.toLocations(lb);
        final MLocation ml = locations.get(0);
        final DBlock db = mover.newDBlock(lb, locations, null);
        final List<StorageType> storageTypes = new ArrayList<StorageType>(Arrays.asList(StorageType.DEFAULT, StorageType.DEFAULT));
        Assert.assertTrue(processor.scheduleMoveReplica(db, ml, storageTypes));
        Assert.assertFalse(processor.scheduleMoveReplica(db, ml, storageTypes));
    } finally {
        cluster.shutdown();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) StorageType(org.apache.hadoop.fs.StorageType) Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) ArrayList(java.util.ArrayList) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) DBlock(org.apache.hadoop.hdfs.server.balancer.Dispatcher.DBlock) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) MLocation(org.apache.hadoop.hdfs.server.mover.Mover.MLocation) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 StorageType (org.apache.hadoop.fs.StorageType)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)1 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)1 LocatedBlock (org.apache.hadoop.hdfs.protocol.LocatedBlock)1 DBlock (org.apache.hadoop.hdfs.server.balancer.Dispatcher.DBlock)1 MLocation (org.apache.hadoop.hdfs.server.mover.Mover.MLocation)1 Test (org.junit.Test)1