PersistentManager implements Closeable { synchronized void freezeAllFilters(Iterable<FilterRecord<F>> records) throws IOException { final Path tempPath = temporaryPersistentFilePath(); int counter = 0; try (FileChannel channel = FileChannel.open(tempPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.READ)) { for (FilterRecord<F> record : records) { record.writeFullyTo(channel); counter++; } channel.force(true); } FilterServiceFileUtils.atomicMoveWithFallback(tempPath, persistentFilePath()); logger.debug("Persistent " + counter + " filters."); } PersistentManager(Path persistentPath); @Override synchronized void close();  }
@Test public void freezeAllFilters() throws IOException { final List<FilterRecord<BloomFilter>> records = generateFilterRecords(10); when(filterManager.iterator()).thenReturn(records.iterator()); manager.freezeAllFilters(filterManager); try (FilterRecordInputStream<GuavaBloomFilter> stream = new FilterRecordInputStream<>( manager.persistentFilePath(), new GuavaBloomFilterFactory())) { for (FilterRecord<BloomFilter> expectRecord : records) { assertThat(stream.nextFilterRecord()).isEqualTo(expectRecord); } assertThat(stream.nextFilterRecord()).isNull(); } }