/** * * @return Returns new empty storage indexing tree. */ private IStorageTreeComponent<DefaultData> getNewStorageIndexingTree() { return storageIndexTreeProvider.getStorageIndexingTree(); }
/** * Default constructor. Generates leaf ID. */ public ArrayBasedStorageLeaf() { this(StorageUtil.getRandomInt()); }
/** * {@inheritDoc} */ @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (deleteSource) { return super.postVisitDirectory(dir, exc); } return FileVisitResult.CONTINUE; }
/** * Deletes all files associated with given {@link StorageData}, thus completely removes storage * from disk. * * @param storageData * Storage to delete data for. * @throws IOException * If {@link IOException} happens. */ protected void deleteCompleteStorageDataFromDisk(IStorageData storageData) throws IOException { Path storageDir = getStoragePath(storageData); if (log.isDebugEnabled()) { log.info("Deleting the complete storage data from disk. Path: " + storageDir); } if (Files.exists(storageDir)) { Files.walkFileTree(storageDir, new DeleteFileVisitor()); } }
printStorageCmrVersionWarn(storageData); Files.walkFileTree(parentDir, new CopyMoveFileVisitor(parentDir, storageDir, true)); Path localInformation = getStoragePath(storageData).resolve(storageData.getId() + StorageFileType.LOCAL_STORAGE_FILE.getExtension()); Files.deleteIfExists(localInformation); Files.walkFileTree(parentDir, new DeleteFileVisitor());
/** * Deletes all files associated with given {@link StorageData}, but only of a types supplied * with a fileTypes parameter. * * @param storageData * Storage to delete data for. * @param fileTypes * File types to delete. * @throws IOException * If {@link IOException} happens. */ protected void deleteStorageDataFromDisk(IStorageData storageData, StorageFileType... fileTypes) throws IOException { Path storageDir = getStoragePath(storageData); if (log.isDebugEnabled()) { log.info("Deleting the storage data from disk. Path: " + storageDir + ". File types to delete: " + ArrayUtils.toString(fileTypes)); } if (Files.exists(storageDir)) { Files.walkFileTree(storageDir, new StorageDeleteFileVisitor(fileTypes, false)); } }
/** * Tests if copying files works with visitor. */ @Test public void copyFileVisitor() throws IOException { Path source = testPath.resolve("source"); Files.createDirectories(source); Path file = source.resolve(".testFile"); Files.createFile(file); Path target = testPath.resolve("target"); Path copiedFile = target.resolve(".testFile"); Files.walkFileTree(source, new CopyMoveFileVisitor(source, target)); assertThat(Files.exists(target), is(true)); assertThat(Files.exists(copiedFile), is(true)); Files.deleteIfExists(file); Files.deleteIfExists(copiedFile); Files.deleteIfExists(target); Files.delete(source); }
/** * {@inheritDoc} */ @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, toPath.resolve(fromPath.relativize(file)), StandardCopyOption.REPLACE_EXISTING); if (deleteSource) { return super.visitFile(file, attrs); } else { return FileVisitResult.CONTINUE; } }
@AfterTest public void cleanUp() throws IOException { if (Files.exists(testPath)) { Files.walkFileTree(testPath, new DeleteFileVisitor()); } Files.deleteIfExists(testPath); }
@SuppressWarnings("unchecked") @BeforeMethod public void init() { MockitoAnnotations.initMocks(this); indexingTreeHandler = new StorageIndexingTreeHandler(); indexingTreeHandler.registerStorageWriter(storageWriter); indexingTreeHandler.executorService = executorService; indexingTreeHandler.objectSizes = objectSizes; indexingTreeHandler.storageIndexTreeProvider = storageIndexTreeProvider; when(storageIndexTreeProvider.getStorageIndexingTree()).thenReturn(indexingTree); when(executorService.scheduleWithFixedDelay(Matchers.<Runnable> anyObject(), anyLong(), anyLong(), Matchers.<TimeUnit> anyObject())).thenReturn(future); indexingTreeHandler.prepare(); }
/** * Test that the deleting of the storage files works with visitor. */ @Test public void storageDeleteFileVisitor() throws IOException { StorageFileType storageFileType = StorageFileType.DATA_FILE; // we create additional dir and file in that dir Path dir = testPath.resolve("dir"); Files.createDirectories(dir); Path file = dir.resolve(storageFileType.getExtension()); Files.createFile(file); // first with no dir deletion Files.walkFileTree(dir, new StorageDeleteFileVisitor(new StorageFileType[] { storageFileType }, false)); assertThat(Files.exists(file), is(false)); assertThat(Files.exists(dir), is(true)); assertThat(Files.exists(testPath), is(true)); // then with dir deletion Files.walkFileTree(dir, new StorageDeleteFileVisitor(new StorageFileType[] { storageFileType }, true)); assertThat(Files.exists(dir), is(false)); assertThat(Files.exists(testPath), is(true)); }
/** * Tests if moving files works with visitor. */ @Test public void moveFileVisitor() throws IOException { Path source = testPath.resolve("source"); Files.createDirectories(source); Path file = source.resolve(".testFile"); Files.createFile(file); Path target = testPath.resolve("target"); Path copiedFile = target.resolve(".testFile"); Files.walkFileTree(source, new CopyMoveFileVisitor(source, target, true)); assertThat(Files.exists(file), is(false)); assertThat(Files.exists(source), is(false)); assertThat(Files.exists(target), is(true)); assertThat(Files.exists(copiedFile), is(true)); Files.deleteIfExists(copiedFile); Files.deleteIfExists(target); } }
/** * This constructor will generate unique ID and will not set child indexer. * * @param delegateIndexer * Provides delegate indexer with a constructor. * @param passId * If pass ID mode is on. With this mode, all sub-components created with this * indexer will have same ID, thus write will be done in same file. */ public StorageBranchIndexer(IBranchIndexer<E> delegateIndexer, boolean passId) { this(delegateIndexer, null, StorageUtil.getRandomInt(), passId); }
/** * {@inheritDoc} */ @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (deleteDirs) { try { return super.postVisitDirectory(dir, exc); } catch (IOException e) { // if directory delete fails, we still want to continue return FileVisitResult.CONTINUE; } } return FileVisitResult.CONTINUE; }
/** * {@inheritDoc} * <p> * Only deletes the files that have extension matching the supplied {@link #storageFileTypes}. */ @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (ArrayUtils.isNotEmpty(storageFileTypes)) { for (StorageFileType storageFileType : storageFileTypes) { if (file.endsWith(storageFileType.getExtension())) { return super.visitFile(file, attrs); } } } return FileVisitResult.CONTINUE; }
/** * Clean test folder after each test. */ @AfterMethod public void cleanUp() throws IOException { if (Files.exists(Paths.get(TEST_FOLDER))) { Files.walkFileTree(Paths.get(TEST_FOLDER), new DeleteFileVisitor()); Files.deleteIfExists(Paths.get(TEST_FOLDER)); } }
/** * This constructor allows setting of all properties except ID that will be uniquely generated. * * @param delegateIndexer * Provides delegate indexer with a constructor. * @param childIndexer * Provides child indexer. * @param passId * If pass ID mode is on. With this mode, all sub-components created with this * indexer will have same ID, thus write will be done in same file. */ public StorageBranchIndexer(IBranchIndexer<E> delegateIndexer, StorageBranchIndexer<E> childIndexer, boolean passId) { this(delegateIndexer, childIndexer, StorageUtil.getRandomInt(), passId); }
/** * Clean test folder after each test. */ @AfterMethod public void cleanUp() throws IOException { if (Files.exists(Paths.get(TEST_FOLDER))) { Files.walkFileTree(Paths.get(TEST_FOLDER), new DeleteFileVisitor()); Files.deleteIfExists(Paths.get(TEST_FOLDER)); } } }
/** * Default constructor. Generates leaf ID. */ public LeafWithNoDescriptors() { this(StorageUtil.getRandomInt()); }
/** * Test that deleting of directory and it content works, but that the parent dir won't be * touched. */ @Test public void deleteFileVisitor() throws IOException { // we create additional dir and file in that dir Path dir = testPath.resolve("dir"); Files.createDirectories(dir); Path file = dir.resolve(".testFile"); Files.createFile(file); Files.walkFileTree(dir, new DeleteFileVisitor()); assertThat(Files.exists(file), is(false)); assertThat(Files.exists(dir), is(false)); assertThat(Files.exists(testPath), is(true)); }