1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
8 import org
.junit
.ClassRule
;
11 import java
.util
.Random
;
13 import static org
.assertj
.core
.api
.Assertions
.assertThat
;
15 public class EnvOptionsTest
{
17 public static final RocksMemoryResource rocksMemoryResource
= new RocksMemoryResource();
19 public static final Random rand
= PlatformRandomHelper
.getPlatformSpecificRandomFactory();
22 public void dbOptionsConstructor() {
23 final long compactionReadaheadSize
= 4 * 1024 * 1024;
24 try (final DBOptions dbOptions
= new DBOptions()
25 .setCompactionReadaheadSize(compactionReadaheadSize
)) {
26 try (final EnvOptions envOptions
= new EnvOptions(dbOptions
)) {
27 assertThat(envOptions
.compactionReadaheadSize())
28 .isEqualTo(compactionReadaheadSize
);
34 public void useMmapReads() {
35 try (final EnvOptions envOptions
= new EnvOptions()) {
36 final boolean boolValue
= rand
.nextBoolean();
37 envOptions
.setUseMmapReads(boolValue
);
38 assertThat(envOptions
.useMmapReads()).isEqualTo(boolValue
);
43 public void useMmapWrites() {
44 try (final EnvOptions envOptions
= new EnvOptions()) {
45 final boolean boolValue
= rand
.nextBoolean();
46 envOptions
.setUseMmapWrites(boolValue
);
47 assertThat(envOptions
.useMmapWrites()).isEqualTo(boolValue
);
52 public void useDirectReads() {
53 try (final EnvOptions envOptions
= new EnvOptions()) {
54 final boolean boolValue
= rand
.nextBoolean();
55 envOptions
.setUseDirectReads(boolValue
);
56 assertThat(envOptions
.useDirectReads()).isEqualTo(boolValue
);
61 public void useDirectWrites() {
62 try (final EnvOptions envOptions
= new EnvOptions()) {
63 final boolean boolValue
= rand
.nextBoolean();
64 envOptions
.setUseDirectWrites(boolValue
);
65 assertThat(envOptions
.useDirectWrites()).isEqualTo(boolValue
);
70 public void allowFallocate() {
71 try (final EnvOptions envOptions
= new EnvOptions()) {
72 final boolean boolValue
= rand
.nextBoolean();
73 envOptions
.setAllowFallocate(boolValue
);
74 assertThat(envOptions
.allowFallocate()).isEqualTo(boolValue
);
79 public void setFdCloexecs() {
80 try (final EnvOptions envOptions
= new EnvOptions()) {
81 final boolean boolValue
= rand
.nextBoolean();
82 envOptions
.setSetFdCloexec(boolValue
);
83 assertThat(envOptions
.setFdCloexec()).isEqualTo(boolValue
);
88 public void bytesPerSync() {
89 try (final EnvOptions envOptions
= new EnvOptions()) {
90 final long longValue
= rand
.nextLong();
91 envOptions
.setBytesPerSync(longValue
);
92 assertThat(envOptions
.bytesPerSync()).isEqualTo(longValue
);
97 public void fallocateWithKeepSize() {
98 try (final EnvOptions envOptions
= new EnvOptions()) {
99 final boolean boolValue
= rand
.nextBoolean();
100 envOptions
.setFallocateWithKeepSize(boolValue
);
101 assertThat(envOptions
.fallocateWithKeepSize()).isEqualTo(boolValue
);
106 public void compactionReadaheadSize() {
107 try (final EnvOptions envOptions
= new EnvOptions()) {
108 final int intValue
= rand
.nextInt();
109 envOptions
.setCompactionReadaheadSize(intValue
);
110 assertThat(envOptions
.compactionReadaheadSize()).isEqualTo(intValue
);
115 public void randomAccessMaxBufferSize() {
116 try (final EnvOptions envOptions
= new EnvOptions()) {
117 final int intValue
= rand
.nextInt();
118 envOptions
.setRandomAccessMaxBufferSize(intValue
);
119 assertThat(envOptions
.randomAccessMaxBufferSize()).isEqualTo(intValue
);
124 public void writableFileMaxBufferSize() {
125 try (final EnvOptions envOptions
= new EnvOptions()) {
126 final int intValue
= rand
.nextInt();
127 envOptions
.setWritableFileMaxBufferSize(intValue
);
128 assertThat(envOptions
.writableFileMaxBufferSize()).isEqualTo(intValue
);
133 public void rateLimiter() {
134 try (final EnvOptions envOptions
= new EnvOptions();
135 final RateLimiter rateLimiter1
= new RateLimiter(1000, 100 * 1000, 1)) {
136 envOptions
.setRateLimiter(rateLimiter1
);
137 assertThat(envOptions
.rateLimiter()).isEqualTo(rateLimiter1
);
139 try(final RateLimiter rateLimiter2
= new RateLimiter(1000)) {
140 envOptions
.setRateLimiter(rateLimiter2
);
141 assertThat(envOptions
.rateLimiter()).isEqualTo(rateLimiter2
);