@@ -66,10 +66,12 @@ public class TestBlockStoragePolicy {
6666 static final long FILE_LEN = 1024 ;
6767 static final short REPLICATION = 3 ;
6868
69- static final byte COLD = (byte ) 4 ;
70- static final byte WARM = (byte ) 8 ;
71- static final byte HOT = (byte ) 12 ;
72- static final byte LAZY_PERSIST = (byte ) 15 ;
69+ static final byte COLD = HdfsConstants .COLD_STORAGE_POLICY_ID ;
70+ static final byte WARM = HdfsConstants .WARM_STORAGE_POLICY_ID ;
71+ static final byte HOT = HdfsConstants .HOT_STORAGE_POLICY_ID ;
72+ static final byte ONESSD = HdfsConstants .ONESSD_STORAGE_POLICY_ID ;
73+ static final byte ALLSSD = HdfsConstants .ALLSSD_STORAGE_POLICY_ID ;
74+ static final byte LAZY_PERSIST = HdfsConstants .MEMORY_STORAGE_POLICY_ID ;
7375
7476 @ Test (timeout =300000 )
7577 public void testConfigKeyEnabled () throws IOException {
@@ -79,7 +81,8 @@ public void testConfigKeyEnabled() throws IOException {
7981 .numDataNodes (1 ).build ();
8082 try {
8183 cluster .waitActive ();
82- cluster .getFileSystem ().setStoragePolicy (new Path ("/" ), "COLD" );
84+ cluster .getFileSystem ().setStoragePolicy (new Path ("/" ),
85+ HdfsConstants .COLD_STORAGE_POLICY_NAME );
8386 } finally {
8487 cluster .shutdown ();
8588 }
@@ -98,7 +101,8 @@ public void testConfigKeyDisabled() throws IOException {
98101 .numDataNodes (1 ).build ();
99102 try {
100103 cluster .waitActive ();
101- cluster .getFileSystem ().setStoragePolicy (new Path ("/" ), "COLD" );
104+ cluster .getFileSystem ().setStoragePolicy (new Path ("/" ),
105+ HdfsConstants .COLD_STORAGE_POLICY_NAME );
102106 } finally {
103107 cluster .shutdown ();
104108 }
@@ -108,17 +112,25 @@ public void testConfigKeyDisabled() throws IOException {
108112 public void testDefaultPolicies () {
109113 final Map <Byte , String > expectedPolicyStrings = new HashMap <Byte , String >();
110114 expectedPolicyStrings .put (COLD ,
111- "BlockStoragePolicy{COLD:4 , storageTypes=[ARCHIVE], " +
115+ "BlockStoragePolicy{COLD:" + COLD + " , storageTypes=[ARCHIVE], " +
112116 "creationFallbacks=[], replicationFallbacks=[]}" );
113117 expectedPolicyStrings .put (WARM ,
114- "BlockStoragePolicy{WARM:8, storageTypes=[DISK, ARCHIVE], " +
115- "creationFallbacks=[DISK, ARCHIVE], replicationFallbacks=[DISK, ARCHIVE]}" );
118+ "BlockStoragePolicy{WARM:" + WARM + ", storageTypes=[DISK, ARCHIVE], " +
119+ "creationFallbacks=[DISK, ARCHIVE], " +
120+ "replicationFallbacks=[DISK, ARCHIVE]}" );
116121 expectedPolicyStrings .put (HOT ,
117- "BlockStoragePolicy{HOT:12 , storageTypes=[DISK], " +
122+ "BlockStoragePolicy{HOT:" + HOT + " , storageTypes=[DISK], " +
118123 "creationFallbacks=[], replicationFallbacks=[ARCHIVE]}" );
119124 expectedPolicyStrings .put (LAZY_PERSIST ,
120- "BlockStoragePolicy{LAZY_PERSIST:15, storageTypes=[RAM_DISK, DISK], " +
125+ "BlockStoragePolicy{LAZY_PERSIST:" + LAZY_PERSIST +
126+ ", storageTypes=[RAM_DISK, DISK], " +
121127 "creationFallbacks=[DISK], replicationFallbacks=[DISK]}" );
128+ expectedPolicyStrings .put (ONESSD , "BlockStoragePolicy{ONE_SSD:" + ONESSD +
129+ ", storageTypes=[SSD, DISK], creationFallbacks=[SSD, DISK], " +
130+ "replicationFallbacks=[SSD, DISK]}" );
131+ expectedPolicyStrings .put (ALLSSD , "BlockStoragePolicy{ALL_SSD:" + ALLSSD +
132+ ", storageTypes=[SSD], creationFallbacks=[DISK], " +
133+ "replicationFallbacks=[DISK]}" );
122134
123135 for (byte i = 1 ; i < 16 ; i ++) {
124136 final BlockStoragePolicy policy = POLICY_SUITE .getPolicy (i );
@@ -845,15 +857,15 @@ public void testSetStoragePolicy() throws Exception {
845857
846858 final Path invalidPath = new Path ("/invalidPath" );
847859 try {
848- fs .setStoragePolicy (invalidPath , "WARM" );
860+ fs .setStoragePolicy (invalidPath , HdfsConstants . WARM_STORAGE_POLICY_NAME );
849861 Assert .fail ("Should throw a FileNotFoundException" );
850862 } catch (FileNotFoundException e ) {
851863 GenericTestUtils .assertExceptionContains (invalidPath .toString (), e );
852864 }
853865
854- fs .setStoragePolicy (fooFile , "COLD" );
855- fs .setStoragePolicy (barDir , "WARM" );
856- fs .setStoragePolicy (barFile2 , "HOT" );
866+ fs .setStoragePolicy (fooFile , HdfsConstants . COLD_STORAGE_POLICY_NAME );
867+ fs .setStoragePolicy (barDir , HdfsConstants . WARM_STORAGE_POLICY_NAME );
868+ fs .setStoragePolicy (barFile2 , HdfsConstants . HOT_STORAGE_POLICY_NAME );
857869
858870 dirList = fs .getClient ().listPaths (dir .toString (),
859871 HdfsFileStatus .EMPTY_NAME ).getPartialListing ();
@@ -901,7 +913,7 @@ public void testSetStoragePolicyWithSnapshot() throws Exception {
901913 DFSTestUtil .createFile (fs , fooFile1 , FILE_LEN , REPLICATION , 0L );
902914 DFSTestUtil .createFile (fs , fooFile2 , FILE_LEN , REPLICATION , 0L );
903915
904- fs .setStoragePolicy (fooDir , "WARM" );
916+ fs .setStoragePolicy (fooDir , HdfsConstants . WARM_STORAGE_POLICY_NAME );
905917
906918 HdfsFileStatus [] dirList = fs .getClient ().listPaths (dir .toString (),
907919 HdfsFileStatus .EMPTY_NAME , true ).getPartialListing ();
@@ -913,7 +925,7 @@ public void testSetStoragePolicyWithSnapshot() throws Exception {
913925 // take snapshot
914926 SnapshotTestHelper .createSnapshot (fs , dir , "s1" );
915927 // change the storage policy of fooFile1
916- fs .setStoragePolicy (fooFile1 , "COLD" );
928+ fs .setStoragePolicy (fooFile1 , HdfsConstants . COLD_STORAGE_POLICY_NAME );
917929
918930 fooList = fs .getClient ().listPaths (fooDir .toString (),
919931 HdfsFileStatus .EMPTY_NAME ).getPartialListing ();
@@ -936,7 +948,7 @@ public void testSetStoragePolicyWithSnapshot() throws Exception {
936948 HdfsFileStatus .EMPTY_NAME ).getPartialListing (), COLD );
937949
938950 // change the storage policy of foo dir
939- fs .setStoragePolicy (fooDir , "HOT" );
951+ fs .setStoragePolicy (fooDir , HdfsConstants . HOT_STORAGE_POLICY_NAME );
940952 // /dir/foo is now hot
941953 dirList = fs .getClient ().listPaths (dir .toString (),
942954 HdfsFileStatus .EMPTY_NAME , true ).getPartialListing ();
@@ -1053,7 +1065,7 @@ private void testChangeFileRep(String policyName, byte policyId,
10531065 */
10541066 @ Test
10551067 public void testChangeHotFileRep () throws Exception {
1056- testChangeFileRep ("HOT" , HOT ,
1068+ testChangeFileRep (HdfsConstants . HOT_STORAGE_POLICY_NAME , HOT ,
10571069 new StorageType []{StorageType .DISK , StorageType .DISK ,
10581070 StorageType .DISK },
10591071 new StorageType []{StorageType .DISK , StorageType .DISK , StorageType .DISK ,
@@ -1067,7 +1079,7 @@ public void testChangeHotFileRep() throws Exception {
10671079 */
10681080 @ Test
10691081 public void testChangeWarmRep () throws Exception {
1070- testChangeFileRep ("WARM" , WARM ,
1082+ testChangeFileRep (HdfsConstants . WARM_STORAGE_POLICY_NAME , WARM ,
10711083 new StorageType []{StorageType .DISK , StorageType .ARCHIVE ,
10721084 StorageType .ARCHIVE },
10731085 new StorageType []{StorageType .DISK , StorageType .ARCHIVE ,
@@ -1080,7 +1092,7 @@ public void testChangeWarmRep() throws Exception {
10801092 */
10811093 @ Test
10821094 public void testChangeColdRep () throws Exception {
1083- testChangeFileRep ("COLD" , COLD ,
1095+ testChangeFileRep (HdfsConstants . COLD_STORAGE_POLICY_NAME , COLD ,
10841096 new StorageType []{StorageType .ARCHIVE , StorageType .ARCHIVE ,
10851097 StorageType .ARCHIVE },
10861098 new StorageType []{StorageType .ARCHIVE , StorageType .ARCHIVE ,
@@ -1144,7 +1156,7 @@ public void testGetAllStoragePolicies() throws Exception {
11441156 final DistributedFileSystem fs = cluster .getFileSystem ();
11451157 try {
11461158 BlockStoragePolicy [] policies = fs .getStoragePolicies ();
1147- Assert .assertEquals (4 , policies .length );
1159+ Assert .assertEquals (6 , policies .length );
11481160 Assert .assertEquals (POLICY_SUITE .getPolicy (COLD ).toString (),
11491161 policies [0 ].toString ());
11501162 Assert .assertEquals (POLICY_SUITE .getPolicy (WARM ).toString (),
0 commit comments