]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/java/src/test/java/org/rocksdb/ReadOptionsTest.java
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / src / test / java / org / rocksdb / ReadOptionsTest.java
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
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).
7c673cae
FG
5
6package org.rocksdb;
7
11fdf7f2 8import java.util.Arrays;
7c673cae
FG
9import java.util.Random;
10
11import org.junit.ClassRule;
12import org.junit.Rule;
13import org.junit.Test;
14import org.junit.rules.ExpectedException;
15
16import static org.assertj.core.api.Assertions.assertThat;
17
18public class ReadOptionsTest {
19
20 @ClassRule
f67539c2
TL
21 public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE =
22 new RocksNativeLibraryResource();
7c673cae
FG
23
24 @Rule
25 public ExpectedException exception = ExpectedException.none();
26
494da23a
TL
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());
1e59de90
TL
42 opt.setTimestamp(buildRandomSlice());
43 opt.setIterStartTs(buildRandomSlice());
494da23a
TL
44 try (final ReadOptions other = new ReadOptions(opt)) {
45 assertThat(opt.verifyChecksums()).isEqualTo(other.verifyChecksums());
46 assertThat(opt.fillCache()).isEqualTo(other.fillCache());
47 assertThat(Arrays.equals(opt.iterateUpperBound().data(), other.iterateUpperBound().data())).isTrue();
48 assertThat(Arrays.equals(opt.iterateLowerBound().data(), other.iterateLowerBound().data())).isTrue();
1e59de90
TL
49 assertThat(Arrays.equals(opt.timestamp().data(), other.timestamp().data())).isTrue();
50 assertThat(Arrays.equals(opt.iterStartTs().data(), other.iterStartTs().data())).isTrue();
494da23a
TL
51 }
52 }
53 }
54
7c673cae
FG
55 @Test
56 public void verifyChecksum() {
57 try (final ReadOptions opt = new ReadOptions()) {
58 final Random rand = new Random();
59 final boolean boolValue = rand.nextBoolean();
60 opt.setVerifyChecksums(boolValue);
61 assertThat(opt.verifyChecksums()).isEqualTo(boolValue);
62 }
63 }
64
65 @Test
66 public void fillCache() {
67 try (final ReadOptions opt = new ReadOptions()) {
68 final Random rand = new Random();
69 final boolean boolValue = rand.nextBoolean();
70 opt.setFillCache(boolValue);
71 assertThat(opt.fillCache()).isEqualTo(boolValue);
72 }
73 }
74
75 @Test
76 public void tailing() {
77 try (final ReadOptions opt = new ReadOptions()) {
78 final Random rand = new Random();
79 final boolean boolValue = rand.nextBoolean();
80 opt.setTailing(boolValue);
81 assertThat(opt.tailing()).isEqualTo(boolValue);
82 }
83 }
84
85 @Test
86 public void snapshot() {
87 try (final ReadOptions opt = new ReadOptions()) {
88 opt.setSnapshot(null);
89 assertThat(opt.snapshot()).isNull();
90 }
91 }
92
93 @Test
94 public void readTier() {
95 try (final ReadOptions opt = new ReadOptions()) {
96 opt.setReadTier(ReadTier.BLOCK_CACHE_TIER);
97 assertThat(opt.readTier()).isEqualTo(ReadTier.BLOCK_CACHE_TIER);
98 }
99 }
100
f67539c2 101 @SuppressWarnings("deprecated")
7c673cae
FG
102 @Test
103 public void managed() {
104 try (final ReadOptions opt = new ReadOptions()) {
105 opt.setManaged(true);
106 assertThat(opt.managed()).isTrue();
107 }
108 }
109
110 @Test
111 public void totalOrderSeek() {
112 try (final ReadOptions opt = new ReadOptions()) {
113 opt.setTotalOrderSeek(true);
114 assertThat(opt.totalOrderSeek()).isTrue();
115 }
116 }
117
118 @Test
119 public void prefixSameAsStart() {
120 try (final ReadOptions opt = new ReadOptions()) {
121 opt.setPrefixSameAsStart(true);
122 assertThat(opt.prefixSameAsStart()).isTrue();
123 }
124 }
125
126 @Test
127 public void pinData() {
128 try (final ReadOptions opt = new ReadOptions()) {
129 opt.setPinData(true);
130 assertThat(opt.pinData()).isTrue();
131 }
132 }
133
134 @Test
135 public void backgroundPurgeOnIteratorCleanup() {
136 try (final ReadOptions opt = new ReadOptions()) {
137 opt.setBackgroundPurgeOnIteratorCleanup(true);
138 assertThat(opt.backgroundPurgeOnIteratorCleanup()).isTrue();
139 }
140 }
141
142 @Test
143 public void readaheadSize() {
144 try (final ReadOptions opt = new ReadOptions()) {
145 final Random rand = new Random();
1e59de90
TL
146 final int intValue = rand.nextInt(2147483647);
147 opt.setReadaheadSize(intValue);
148 assertThat(opt.readaheadSize()).isEqualTo(intValue);
7c673cae
FG
149 }
150 }
151
152 @Test
153 public void ignoreRangeDeletions() {
154 try (final ReadOptions opt = new ReadOptions()) {
155 opt.setIgnoreRangeDeletions(true);
156 assertThat(opt.ignoreRangeDeletions()).isTrue();
157 }
158 }
159
11fdf7f2
TL
160 @Test
161 public void iterateUpperBound() {
162 try (final ReadOptions opt = new ReadOptions()) {
163 Slice upperBound = buildRandomSlice();
164 opt.setIterateUpperBound(upperBound);
165 assertThat(Arrays.equals(upperBound.data(), opt.iterateUpperBound().data())).isTrue();
1e59de90
TL
166 opt.setIterateUpperBound(null);
167 assertThat(opt.iterateUpperBound()).isNull();
11fdf7f2
TL
168 }
169 }
170
171 @Test
172 public void iterateUpperBoundNull() {
173 try (final ReadOptions opt = new ReadOptions()) {
174 assertThat(opt.iterateUpperBound()).isNull();
175 }
176 }
177
178 @Test
494da23a 179 public void iterateLowerBound() {
11fdf7f2 180 try (final ReadOptions opt = new ReadOptions()) {
494da23a
TL
181 Slice lowerBound = buildRandomSlice();
182 opt.setIterateLowerBound(lowerBound);
183 assertThat(Arrays.equals(lowerBound.data(), opt.iterateLowerBound().data())).isTrue();
1e59de90
TL
184 opt.setIterateLowerBound(null);
185 assertThat(opt.iterateLowerBound()).isNull();
494da23a
TL
186 }
187 }
188
189 @Test
190 public void iterateLowerBoundNull() {
191 try (final ReadOptions opt = new ReadOptions()) {
192 assertThat(opt.iterateLowerBound()).isNull();
193 }
194 }
195
196 @Test
197 public void tableFilter() {
198 try (final ReadOptions opt = new ReadOptions();
199 final AbstractTableFilter allTablesFilter = new AllTablesFilter()) {
200 opt.setTableFilter(allTablesFilter);
201 }
202 }
203
204 @Test
1e59de90
TL
205 public void autoPrefixMode() {
206 try (final ReadOptions opt = new ReadOptions()) {
207 opt.setAutoPrefixMode(true);
208 assertThat(opt.autoPrefixMode()).isTrue();
209 }
210 }
211
212 @Test
213 public void timestamp() {
214 try (final ReadOptions opt = new ReadOptions()) {
215 Slice timestamp = buildRandomSlice();
216 opt.setTimestamp(timestamp);
217 assertThat(Arrays.equals(timestamp.data(), opt.timestamp().data())).isTrue();
218 opt.setTimestamp(null);
219 assertThat(opt.timestamp()).isNull();
220 }
221 }
222
223 @Test
224 public void iterStartTs() {
225 try (final ReadOptions opt = new ReadOptions()) {
226 Slice itertStartTsSlice = buildRandomSlice();
227 opt.setIterStartTs(itertStartTsSlice);
228 assertThat(Arrays.equals(itertStartTsSlice.data(), opt.iterStartTs().data())).isTrue();
229 opt.setIterStartTs(null);
230 assertThat(opt.iterStartTs()).isNull();
231 }
232 }
233
234 @Test
235 public void deadline() {
494da23a 236 try (final ReadOptions opt = new ReadOptions()) {
1e59de90
TL
237 opt.setDeadline(1999l);
238 assertThat(opt.deadline()).isEqualTo(1999l);
239 }
240 }
494da23a 241
1e59de90
TL
242 @Test
243 public void ioTimeout() {
244 try (final ReadOptions opt = new ReadOptions()) {
245 opt.setIoTimeout(34555l);
246 assertThat(opt.ioTimeout()).isEqualTo(34555l);
247 }
248 }
249
250 @Test
251 public void valueSizeSoftLimit() {
252 try (final ReadOptions opt = new ReadOptions()) {
253 opt.setValueSizeSoftLimit(12134324l);
254 assertThat(opt.valueSizeSoftLimit()).isEqualTo(12134324l);
11fdf7f2
TL
255 }
256 }
257
7c673cae
FG
258 @Test
259 public void failSetVerifyChecksumUninitialized() {
260 try (final ReadOptions readOptions =
261 setupUninitializedReadOptions(exception)) {
262 readOptions.setVerifyChecksums(true);
263 }
264 }
265
266 @Test
267 public void failVerifyChecksumUninitialized() {
268 try (final ReadOptions readOptions =
269 setupUninitializedReadOptions(exception)) {
270 readOptions.verifyChecksums();
271 }
272 }
273
274 @Test
275 public void failSetFillCacheUninitialized() {
276 try (final ReadOptions readOptions =
277 setupUninitializedReadOptions(exception)) {
278 readOptions.setFillCache(true);
279 }
280 }
281
282 @Test
283 public void failFillCacheUninitialized() {
284 try (final ReadOptions readOptions =
285 setupUninitializedReadOptions(exception)) {
286 readOptions.fillCache();
287 }
288 }
289
290 @Test
291 public void failSetTailingUninitialized() {
292 try (final ReadOptions readOptions =
293 setupUninitializedReadOptions(exception)) {
294 readOptions.setTailing(true);
295 }
296 }
297
298 @Test
299 public void failTailingUninitialized() {
300 try (final ReadOptions readOptions =
301 setupUninitializedReadOptions(exception)) {
302 readOptions.tailing();
303 }
304 }
305
306 @Test
307 public void failSetSnapshotUninitialized() {
308 try (final ReadOptions readOptions =
309 setupUninitializedReadOptions(exception)) {
310 readOptions.setSnapshot(null);
311 }
312 }
313
314 @Test
315 public void failSnapshotUninitialized() {
316 try (final ReadOptions readOptions =
317 setupUninitializedReadOptions(exception)) {
318 readOptions.snapshot();
319 }
320 }
321
11fdf7f2
TL
322 @Test
323 public void failSetIterateUpperBoundUninitialized() {
324 try (final ReadOptions readOptions =
325 setupUninitializedReadOptions(exception)) {
326 readOptions.setIterateUpperBound(null);
327 }
328 }
329
330 @Test
331 public void failIterateUpperBoundUninitialized() {
332 try (final ReadOptions readOptions =
333 setupUninitializedReadOptions(exception)) {
334 readOptions.iterateUpperBound();
335 }
336 }
337
494da23a
TL
338 @Test
339 public void failSetIterateLowerBoundUninitialized() {
340 try (final ReadOptions readOptions =
341 setupUninitializedReadOptions(exception)) {
342 readOptions.setIterateLowerBound(null);
343 }
344 }
345
346 @Test
347 public void failIterateLowerBoundUninitialized() {
348 try (final ReadOptions readOptions =
349 setupUninitializedReadOptions(exception)) {
350 readOptions.iterateLowerBound();
351 }
352 }
353
7c673cae
FG
354 private ReadOptions setupUninitializedReadOptions(
355 ExpectedException exception) {
356 final ReadOptions readOptions = new ReadOptions();
357 readOptions.close();
358 exception.expect(AssertionError.class);
359 return readOptions;
360 }
11fdf7f2
TL
361
362 private Slice buildRandomSlice() {
363 final Random rand = new Random();
364 byte[] sliceBytes = new byte[rand.nextInt(100) + 1];
365 rand.nextBytes(sliceBytes);
366 return new Slice(sliceBytes);
367 }
368
494da23a
TL
369 private static class AllTablesFilter extends AbstractTableFilter {
370 @Override
371 public boolean filter(final TableProperties tableProperties) {
372 return true;
373 }
374 }
7c673cae 375}