HDFS-10260. TestFsDatasetImpl#testCleanShutdownOfVolume often fails. Contributed by Rushabh Shah.

(cherry picked from commit af9b000535)
This commit is contained in:
Kihwal Lee 2016-04-29 09:59:58 -05:00
parent ff233dfca0
commit 0b9057e1d3
1 changed files with 9 additions and 6 deletions

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.hdfs.server.datanode.fsdataset.impl; package org.apache.hadoop.hdfs.server.datanode.fsdataset.impl;
import com.google.common.base.Supplier;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
@ -653,8 +654,8 @@ public class TestFsDatasetImpl {
out.hflush(); out.hflush();
ExtendedBlock block = DFSTestUtil.getFirstBlock(fs, filePath); ExtendedBlock block = DFSTestUtil.getFirstBlock(fs, filePath);
FsVolumeImpl volume = (FsVolumeImpl) dataNode.getFSDataset().getVolume( final FsVolumeImpl volume = (FsVolumeImpl) dataNode.getFSDataset().
block); getVolume(block);
File finalizedDir = volume.getFinalizedDir(cluster.getNamesystem() File finalizedDir = volume.getFinalizedDir(cluster.getNamesystem()
.getBlockPoolId()); .getBlockPoolId());
@ -669,9 +670,11 @@ public class TestFsDatasetImpl {
// Invoke the synchronous checkDiskError method // Invoke the synchronous checkDiskError method
dataNode.getFSDataset().checkDataDir(); dataNode.getFSDataset().checkDataDir();
// Sleep for 1 second so that datanode can interrupt and cluster clean up // Sleep for 1 second so that datanode can interrupt and cluster clean up
Thread.sleep(1000); GenericTestUtils.waitFor(new Supplier<Boolean>() {
assertEquals("There are active threads still referencing volume: " @Override public Boolean get() {
+ volume.getBasePath(), 0, volume.getReferenceCount()); return volume.getReferenceCount() == 0;
}
}, 100, 10);
LocatedBlock lb = DFSTestUtil.getAllBlocks(fs, filePath).get(0); LocatedBlock lb = DFSTestUtil.getAllBlocks(fs, filePath).get(0);
DatanodeInfo info = lb.getLocations()[0]; DatanodeInfo info = lb.getLocations()[0];
@ -680,7 +683,7 @@ public class TestFsDatasetImpl {
Assert.fail("This is not a valid code path. " Assert.fail("This is not a valid code path. "
+ "out.close should have thrown an exception."); + "out.close should have thrown an exception.");
} catch (IOException ioe) { } catch (IOException ioe) {
Assert.assertTrue(ioe.getMessage().contains(info.toString())); GenericTestUtils.assertExceptionContains(info.toString(), ioe);
} }
finalizedDir.setWritable(true); finalizedDir.setWritable(true);
finalizedDir.setExecutable(true); finalizedDir.setExecutable(true);