|
23 | 23 | import static org.lmdbjava.DbiFlags.MDB_CREATE; |
24 | 24 | import static org.lmdbjava.Env.Builder.MAX_READERS_DEFAULT; |
25 | 25 | import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR; |
| 26 | +import static org.lmdbjava.EnvFlags.MDB_NOTLS; |
26 | 27 | import static org.lmdbjava.EnvFlags.MDB_RDONLY_ENV; |
27 | 28 | import static org.lmdbjava.TestUtils.DB_1; |
28 | 29 | import static org.lmdbjava.TestUtils.bb; |
|
32 | 33 | import java.nio.ByteBuffer; |
33 | 34 | import java.nio.file.Files; |
34 | 35 | import java.nio.file.Path; |
| 36 | +import java.util.Collection; |
35 | 37 | import java.util.List; |
36 | 38 | import java.util.Random; |
| 39 | +import org.assertj.core.api.Assertions; |
37 | 40 | import org.junit.jupiter.api.AfterEach; |
38 | 41 | import org.junit.jupiter.api.BeforeEach; |
39 | 42 | import org.junit.jupiter.api.Test; |
@@ -557,4 +560,89 @@ void testDefaultOpenNoName2() { |
557 | 560 | assertThat(dbiNames.get(1)).isEqualTo("def".getBytes(Env.DEFAULT_NAME_CHARSET)); |
558 | 561 | } |
559 | 562 | } |
| 563 | + |
| 564 | + @Test |
| 565 | + void addEnvFlag() { |
| 566 | + final Path file = tempDir.createTempFile(); |
| 567 | + try (Env<ByteBuffer> env = |
| 568 | + Env.create() |
| 569 | + .setMapSize(1, ByteUnit.MEBIBYTES) |
| 570 | + .setMaxDbs(1) |
| 571 | + .setMaxReaders(1) |
| 572 | + .addEnvFlag(MDB_NOSUBDIR) |
| 573 | + .addEnvFlag(MDB_NOTLS) // Should not overwrite the existing one |
| 574 | + .open(file)) { |
| 575 | + env.sync(true); |
| 576 | + assertThat(Files.isRegularFile(file)).isTrue(); |
| 577 | + } |
| 578 | + } |
| 579 | + |
| 580 | + @Test |
| 581 | + void addEnvFlags() { |
| 582 | + final Path file = tempDir.createTempFile(); |
| 583 | + try (Env<ByteBuffer> env = |
| 584 | + Env.create() |
| 585 | + .setMapSize(1, ByteUnit.MEBIBYTES) |
| 586 | + .setMaxDbs(1) |
| 587 | + .setMaxReaders(1) |
| 588 | + .addEnvFlags(EnvFlagSet.of(MDB_NOSUBDIR, MDB_NOTLS)) |
| 589 | + .addEnvFlag(MDB_NOTLS) // Should not overwrite the existing one |
| 590 | + .addEnvFlag(null) // no-op |
| 591 | + .addEnvFlags(null) // no-op |
| 592 | + .open(file)) { |
| 593 | + env.sync(true); |
| 594 | + assertThat(Files.isRegularFile(file)).isTrue(); |
| 595 | + } |
| 596 | + } |
| 597 | + |
| 598 | + @Test |
| 599 | + void setEnvFlags_null1() { |
| 600 | + final Path file = tempDir.createTempFile(); |
| 601 | + // MDB_NOSUBDIR is cleared out so it will error as file is a file not a dir |
| 602 | + Assertions.assertThatThrownBy(() -> { |
| 603 | + try (Env<ByteBuffer> env = |
| 604 | + Env.create() |
| 605 | + .setMapSize(1, ByteUnit.MEBIBYTES) |
| 606 | + .setMaxDbs(1) |
| 607 | + .setMaxReaders(1) |
| 608 | + .addEnvFlag(MDB_NOSUBDIR) |
| 609 | + .setEnvFlags((Collection<EnvFlags>) null) // Clears the flags |
| 610 | + .open(file)) { |
| 611 | + } |
| 612 | + }).isInstanceOf(LmdbNativeException.class); |
| 613 | + } |
| 614 | + |
| 615 | + @Test |
| 616 | + void setEnvFlags_null2() { |
| 617 | + final Path file = tempDir.createTempFile(); |
| 618 | + // MDB_NOSUBDIR is cleared out so it will error as file is a file not a dir |
| 619 | + Assertions.assertThatThrownBy(() -> { |
| 620 | + try (Env<ByteBuffer> env = |
| 621 | + Env.create() |
| 622 | + .setMapSize(1, ByteUnit.MEBIBYTES) |
| 623 | + .setMaxDbs(1) |
| 624 | + .setMaxReaders(1) |
| 625 | + .addEnvFlag(MDB_NOSUBDIR) |
| 626 | + .setEnvFlags((EnvFlags) null) // Clears the flags |
| 627 | + .open(file)) { |
| 628 | + } |
| 629 | + }).isInstanceOf(LmdbNativeException.class); |
| 630 | + } |
| 631 | + |
| 632 | + @Test |
| 633 | + void setEnvFlags_null3() { |
| 634 | + final Path file = tempDir.createTempFile(); |
| 635 | + // MDB_NOSUBDIR is cleared out so it will error as file is a file not a dir |
| 636 | + Assertions.assertThatThrownBy(() -> { |
| 637 | + try (Env<ByteBuffer> env = |
| 638 | + Env.create() |
| 639 | + .setMapSize(1, ByteUnit.MEBIBYTES) |
| 640 | + .setMaxDbs(1) |
| 641 | + .setMaxReaders(1) |
| 642 | + .addEnvFlag(MDB_NOSUBDIR) |
| 643 | + .setEnvFlags((EnvFlagSet) null) // Clears the flags |
| 644 | + .open(file)) { |
| 645 | + } |
| 646 | + }).isInstanceOf(LmdbNativeException.class); |
| 647 | + } |
560 | 648 | } |
0 commit comments