From 867f0f141cc935c1f67680533cc22f25b804f720 Mon Sep 17 00:00:00 2001 From: Jing Zhao Date: Mon, 8 Sep 2014 14:57:27 -0700 Subject: [PATCH] HDFS-7029. Archival Storage: fix TestDFSInotifyEventInputStream and TestDistributedFileSystem. Contributed by Tsz Wo Nicholas Sze. --- .../apache/hadoop/hdfs/BlockStoragePolicy.java | 15 +++++++++++++++ .../hdfs/TestDFSInotifyEventInputStream.java | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/BlockStoragePolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/BlockStoragePolicy.java index a72d4f1eeb..efbf8a00d6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/BlockStoragePolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/BlockStoragePolicy.java @@ -55,6 +55,17 @@ public class BlockStoragePolicy { public static final int ID_MAX = (1 << ID_BIT_LENGTH) - 1; public static final byte ID_UNSPECIFIED = 0; + private static final Suite DEFAULT_SUITE = createDefaultSuite(); + + private static Suite createDefaultSuite() { + final BlockStoragePolicy[] policies = new BlockStoragePolicy[1 << ID_BIT_LENGTH]; + final StorageType[] storageTypes = {StorageType.DISK}; + final byte defaultPolicyId = 12; + policies[defaultPolicyId] = new BlockStoragePolicy(defaultPolicyId, "HOT", + storageTypes, StorageType.EMPTY_ARRAY, StorageType.EMPTY_ARRAY); + return new Suite(defaultPolicyId, policies); + } + /** A block storage policy suite. */ public static class Suite { private final byte defaultPolicyID; @@ -342,6 +353,10 @@ private static BlockStoragePolicy readBlockStoragePolicy(byte id, String name, public static Suite readBlockStorageSuite(Configuration conf) { final BlockStoragePolicy[] policies = new BlockStoragePolicy[1 << ID_BIT_LENGTH]; final String[] values = conf.getStrings(DFS_BLOCK_STORAGE_POLICIES_KEY); + if (values == null) { + // conf property is missing, use default suite. + return DEFAULT_SUITE; + } byte firstID = -1; for(String v : values) { v = v.trim(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSInotifyEventInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSInotifyEventInputStream.java index 45b588b93a..a608ba8360 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSInotifyEventInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSInotifyEventInputStream.java @@ -64,7 +64,7 @@ private static Event waitForNextEvent(DFSInotifyEventInputStream eis) */ @Test public void testOpcodeCount() { - Assert.assertTrue(FSEditLogOpCodes.values().length == 46); + Assert.assertTrue(FSEditLogOpCodes.values().length == 47); }