StroomZipRepository { void clean(final boolean deleteRootDirectory) { LOGGER.info("clean() " + currentDir); clean(currentDir, deleteRootDirectory); } StroomZipRepository(final String dir, final boolean readOnly);   StroomZipRepository(final String dir,
                        final String repositoryFormat,
                        final boolean lock,
                        final int lockDeleteAgeMs,
                        final int cleanDelayMs,
                        final boolean readOnly);   StroomZipRepository(final String dir,
                        final String repositoryFormat,
                        final boolean lock,
                        final int lockDeleteAgeMs,
                        final boolean readOnly,
                        final LinkedBlockingDeque<StroomZipRepository> rolledRepositoryQueue);   StroomZipRepository(final String dir,
                        final String repositoryFormat,
                        final boolean lock,
                        final int lockDeleteAgeMs,
                        final int cleanDelayMs,
                        final boolean readOnly,
                        final LinkedBlockingDeque<StroomZipRepository> rolledRepositoryQueue); Path getRootDir(); final static String ZIP_EXTENSION; }
@Test void testClean() throws IOException { final String repoDir = FileUtil.getCanonicalPath(Files.createTempDirectory("stroom").resolve("repo2")); StroomZipRepository stroomZipRepository = new StroomZipRepository(repoDir, null, false, 10000, 0, false); StroomZipOutputStreamImpl out1; try (final StroomZipOutputStreamImpl out = (StroomZipOutputStreamImpl) stroomZipRepository.getStroomZipOutputStream()) { StroomZipOutputStreamUtil.addSimpleEntry(out, new StroomZipEntry(null, "file", StroomZipFileType.Data), "SOME_DATA".getBytes(CharsetConstants.DEFAULT_CHARSET)); assertThat(Files.isRegularFile(out.getFile())).isFalse(); out1 = out; } assertThat(Files.isRegularFile(out1.getFile())).isTrue(); final StroomZipOutputStreamImpl out2 = (StroomZipOutputStreamImpl) stroomZipRepository.getStroomZipOutputStream(); StroomZipOutputStreamUtil.addSimpleEntry(out2, new StroomZipEntry(null, "file", StroomZipFileType.Data), "SOME_DATA".getBytes(CharsetConstants.DEFAULT_CHARSET)); assertThat(Files.isRegularFile(out2.getFile())).isFalse(); assertThat(Files.isRegularFile(out2.getLockFile())).isTrue(); stroomZipRepository = new StroomZipRepository(repoDir, null, false, 1000, 0, false); assertThat(Files.isRegularFile(out1.getFile())).as("Expecting pucker file to be left").isTrue(); assertThat(Files.isRegularFile(out2.getLockFile())).as("Expecting lock file to not be deleted").isTrue(); final StroomZipOutputStreamImpl out3 = (StroomZipOutputStreamImpl) stroomZipRepository.getStroomZipOutputStream(); StroomZipOutputStreamUtil.addSimpleEntry(out3, new StroomZipEntry(null, "file", StroomZipFileType.Data), "SOME_DATA".getBytes(CharsetConstants.DEFAULT_CHARSET)); final Path lockFile3 = out3.getLockFile(); assertThat(Files.isRegularFile(lockFile3)).isTrue(); stroomZipRepository.clean(true); assertThat(Files.isRegularFile(lockFile3)).isTrue(); try { Files.setLastModifiedTime(lockFile3, FileTime.fromMillis(System.currentTimeMillis() - (48 * 60 * 60 * 1000))); } catch (final RuntimeException e) { fail("Unable to set LastModified"); } stroomZipRepository.clean(true); assertThat(Files.isRegularFile(lockFile3)).as("Expecting old lock file to be deleted").isFalse(); }
@Test void testClean_emptyRepo() throws IOException { final String repoDir = FileUtil.getCanonicalPath(Files.createTempDirectory("stroom").resolve("repo2")); StroomZipRepository stroomZipRepository = new StroomZipRepository( repoDir, null, false, 10000, 0, false); Path repoDirPath = Paths.get(repoDir); assertThat(repoDirPath).exists(); stroomZipRepository.clean(false); assertThat(repoDirPath).exists(); stroomZipRepository.clean(true); assertThat(repoDirPath).doesNotExist(); }
@Test void testClean_tooNew() throws IOException { final String repoDir = FileUtil.getCanonicalPath(Files.createTempDirectory("stroom").resolve("repo2")); int cleanDelayMs = (int) Duration.ofHours(1).toMillis(); StroomZipRepository stroomZipRepository = new StroomZipRepository( repoDir, null, false, 10000, cleanDelayMs, false); Path repoDirPath = Paths.get(repoDir); assertThat(repoDirPath).exists(); stroomZipRepository.clean(false); assertThat(repoDirPath).exists(); stroomZipRepository.clean(true); assertThat(repoDirPath).exists(); }