]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/test/java/org/rocksdb/ReadOptionsTest.java
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / java / src / test / java / org / rocksdb / ReadOptionsTest.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 java.util.Arrays;
9 import java.util.Random;
10
11 import org.junit.ClassRule;
12 import org.junit.Rule;
13 import org.junit.Test;
14 import org.junit.rules.ExpectedException;
15
16 import static org.assertj.core.api.Assertions.assertThat;
17
18 public class ReadOptionsTest {
19
20 @ClassRule
21 public static final RocksMemoryResource rocksMemoryResource =
22 new RocksMemoryResource();
23
24 @Rule
25 public ExpectedException exception = ExpectedException.none();
26
27 @Test
28 public void altConstructor() {
29 try (final ReadOptions opt = new ReadOptions(true, true)) {
30 assertThat(opt.verifyChecksums()).isTrue();
31 assertThat(opt.fillCache()).isTrue();
32 }
33 }
34
35 @Test
36 public void copyConstructor() {
37 try (final ReadOptions opt = new ReadOptions()) {
38 opt.setVerifyChecksums(false);
39 opt.setFillCache(false);
40 opt.setIterateUpperBound(buildRandomSlice());
41 opt.setIterateLowerBound(buildRandomSlice());
42 try (final ReadOptions other = new ReadOptions(opt)) {
43 assertThat(opt.verifyChecksums()).isEqualTo(other.verifyChecksums());
44 assertThat(opt.fillCache()).isEqualTo(other.fillCache());
45 assertThat(Arrays.equals(opt.iterateUpperBound().data(), other.iterateUpperBound().data())).isTrue();
46 assertThat(Arrays.equals(opt.iterateLowerBound().data(), other.iterateLowerBound().data())).isTrue();
47 }
48 }
49 }
50
51 @Test
52 public void verifyChecksum() {
53 try (final ReadOptions opt = new ReadOptions()) {
54 final Random rand = new Random();
55 final boolean boolValue = rand.nextBoolean();
56 opt.setVerifyChecksums(boolValue);
57 assertThat(opt.verifyChecksums()).isEqualTo(boolValue);
58 }
59 }
60
61 @Test
62 public void fillCache() {
63 try (final ReadOptions opt = new ReadOptions()) {
64 final Random rand = new Random();
65 final boolean boolValue = rand.nextBoolean();
66 opt.setFillCache(boolValue);
67 assertThat(opt.fillCache()).isEqualTo(boolValue);
68 }
69 }
70
71 @Test
72 public void tailing() {
73 try (final ReadOptions opt = new ReadOptions()) {
74 final Random rand = new Random();
75 final boolean boolValue = rand.nextBoolean();
76 opt.setTailing(boolValue);
77 assertThat(opt.tailing()).isEqualTo(boolValue);
78 }
79 }
80
81 @Test
82 public void snapshot() {
83 try (final ReadOptions opt = new ReadOptions()) {
84 opt.setSnapshot(null);
85 assertThat(opt.snapshot()).isNull();
86 }
87 }
88
89 @Test
90 public void readTier() {
91 try (final ReadOptions opt = new ReadOptions()) {
92 opt.setReadTier(ReadTier.BLOCK_CACHE_TIER);
93 assertThat(opt.readTier()).isEqualTo(ReadTier.BLOCK_CACHE_TIER);
94 }
95 }
96
97 @Test
98 public void managed() {
99 try (final ReadOptions opt = new ReadOptions()) {
100 opt.setManaged(true);
101 assertThat(opt.managed()).isTrue();
102 }
103 }
104
105 @Test
106 public void totalOrderSeek() {
107 try (final ReadOptions opt = new ReadOptions()) {
108 opt.setTotalOrderSeek(true);
109 assertThat(opt.totalOrderSeek()).isTrue();
110 }
111 }
112
113 @Test
114 public void prefixSameAsStart() {
115 try (final ReadOptions opt = new ReadOptions()) {
116 opt.setPrefixSameAsStart(true);
117 assertThat(opt.prefixSameAsStart()).isTrue();
118 }
119 }
120
121 @Test
122 public void pinData() {
123 try (final ReadOptions opt = new ReadOptions()) {
124 opt.setPinData(true);
125 assertThat(opt.pinData()).isTrue();
126 }
127 }
128
129 @Test
130 public void backgroundPurgeOnIteratorCleanup() {
131 try (final ReadOptions opt = new ReadOptions()) {
132 opt.setBackgroundPurgeOnIteratorCleanup(true);
133 assertThat(opt.backgroundPurgeOnIteratorCleanup()).isTrue();
134 }
135 }
136
137 @Test
138 public void readaheadSize() {
139 try (final ReadOptions opt = new ReadOptions()) {
140 final Random rand = new Random();
141 final long longValue = rand.nextLong();
142 opt.setReadaheadSize(longValue);
143 assertThat(opt.readaheadSize()).isEqualTo(longValue);
144 }
145 }
146
147 @Test
148 public void ignoreRangeDeletions() {
149 try (final ReadOptions opt = new ReadOptions()) {
150 opt.setIgnoreRangeDeletions(true);
151 assertThat(opt.ignoreRangeDeletions()).isTrue();
152 }
153 }
154
155 @Test
156 public void iterateUpperBound() {
157 try (final ReadOptions opt = new ReadOptions()) {
158 Slice upperBound = buildRandomSlice();
159 opt.setIterateUpperBound(upperBound);
160 assertThat(Arrays.equals(upperBound.data(), opt.iterateUpperBound().data())).isTrue();
161 }
162 }
163
164 @Test
165 public void iterateUpperBoundNull() {
166 try (final ReadOptions opt = new ReadOptions()) {
167 assertThat(opt.iterateUpperBound()).isNull();
168 }
169 }
170
171 @Test
172 public void iterateLowerBound() {
173 try (final ReadOptions opt = new ReadOptions()) {
174 Slice lowerBound = buildRandomSlice();
175 opt.setIterateLowerBound(lowerBound);
176 assertThat(Arrays.equals(lowerBound.data(), opt.iterateLowerBound().data())).isTrue();
177 }
178 }
179
180 @Test
181 public void iterateLowerBoundNull() {
182 try (final ReadOptions opt = new ReadOptions()) {
183 assertThat(opt.iterateLowerBound()).isNull();
184 }
185 }
186
187 @Test
188 public void tableFilter() {
189 try (final ReadOptions opt = new ReadOptions();
190 final AbstractTableFilter allTablesFilter = new AllTablesFilter()) {
191 opt.setTableFilter(allTablesFilter);
192 }
193 }
194
195 @Test
196 public void iterStartSeqnum() {
197 try (final ReadOptions opt = new ReadOptions()) {
198 assertThat(opt.iterStartSeqnum()).isEqualTo(0);
199
200 opt.setIterStartSeqnum(10);
201 assertThat(opt.iterStartSeqnum()).isEqualTo(10);
202 }
203 }
204
205 @Test
206 public void failSetVerifyChecksumUninitialized() {
207 try (final ReadOptions readOptions =
208 setupUninitializedReadOptions(exception)) {
209 readOptions.setVerifyChecksums(true);
210 }
211 }
212
213 @Test
214 public void failVerifyChecksumUninitialized() {
215 try (final ReadOptions readOptions =
216 setupUninitializedReadOptions(exception)) {
217 readOptions.verifyChecksums();
218 }
219 }
220
221 @Test
222 public void failSetFillCacheUninitialized() {
223 try (final ReadOptions readOptions =
224 setupUninitializedReadOptions(exception)) {
225 readOptions.setFillCache(true);
226 }
227 }
228
229 @Test
230 public void failFillCacheUninitialized() {
231 try (final ReadOptions readOptions =
232 setupUninitializedReadOptions(exception)) {
233 readOptions.fillCache();
234 }
235 }
236
237 @Test
238 public void failSetTailingUninitialized() {
239 try (final ReadOptions readOptions =
240 setupUninitializedReadOptions(exception)) {
241 readOptions.setTailing(true);
242 }
243 }
244
245 @Test
246 public void failTailingUninitialized() {
247 try (final ReadOptions readOptions =
248 setupUninitializedReadOptions(exception)) {
249 readOptions.tailing();
250 }
251 }
252
253 @Test
254 public void failSetSnapshotUninitialized() {
255 try (final ReadOptions readOptions =
256 setupUninitializedReadOptions(exception)) {
257 readOptions.setSnapshot(null);
258 }
259 }
260
261 @Test
262 public void failSnapshotUninitialized() {
263 try (final ReadOptions readOptions =
264 setupUninitializedReadOptions(exception)) {
265 readOptions.snapshot();
266 }
267 }
268
269 @Test
270 public void failSetIterateUpperBoundUninitialized() {
271 try (final ReadOptions readOptions =
272 setupUninitializedReadOptions(exception)) {
273 readOptions.setIterateUpperBound(null);
274 }
275 }
276
277 @Test
278 public void failIterateUpperBoundUninitialized() {
279 try (final ReadOptions readOptions =
280 setupUninitializedReadOptions(exception)) {
281 readOptions.iterateUpperBound();
282 }
283 }
284
285 @Test
286 public void failSetIterateLowerBoundUninitialized() {
287 try (final ReadOptions readOptions =
288 setupUninitializedReadOptions(exception)) {
289 readOptions.setIterateLowerBound(null);
290 }
291 }
292
293 @Test
294 public void failIterateLowerBoundUninitialized() {
295 try (final ReadOptions readOptions =
296 setupUninitializedReadOptions(exception)) {
297 readOptions.iterateLowerBound();
298 }
299 }
300
301 private ReadOptions setupUninitializedReadOptions(
302 ExpectedException exception) {
303 final ReadOptions readOptions = new ReadOptions();
304 readOptions.close();
305 exception.expect(AssertionError.class);
306 return readOptions;
307 }
308
309 private Slice buildRandomSlice() {
310 final Random rand = new Random();
311 byte[] sliceBytes = new byte[rand.nextInt(100) + 1];
312 rand.nextBytes(sliceBytes);
313 return new Slice(sliceBytes);
314 }
315
316 private static class AllTablesFilter extends AbstractTableFilter {
317 @Override
318 public boolean filter(final TableProperties tableProperties) {
319 return true;
320 }
321 }
322 }