### Question:
DataStorage extends Storage { synchronized void addStorageLocations(DataNode datanode, NamespaceInfo nsInfo, Collection<StorageLocation> dataDirs, StartupOption startOpt) throws IOException { List<StorageLocation> tmpDataDirs = new ArrayList<StorageLocation>(dataDirs); addStorageLocations(datanode, nsInfo, tmpDataDirs, startOpt, false, true); Collection<File> bpDataDirs = new ArrayList<File>(); String bpid = nsInfo.getBlockPoolID(); for (StorageLocation dir : dataDirs) { File dnRoot = dir.getFile(); File bpRoot = BlockPoolSliceStorage.getBpRoot(bpid, new File(dnRoot, STORAGE_DIR_CURRENT)); bpDataDirs.add(bpRoot); } makeBlockPoolDataDir(bpDataDirs, null); BlockPoolSliceStorage bpStorage = this.bpStorageMap.get(bpid); if (bpStorage == null) { bpStorage = new BlockPoolSliceStorage( nsInfo.getNamespaceID(), bpid, nsInfo.getCTime(), nsInfo.getClusterID()); } bpStorage.recoverTransitionRead(datanode, nsInfo, bpDataDirs, startOpt); addBlockPoolStorage(bpid, bpStorage); } DataStorage();  DataStorage(StorageInfo storageInfo); BlockPoolSliceStorage getBPStorage(String bpid); synchronized String getDatanodeUuid(); synchronized void setDatanodeUuid(String newDatanodeUuid); synchronized void createStorageID(StorageDirectory sd); void enableTrash(String bpid); void restoreTrash(String bpid); boolean trashEnabled(String bpid); String getTrashDirectoryForBlockFile(String bpid, File blockFile); @Override boolean isPreUpgradableLayout(StorageDirectory sd); final static String BLOCK_SUBDIR_PREFIX; final static String STORAGE_DIR_RBW; final static String STORAGE_DIR_FINALIZED; final static String STORAGE_DIR_TMP; }### Answer:
@Test public void testAddStorageDirectories() throws IOException, URISyntaxException { final int numLocations = 3; final int numNamespace = 3; List<StorageLocation> locations = createStorageLocations(numLocations); List<NamespaceInfo> namespaceInfos = createNamespaceInfos(numNamespace); for (NamespaceInfo ni : namespaceInfos) { storage.addStorageLocations(mockDN, ni, locations, START_OPT); for (StorageLocation sl : locations) { checkDir(sl.getFile()); checkDir(sl.getFile(), ni.getBlockPoolID()); } } assertEquals(numLocations, storage.getNumStorageDirs()); locations = createStorageLocations(numLocations); try { storage.addStorageLocations(mockDN, namespaceInfos.get(0), locations, START_OPT); fail("Expected to throw IOException: adding active directories."); } catch (IOException e) { GenericTestUtils.assertExceptionContains( "All specified directories are not accessible or do not exist.", e); } assertEquals(numLocations, storage.getNumStorageDirs()); locations = createStorageLocations(6); storage.addStorageLocations(mockDN, nsInfo, locations, START_OPT); assertEquals(6, storage.getNumStorageDirs()); }