Skip to content

Commit c9763a9

Browse files
authored
HDFS-16227. De-flake TestMover#testMoverWithStripedFile (#3429)
1 parent cd5c639 commit c9763a9

1 file changed

Lines changed: 43 additions & 6 deletions

File tree

  • hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/mover

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/mover/TestMover.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.util.List;
5353
import java.util.Map;
5454
import java.util.Properties;
55+
import java.util.concurrent.TimeoutException;
5556
import java.util.concurrent.atomic.AtomicInteger;
5657

5758
import org.apache.hadoop.conf.Configuration;
@@ -958,13 +959,12 @@ public void testMoverWithStripedFile() throws Exception {
958959
new String[] { "-p", barDir });
959960
Assert.assertEquals("Movement to ARCHIVE should be successful", 0, rc);
960961

961-
// verify storage types and locations
962+
// Verify storage types and locations.
963+
// Wait until Namenode confirms ARCHIVE storage type for all blocks of
964+
// fooFile.
965+
waitForUpdatedStorageType(client, fooFile, fileLen, StorageType.ARCHIVE);
966+
962967
locatedBlocks = client.getBlockLocations(fooFile, 0, fileLen);
963-
for(LocatedBlock lb : locatedBlocks.getLocatedBlocks()){
964-
for( StorageType type : lb.getStorageTypes()){
965-
Assert.assertEquals(StorageType.ARCHIVE, type);
966-
}
967-
}
968968
StripedFileTestUtil.verifyLocatedStripedBlocks(locatedBlocks,
969969
dataBlocks + parityBlocks);
970970

@@ -1005,6 +1005,43 @@ public void testMoverWithStripedFile() throws Exception {
10051005
}
10061006
}
10071007

1008+
/**
1009+
* Wait until Namenode reports expected storage type for all blocks of
1010+
* given file.
1011+
*
1012+
* @param client handle all RPC calls to Namenode.
1013+
* @param file file for which we are expecting same storage type of all
1014+
* located blocks.
1015+
* @param fileLen length of the file.
1016+
* @param expectedStorageType storage type to expect for all blocks of the
1017+
* given file.
1018+
* @throws TimeoutException if the wait timed out.
1019+
* @throws InterruptedException if interrupted while waiting for the response.
1020+
*/
1021+
private void waitForUpdatedStorageType(ClientProtocol client, String file,
1022+
long fileLen, StorageType expectedStorageType)
1023+
throws TimeoutException, InterruptedException {
1024+
GenericTestUtils.waitFor(() -> {
1025+
LocatedBlocks blocks;
1026+
try {
1027+
blocks = client.getBlockLocations(file, 0, fileLen);
1028+
} catch (IOException e) {
1029+
throw new RuntimeException(e);
1030+
}
1031+
for (LocatedBlock lb : blocks.getLocatedBlocks()) {
1032+
for (StorageType type : lb.getStorageTypes()) {
1033+
if (!expectedStorageType.equals(type)) {
1034+
LOG.info("Block {} has StorageType: {}. It might not have been "
1035+
+ "updated yet, awaiting the latest update.",
1036+
lb.getBlock().toString(), type);
1037+
return false;
1038+
}
1039+
}
1040+
}
1041+
return true;
1042+
}, 500, 5000, "Blocks storage type must be ARCHIVE");
1043+
}
1044+
10081045
private void initSecureConf(Configuration conf) throws Exception {
10091046
String username = "mover";
10101047
File baseDir = GenericTestUtils.getTestDir(TestMover.class.getSimpleName());

0 commit comments

Comments
 (0)