|
44 | 44 | public class TestDataStorage { |
45 | 45 | private final static String DEFAULT_BPID = "bp-0"; |
46 | 46 | private final static String CLUSTER_ID = "cluster0"; |
| 47 | + private final static String CLUSTER_ID2 = "cluster1"; |
47 | 48 | private final static String BUILD_VERSION = "2.0"; |
48 | 49 | private final static String SOFTWARE_VERSION = "2.0"; |
49 | 50 | private final static long CTIME = 1; |
@@ -165,6 +166,35 @@ public void testAddStorageDirectories() throws IOException, |
165 | 166 | assertEquals(6, storage.getNumStorageDirs()); |
166 | 167 | } |
167 | 168 |
|
| 169 | + @Test |
| 170 | + public void testAddStorageDirectoriesFailure() throws IOException { |
| 171 | + final int numLocations = 1; |
| 172 | + List<StorageLocation> locations = createStorageLocations(numLocations); |
| 173 | + assertEquals(numLocations, locations.size()); |
| 174 | + |
| 175 | + NamespaceInfo namespaceInfo = new NamespaceInfo(0, CLUSTER_ID, |
| 176 | + DEFAULT_BPID, CTIME, BUILD_VERSION, SOFTWARE_VERSION); |
| 177 | + List<StorageDirectory> successLocations = storage.addStorageLocations( |
| 178 | + mockDN, namespaceInfo, locations, START_OPT); |
| 179 | + assertEquals(1, successLocations.size()); |
| 180 | + |
| 181 | + /** |
| 182 | + * After the DataNode restarts, the value of the clusterId is different |
| 183 | + * from the value before the restart. |
| 184 | + */ |
| 185 | + storage.unlockAll(); |
| 186 | + DataNode newMockDN = Mockito.mock(DataNode.class); |
| 187 | + Mockito.when(newMockDN.getConf()).thenReturn(new HdfsConfiguration()); |
| 188 | + DataStorage newStorage = new DataStorage(); |
| 189 | + NamespaceInfo newNamespaceInfo = new NamespaceInfo(0, CLUSTER_ID2, |
| 190 | + DEFAULT_BPID, CTIME, BUILD_VERSION, SOFTWARE_VERSION); |
| 191 | + successLocations = newStorage.addStorageLocations( |
| 192 | + newMockDN, newNamespaceInfo, locations, START_OPT); |
| 193 | + assertEquals(0, successLocations.size()); |
| 194 | + newStorage.unlockAll(); |
| 195 | + newMockDN.shutdown(); |
| 196 | + } |
| 197 | + |
168 | 198 | @Test |
169 | 199 | public void testMissingVersion() throws IOException, |
170 | 200 | URISyntaxException { |
|
0 commit comments