diff --git a/platform/platform-tests/testSrc/com/intellij/util/io/PerformanceOfFileAccessWithFilePageCacheTest.java b/platform/platform-tests/testSrc/com/intellij/util/io/PerformanceOfFileAccessWithFilePageCacheTest.java index ade0056d5c2d..58a420bc7639 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/io/PerformanceOfFileAccessWithFilePageCacheTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/io/PerformanceOfFileAccessWithFilePageCacheTest.java @@ -225,8 +225,7 @@ public class PerformanceOfFileAccessWithFilePageCacheTest extends PerformanceOfF final long[] offsetsToRequest = IntStream.range(0, DIFFERENT_OFFSETS_TO_REQUEST) .mapToLong(i -> ThreadLocalRandom.current().nextLong(FILE_SIZE)) .toArray(); - final PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true); - try { + try (PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true)) { final Callable task = () -> { final ThreadLocalRandom rnd = ThreadLocalRandom.current(); final int requestNo = rnd.nextInt(offsetsToRequest.length); @@ -282,9 +281,6 @@ public class PerformanceOfFileAccessWithFilePageCacheTest extends PerformanceOfF final FilePageCacheStatistics statistics = pageCache.getStatistics(); System.out.println(statistics); } - finally { - pagedStorage.close(); - } } @Test @@ -296,8 +292,7 @@ public class PerformanceOfFileAccessWithFilePageCacheTest extends PerformanceOfF final long[] offsetsToRequest = IntStream.range(0, DIFFERENT_OFFSETS_TO_REQUEST) .mapToLong(i -> ThreadLocalRandom.current().nextLong(FILE_SIZE)) .toArray(); - final PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true); - try { + try (PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true)) { final Callable task = () -> { final ThreadLocalRandom rnd = ThreadLocalRandom.current(); final int requestNo = rnd.nextInt(offsetsToRequest.length); @@ -356,9 +351,6 @@ public class PerformanceOfFileAccessWithFilePageCacheTest extends PerformanceOfF final FilePageCacheStatistics statistics = pageCache.getStatistics(); System.out.println(statistics); } - finally { - pagedStorage.close(); - } } @@ -366,8 +358,7 @@ public class PerformanceOfFileAccessWithFilePageCacheTest extends PerformanceOfF private void readFileSequentiallyTwice(final @NotNull File file, final @NotNull ByteBuffer buffer) throws IOException { - final PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true); - try { + try (PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true)) { final long blocksCount = FILE_SIZE / BUFFER_SIZE; for (int turn = 0; turn < TWICE; turn++) { for (int blockNo = 0; blockNo < blocksCount; blockNo++) { @@ -391,15 +382,11 @@ public class PerformanceOfFileAccessWithFilePageCacheTest extends PerformanceOfF } } } - finally { - pagedStorage.close(); - } } private void readFileRandomlyApproximatelyTwice(final @NotNull File file, final @NotNull ByteBuffer buffer) throws IOException { - final PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true); - try { + try (PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true)) { final ThreadLocalRandom rnd = ThreadLocalRandom.current(); final long blocksCount = FILE_SIZE / BUFFER_SIZE; for (int i = 0; i < blocksCount * TWICE; i++) { @@ -423,15 +410,11 @@ public class PerformanceOfFileAccessWithFilePageCacheTest extends PerformanceOfF } } } - finally { - pagedStorage.close(); - } } private void writeFileSequentiallyTwice(final @NotNull File file, final @NotNull ByteBuffer buffer) throws IOException { - final PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true); - try { + try (PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true)) { final long blocksCount = FILE_SIZE / BUFFER_SIZE; for (int turn = 0; turn < TWICE; turn++) { for (int blockNo = 0; blockNo < blocksCount; blockNo++) { @@ -454,15 +437,11 @@ public class PerformanceOfFileAccessWithFilePageCacheTest extends PerformanceOfF } } } - finally { - pagedStorage.close(); - } } private void writeFileRandomlyApproximatelyTwice(final @NotNull File file, final @NotNull ByteBuffer buffer) throws IOException { - final PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true); - try { + try (PagedFileStorage pagedStorage = new PagedFileStorage(file.toPath(), storageContext, BUFFER_SIZE, true, true)) { final ThreadLocalRandom rnd = ThreadLocalRandom.current(); final long blocksCount = FILE_SIZE / BUFFER_SIZE; for (int i = 0; i < blocksCount * TWICE; i++) { @@ -485,8 +464,5 @@ public class PerformanceOfFileAccessWithFilePageCacheTest extends PerformanceOfF } } } - finally { - pagedStorage.close(); - } } } \ No newline at end of file