From cc32c888770770f24792a5731996bb3336d3e64a Mon Sep 17 00:00:00 2001 From: Nick Ginther Date: Tue, 17 Sep 2024 09:23:01 -0500 Subject: [PATCH] remove duplicate tests, tidy --- .../solr/storage/SizeAwareDirectoryTest.java | 94 ++----------------- 1 file changed, 10 insertions(+), 84 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/storage/SizeAwareDirectoryTest.java b/solr/core/src/test/org/apache/solr/storage/SizeAwareDirectoryTest.java index e7e9fa691ce..b8465d8c79a 100644 --- a/solr/core/src/test/org/apache/solr/storage/SizeAwareDirectoryTest.java +++ b/solr/core/src/test/org/apache/solr/storage/SizeAwareDirectoryTest.java @@ -3,7 +3,6 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; @@ -32,42 +31,6 @@ public void setUp() throws Exception { path = createTempDir().toString() + "/somedir"; } - @Test - public void testInitSize() throws Exception { - CompressingDirectoryFactory dirFac = new CompressingDirectoryFactory(); - try (dirFac) { - dirFac.initCoreContainer(null); - dirFac.init(new NamedList<>()); - - Directory dir = - dirFac.get(path, DirectoryFactory.DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE); - try { - try (IndexOutput file = dir.createOutput("test_file", IOContext.DEFAULT)) { - file.writeInt(42); - } // implicitly close file - - try (IndexOutput file = dir.createOutput("test_file2", IOContext.DEFAULT)) { - file.writeInt(84); - } // implicitly close file - - dir.sync(Collections.singleton("test_file")); - assertTrue(path + " should exist once file is synced", dirFac.exists(path)); - dir.sync(Collections.singleton("test_file2")); - assertTrue(path + " should exist once file is synced", dirFac.exists(path)); - - long expectedDiskSize = - Files.size(Paths.get(path + "/test_file")) - + Files.size(Paths.get(path + "/test_file2")); - assertEquals( - "directory size should be equal to on disk size of test files", - expectedDiskSize, - dirFac.onDiskSize(dir)); - } finally { - dirFac.release(dir); - } - } - } - @Test public void testSizeTracking() throws Exception { // after onDiskSize has been init(), the size should be correct using the LongAdder sum in @@ -108,7 +71,9 @@ public void testSizeTracking() throws Exception { } @Test - public void testWriteBigFile() throws Exception { + public void testDelete() throws Exception { + // write a file, then another, then delete one of the files - the onDiskSize should update + // correctly CompressingDirectoryFactory dirFac = new CompressingDirectoryFactory(); try (dirFac) { dirFac.initCoreContainer(null); @@ -137,6 +102,13 @@ public void testWriteBigFile() throws Exception { "directory size should be equal to on disk size of test files", expectedDiskSize, dirFac.onDiskSize(dir)); + + deleteFile(dir, "test_file2"); + expectedDiskSize = Files.size(Paths.get(path + "/test_file")); + assertEquals( + "directory size should be equal to on disk size of test files", + expectedDiskSize, + dirFac.onDiskSize(dir)); } finally { dirFac.release(dir); } @@ -274,52 +246,6 @@ public void run() { } } - @Test - public void testDelete() throws Exception { - // write a file, then another, then delete one of the files - the onDiskSize should update - // correctly - CompressingDirectoryFactory dirFac = new CompressingDirectoryFactory(); - ; - try (dirFac) { - dirFac.initCoreContainer(null); - dirFac.init(new NamedList<>()); - - Directory dir = - dirFac.get(path, DirectoryFactory.DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE); - try { - // small file first to initSize() - try (IndexOutput file = dir.createOutput("test_file", IOContext.DEFAULT)) { - file.writeInt(42); - } // implicitly close file - - long expectedDiskSize = Files.size(Paths.get(path + "/test_file")); - assertEquals( - "directory size should be equal to on disk size of test files", - expectedDiskSize, - dirFac.onDiskSize(dir)); - - writeBlockSizeFile(dir, "test_file2"); - - expectedDiskSize = - Files.size(Paths.get(path + "/test_file")) - + Files.size(Paths.get(path + "/test_file2")); - assertEquals( - "directory size should be equal to on disk size of test files", - expectedDiskSize, - dirFac.onDiskSize(dir)); - - deleteFile(dir, "test_file2"); - expectedDiskSize = Files.size(Paths.get(path + "/test_file")); - assertEquals( - "directory size should be equal to on disk size of test files", - expectedDiskSize, - dirFac.onDiskSize(dir)); - } finally { - dirFac.release(dir); - } - } - } - private void deleteFile(Directory dir, String name) throws Exception { dir.deleteFile(name); activeFiles.remove(name);