Skip to content

Commit 42381be

Browse files
committed
Improve unit test for block condition check
1 parent 1b41027 commit 42381be

File tree

1 file changed

+23
-12
lines changed
  • hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement

1 file changed

+23
-12
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockInfo.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,35 @@ public void testAddStorage() throws Exception {
6969

7070
@Test
7171
public void testAddProvidedStorage() throws Exception {
72+
// block with only provided storage
7273
BlockInfo blockInfo = new BlockInfoContiguous((short) 3);
73-
74-
DatanodeStorageInfo storage = mock(DatanodeStorageInfo.class);
75-
when(storage.getStorageType()).thenReturn(StorageType.PROVIDED);
76-
boolean added = blockInfo.addStorage(storage, blockInfo);
77-
74+
DatanodeStorageInfo providedStorage = mock(DatanodeStorageInfo.class);
75+
when(providedStorage.getStorageType()).thenReturn(StorageType.PROVIDED);
76+
boolean added = blockInfo.addStorage(providedStorage, blockInfo);
7877
Assert.assertTrue(added);
79-
Assert.assertEquals(storage, blockInfo.getStorageInfo(0));
78+
Assert.assertEquals(providedStorage, blockInfo.getStorageInfo(0));
8079
Assert.assertTrue(blockInfo.isProvided());
80+
}
8181

82-
blockInfo = new BlockInfoContiguous((short) 3);
83-
storage = mock(DatanodeStorageInfo.class);
84-
when(storage.getStorageType()).thenReturn(StorageType.DISK);
85-
added = blockInfo.addStorage(storage, blockInfo);
86-
82+
@Test
83+
public void testAddTwoStorageTypes() throws Exception {
84+
// block with only disk storage
85+
BlockInfo blockInfo = new BlockInfoContiguous((short) 3);
86+
DatanodeStorageInfo diskStorage = mock(DatanodeStorageInfo.class);
87+
DatanodeDescriptor mockDN = mock(DatanodeDescriptor.class);
88+
when(diskStorage.getDatanodeDescriptor()).thenReturn(mockDN);
89+
when(diskStorage.getStorageType()).thenReturn(StorageType.DISK);
90+
boolean added = blockInfo.addStorage(diskStorage, blockInfo);
8791
Assert.assertTrue(added);
88-
Assert.assertEquals(storage, blockInfo.getStorageInfo(0));
92+
Assert.assertEquals(diskStorage, blockInfo.getStorageInfo(0));
8993
Assert.assertFalse(blockInfo.isProvided());
94+
95+
// now add provided storage
96+
DatanodeStorageInfo providedStorage = mock(DatanodeStorageInfo.class);
97+
when(providedStorage.getStorageType()).thenReturn(StorageType.PROVIDED);
98+
added = blockInfo.addStorage(providedStorage, blockInfo);
99+
Assert.assertTrue(added);
100+
Assert.assertTrue(blockInfo.isProvided());
90101
}
91102

92103
@Test

0 commit comments

Comments
 (0)