[ 
https://issues.apache.org/jira/browse/HBASE-6175?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13291376#comment-13291376
 ] 

nkeywal commented on HBASE-6175:
--------------------------------

The hbase-free version of the test:
{noformat}
package org.apache.hadoop.test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.junit.Test;

import static junit.framework.Assert.assertEquals;

public class TestHDFS {

  @Test
  public void testFSUTils() throws Exception {
    final Configuration conf = new Configuration();
    final String hosts[] = {"host1", "host2", "host3", "host4"};
    final byte[] data = new byte[1]; // Will fit in one block
    final Path testFile = new Path("/test1.txt");

      MiniDFSCluster dfsCluster = new MiniDFSCluster(0, conf, hosts.length, 
true, true, true, null, null, hosts, null);
    try {
      FileSystem fs = dfsCluster.getFileSystem();
      dfsCluster.waitClusterUp();

      for (int i = 0; i < 200; ++i) {
        FSDataOutputStream out = fs.create(testFile);
        out.write(data, 0, 1);
        out.close();

        // Put a sleep here to make me work
        //Thread.sleep(1000);

        FileStatus status = fs.getFileStatus(testFile);
        int nbHosts = fs.getFileBlockLocations(status, 0, 
status.getLen())[0].getHosts().length;
        assertEquals(1, fs.getFileBlockLocations(status, 0, 
status.getLen()).length);
        assertEquals("Wrong number of hosts distributing blocks at iteration " 
+ i, 3, nbHosts);

        fs.delete(testFile, true);
      }

    } finally {
      dfsCluster.shutdown();
    }
  }
}
{noformat}

                
> TestFSUtils flaky on hdfs getFileStatus method
> ----------------------------------------------
>
>                 Key: HBASE-6175
>                 URL: https://issues.apache.org/jira/browse/HBASE-6175
>             Project: HBase
>          Issue Type: Bug
>          Components: test
>    Affects Versions: 0.96.0
>            Reporter: nkeywal
>            Assignee: nkeywal
>            Priority: Trivial
>             Fix For: 0.96.0
>
>
> This is a simplified version of a TestFSUtils issue: a sleep and the test 
> works 100% of the time. No sleep and it becomes flaky. Root cause unknown. 
> While the issue appears on the tests, the root cause could be an issue on 
> real production system as well.
> {noformat}
> @Test
>  public void testFSUTils() throws Exception {
>    final String hosts[] = {"host1", "host2", "host3", "host4"};
>    Path testFile = new Path("/test1.txt");
>    HBaseTestingUtility htu = new HBaseTestingUtility();
>    try {
>      htu.startMiniDFSCluster(hosts).waitActive();
>      FileSystem fs = htu.getDFSCluster().getFileSystem();
>      for (int i = 0; i < 100; ++i) {
>        FSDataOutputStream out = fs.create(testFile);
>        byte[] data = new byte[1];
>        out.write(data, 0, 1);
>        out.close();
>        // Put a sleep here to make me work
>        //Thread.sleep(2000);
>        FileStatus status = fs.getFileStatus(testFile);
>        HDFSBlocksDistribution blocksDistribution =
>          FSUtils.computeHDFSBlocksDistribution(fs, status, 0, 
> status.getLen());
>        assertEquals("Wrong number of hosts distributing blocks. at
> iteration "+i, 3,
>          blocksDistribution.getTopHosts().size());
>        fs.delete(testFile, true);
>      }
>    } finally {
>      htu.shutdownMiniDFSCluster();
>    }
>  }
> {noformat}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to