|
22 | 22 | import org.junit.jupiter.api.io.TempDir; |
23 | 23 |
|
24 | 24 | import java.nio.charset.StandardCharsets; |
| 25 | +import java.nio.file.Files; |
25 | 26 | import java.nio.file.Path; |
26 | 27 | import java.time.Instant; |
27 | 28 | import java.util.ArrayList; |
@@ -2647,6 +2648,87 @@ void testSetClearHookNotRacingClose() throws TidesDBException, InterruptedExcept |
2647 | 2648 | } |
2648 | 2649 | } |
2649 | 2650 |
|
| 2651 | + @Test |
| 2652 | + @Order(71) |
| 2653 | + void testOpenWithObjectStoreFsPathFailsOnBadPath() throws Exception { |
| 2654 | + // A regular file (not a directory) as objectStoreFsPath must cause tidesdb_objstore_fs_create |
| 2655 | + // to return NULL, which should surface as TidesDBException instead of silently opening |
| 2656 | + // an ordinary local database. |
| 2657 | + Path osFile = tempDir.resolve("os_file"); |
| 2658 | + Files.createFile(osFile); |
| 2659 | + |
| 2660 | + Config config = Config.builder(tempDir.resolve("testdb_fs_badpath").toString()) |
| 2661 | + .objectStoreFsPath(osFile.toString()) |
| 2662 | + .build(); |
| 2663 | + |
| 2664 | + TidesDBException ex = assertThrows(TidesDBException.class, () -> TidesDB.open(config)); |
| 2665 | + assertEquals(TidesDBException.ERR_IO, ex.getErrorCode()); |
| 2666 | + } |
| 2667 | + |
| 2668 | + @Test |
| 2669 | + @Order(72) |
| 2670 | + void testOpenWithObjectStoreFsPathSucceedsWithValidDirectory() throws TidesDBException { |
| 2671 | + Path osDir = tempDir.resolve("os_dir"); |
| 2672 | + osDir.toFile().mkdirs(); |
| 2673 | + |
| 2674 | + Config config = Config.builder(tempDir.resolve("testdb_fs_goodpath").toString()) |
| 2675 | + .objectStoreFsPath(osDir.toString()) |
| 2676 | + .build(); |
| 2677 | + |
| 2678 | + try (TidesDB db = TidesDB.open(config)) { |
| 2679 | + assertNotNull(db); |
| 2680 | + DbStats dbStats = db.getDbStats(); |
| 2681 | + assertNotNull(dbStats); |
| 2682 | + assertTrue(dbStats.isObjectStoreEnabled()); |
| 2683 | + } |
| 2684 | + } |
| 2685 | + |
| 2686 | + @Test |
| 2687 | + @Order(73) |
| 2688 | + void testOpenWithoutObjectStoreFsPathSucceeds() throws TidesDBException { |
| 2689 | + Config config = Config.builder(tempDir.resolve("plaindb").toString()) |
| 2690 | + .numFlushThreads(2) |
| 2691 | + .numCompactionThreads(2) |
| 2692 | + .logLevel(LogLevel.INFO) |
| 2693 | + .blockCacheSize(64 * 1024 * 1024) |
| 2694 | + .maxOpenSSTables(256) |
| 2695 | + .build(); |
| 2696 | + |
| 2697 | + try (TidesDB db = TidesDB.open(config)) { |
| 2698 | + assertNotNull(db); |
| 2699 | + } |
| 2700 | + } |
| 2701 | + |
| 2702 | + @Test |
| 2703 | + @Order(74) |
| 2704 | + void testS3PrecedenceOverFsPathOnFailure() throws TidesDBException { |
| 2705 | + Path osFile = tempDir.resolve("os_file_s3"); |
| 2706 | + try { |
| 2707 | + Files.createFile(osFile); |
| 2708 | + } catch (java.io.IOException e) { |
| 2709 | + throw new RuntimeException(e); |
| 2710 | + } |
| 2711 | + |
| 2712 | + S3Config s3 = S3Config.builder() |
| 2713 | + .endpoint("127.0.0.1:19001") |
| 2714 | + .bucket("tidesdb-test") |
| 2715 | + .accessKey("minioadmin") |
| 2716 | + .secretKey("minioadmin") |
| 2717 | + .usePathStyle(true) |
| 2718 | + .useSsl(false) |
| 2719 | + .build(); |
| 2720 | + |
| 2721 | + Config config = Config.builder(tempDir.resolve("testdb_s3_over_fs").toString()) |
| 2722 | + .objectStoreS3Config(s3) |
| 2723 | + .objectStoreFsPath(osFile.toString()) |
| 2724 | + .build(); |
| 2725 | + |
| 2726 | + // S3 takes precedence over fs path. If S3 is available, the S3 connector creation or |
| 2727 | + // open fails with TidesDBException. If S3 is unavailable, the S3 connector creation |
| 2728 | + // itself throws. In neither case does a silent filesystem fallback occur. |
| 2729 | + assertThrows(TidesDBException.class, () -> TidesDB.open(config)); |
| 2730 | + } |
| 2731 | + |
2650 | 2732 | @Test |
2651 | 2733 | @Order(70) |
2652 | 2734 | void testJniBufferMethodsCoverage() throws TidesDBException { |
|
0 commit comments