Skip to content

Commit

Permalink
remove duplicate tests, tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
nginthfs committed Sep 17, 2024
1 parent 25e918c commit cc32c88
Showing 1 changed file with 10 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cc32c88

Please sign in to comment.