]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/test/java/org/rocksdb/EnvOptionsTest.java
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / java / src / test / java / org / rocksdb / EnvOptionsTest.java
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).
5
6 package org.rocksdb;
7
8 import org.junit.ClassRule;
9 import org.junit.Test;
10
11 import java.util.Random;
12
13 import static org.assertj.core.api.Assertions.assertThat;
14
15 public class EnvOptionsTest {
16 @ClassRule
17 public static final RocksMemoryResource rocksMemoryResource = new RocksMemoryResource();
18
19 public static final Random rand = PlatformRandomHelper.getPlatformSpecificRandomFactory();
20
21 @Test
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);
29 }
30 }
31 }
32
33 @Test
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);
39 }
40 }
41
42 @Test
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);
48 }
49 }
50
51 @Test
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);
57 }
58 }
59
60 @Test
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);
66 }
67 }
68
69 @Test
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);
75 }
76 }
77
78 @Test
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);
84 }
85 }
86
87 @Test
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);
93 }
94 }
95
96 @Test
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);
102 }
103 }
104
105 @Test
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);
111 }
112 }
113
114 @Test
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);
120 }
121 }
122
123 @Test
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);
129 }
130 }
131
132 @Test
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);
138
139 try(final RateLimiter rateLimiter2 = new RateLimiter(1000)) {
140 envOptions.setRateLimiter(rateLimiter2);
141 assertThat(envOptions.rateLimiter()).isEqualTo(rateLimiter2);
142 }
143 }
144 }
145 }