]>
Commit | Line | Data |
---|---|---|
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 | |
6 | package org.rocksdb; | |
7 | ||
20effc67 TL |
8 | import static org.assertj.core.api.Assertions.assertThat; |
9 | import static org.junit.Assert.*; | |
10 | ||
11 | import java.io.IOException; | |
12 | import java.nio.file.Files; | |
7c673cae | 13 | import java.nio.file.Paths; |
494da23a | 14 | import java.util.*; |
20effc67 | 15 | import java.util.concurrent.atomic.AtomicBoolean; |
7c673cae FG |
16 | import org.junit.ClassRule; |
17 | import org.junit.Test; | |
494da23a | 18 | import org.rocksdb.test.RemoveEmptyValueCompactionFilterFactory; |
7c673cae | 19 | |
7c673cae FG |
20 | public class OptionsTest { |
21 | ||
22 | @ClassRule | |
f67539c2 TL |
23 | public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE = |
24 | new RocksNativeLibraryResource(); | |
7c673cae FG |
25 | |
26 | public static final Random rand = PlatformRandomHelper. | |
27 | getPlatformSpecificRandomFactory(); | |
28 | ||
11fdf7f2 TL |
29 | @Test |
30 | public void copyConstructor() { | |
31 | Options origOpts = new Options(); | |
32 | origOpts.setNumLevels(rand.nextInt(8)); | |
33 | origOpts.setTargetFileSizeMultiplier(rand.nextInt(100)); | |
34 | origOpts.setLevel0StopWritesTrigger(rand.nextInt(50)); | |
35 | Options copyOpts = new Options(origOpts); | |
36 | assertThat(origOpts.numLevels()).isEqualTo(copyOpts.numLevels()); | |
37 | assertThat(origOpts.targetFileSizeMultiplier()).isEqualTo(copyOpts.targetFileSizeMultiplier()); | |
38 | assertThat(origOpts.level0StopWritesTrigger()).isEqualTo(copyOpts.level0StopWritesTrigger()); | |
39 | } | |
40 | ||
7c673cae FG |
41 | @Test |
42 | public void setIncreaseParallelism() { | |
43 | try (final Options opt = new Options()) { | |
44 | final int threads = Runtime.getRuntime().availableProcessors() * 2; | |
45 | opt.setIncreaseParallelism(threads); | |
46 | } | |
47 | } | |
48 | ||
49 | @Test | |
50 | public void writeBufferSize() throws RocksDBException { | |
51 | try (final Options opt = new Options()) { | |
52 | final long longValue = rand.nextLong(); | |
53 | opt.setWriteBufferSize(longValue); | |
54 | assertThat(opt.writeBufferSize()).isEqualTo(longValue); | |
55 | } | |
56 | } | |
57 | ||
58 | @Test | |
59 | public void maxWriteBufferNumber() { | |
60 | try (final Options opt = new Options()) { | |
61 | final int intValue = rand.nextInt(); | |
62 | opt.setMaxWriteBufferNumber(intValue); | |
63 | assertThat(opt.maxWriteBufferNumber()).isEqualTo(intValue); | |
64 | } | |
65 | } | |
66 | ||
67 | @Test | |
68 | public void minWriteBufferNumberToMerge() { | |
69 | try (final Options opt = new Options()) { | |
70 | final int intValue = rand.nextInt(); | |
71 | opt.setMinWriteBufferNumberToMerge(intValue); | |
72 | assertThat(opt.minWriteBufferNumberToMerge()).isEqualTo(intValue); | |
73 | } | |
74 | } | |
75 | ||
76 | @Test | |
77 | public void numLevels() { | |
78 | try (final Options opt = new Options()) { | |
79 | final int intValue = rand.nextInt(); | |
80 | opt.setNumLevels(intValue); | |
81 | assertThat(opt.numLevels()).isEqualTo(intValue); | |
82 | } | |
83 | } | |
84 | ||
85 | @Test | |
86 | public void levelZeroFileNumCompactionTrigger() { | |
87 | try (final Options opt = new Options()) { | |
88 | final int intValue = rand.nextInt(); | |
89 | opt.setLevelZeroFileNumCompactionTrigger(intValue); | |
90 | assertThat(opt.levelZeroFileNumCompactionTrigger()).isEqualTo(intValue); | |
91 | } | |
92 | } | |
93 | ||
94 | @Test | |
95 | public void levelZeroSlowdownWritesTrigger() { | |
96 | try (final Options opt = new Options()) { | |
97 | final int intValue = rand.nextInt(); | |
98 | opt.setLevelZeroSlowdownWritesTrigger(intValue); | |
99 | assertThat(opt.levelZeroSlowdownWritesTrigger()).isEqualTo(intValue); | |
100 | } | |
101 | } | |
102 | ||
103 | @Test | |
104 | public void levelZeroStopWritesTrigger() { | |
105 | try (final Options opt = new Options()) { | |
106 | final int intValue = rand.nextInt(); | |
107 | opt.setLevelZeroStopWritesTrigger(intValue); | |
108 | assertThat(opt.levelZeroStopWritesTrigger()).isEqualTo(intValue); | |
109 | } | |
110 | } | |
111 | ||
112 | @Test | |
113 | public void targetFileSizeBase() { | |
114 | try (final Options opt = new Options()) { | |
115 | final long longValue = rand.nextLong(); | |
116 | opt.setTargetFileSizeBase(longValue); | |
117 | assertThat(opt.targetFileSizeBase()).isEqualTo(longValue); | |
118 | } | |
119 | } | |
120 | ||
121 | @Test | |
122 | public void targetFileSizeMultiplier() { | |
123 | try (final Options opt = new Options()) { | |
124 | final int intValue = rand.nextInt(); | |
125 | opt.setTargetFileSizeMultiplier(intValue); | |
126 | assertThat(opt.targetFileSizeMultiplier()).isEqualTo(intValue); | |
127 | } | |
128 | } | |
129 | ||
130 | @Test | |
131 | public void maxBytesForLevelBase() { | |
132 | try (final Options opt = new Options()) { | |
133 | final long longValue = rand.nextLong(); | |
134 | opt.setMaxBytesForLevelBase(longValue); | |
135 | assertThat(opt.maxBytesForLevelBase()).isEqualTo(longValue); | |
136 | } | |
137 | } | |
138 | ||
139 | @Test | |
140 | public void levelCompactionDynamicLevelBytes() { | |
141 | try (final Options opt = new Options()) { | |
142 | final boolean boolValue = rand.nextBoolean(); | |
143 | opt.setLevelCompactionDynamicLevelBytes(boolValue); | |
144 | assertThat(opt.levelCompactionDynamicLevelBytes()) | |
145 | .isEqualTo(boolValue); | |
146 | } | |
147 | } | |
148 | ||
149 | @Test | |
150 | public void maxBytesForLevelMultiplier() { | |
151 | try (final Options opt = new Options()) { | |
152 | final double doubleValue = rand.nextDouble(); | |
153 | opt.setMaxBytesForLevelMultiplier(doubleValue); | |
154 | assertThat(opt.maxBytesForLevelMultiplier()).isEqualTo(doubleValue); | |
155 | } | |
156 | } | |
157 | ||
158 | @Test | |
159 | public void maxBytesForLevelMultiplierAdditional() { | |
160 | try (final Options opt = new Options()) { | |
161 | final int intValue1 = rand.nextInt(); | |
162 | final int intValue2 = rand.nextInt(); | |
163 | final int[] ints = new int[]{intValue1, intValue2}; | |
164 | opt.setMaxBytesForLevelMultiplierAdditional(ints); | |
165 | assertThat(opt.maxBytesForLevelMultiplierAdditional()).isEqualTo(ints); | |
166 | } | |
167 | } | |
168 | ||
169 | @Test | |
170 | public void maxCompactionBytes() { | |
171 | try (final Options opt = new Options()) { | |
172 | final long longValue = rand.nextLong(); | |
173 | opt.setMaxCompactionBytes(longValue); | |
174 | assertThat(opt.maxCompactionBytes()).isEqualTo(longValue); | |
175 | } | |
176 | } | |
177 | ||
178 | @Test | |
179 | public void softPendingCompactionBytesLimit() { | |
180 | try (final Options opt = new Options()) { | |
181 | final long longValue = rand.nextLong(); | |
182 | opt.setSoftPendingCompactionBytesLimit(longValue); | |
183 | assertThat(opt.softPendingCompactionBytesLimit()).isEqualTo(longValue); | |
184 | } | |
185 | } | |
186 | ||
187 | @Test | |
188 | public void hardPendingCompactionBytesLimit() { | |
189 | try (final Options opt = new Options()) { | |
190 | final long longValue = rand.nextLong(); | |
191 | opt.setHardPendingCompactionBytesLimit(longValue); | |
192 | assertThat(opt.hardPendingCompactionBytesLimit()).isEqualTo(longValue); | |
193 | } | |
194 | } | |
195 | ||
196 | @Test | |
197 | public void level0FileNumCompactionTrigger() { | |
198 | try (final Options opt = new Options()) { | |
199 | final int intValue = rand.nextInt(); | |
200 | opt.setLevel0FileNumCompactionTrigger(intValue); | |
201 | assertThat(opt.level0FileNumCompactionTrigger()).isEqualTo(intValue); | |
202 | } | |
203 | } | |
204 | ||
205 | @Test | |
206 | public void level0SlowdownWritesTrigger() { | |
207 | try (final Options opt = new Options()) { | |
208 | final int intValue = rand.nextInt(); | |
209 | opt.setLevel0SlowdownWritesTrigger(intValue); | |
210 | assertThat(opt.level0SlowdownWritesTrigger()).isEqualTo(intValue); | |
211 | } | |
212 | } | |
213 | ||
214 | @Test | |
215 | public void level0StopWritesTrigger() { | |
216 | try (final Options opt = new Options()) { | |
217 | final int intValue = rand.nextInt(); | |
218 | opt.setLevel0StopWritesTrigger(intValue); | |
219 | assertThat(opt.level0StopWritesTrigger()).isEqualTo(intValue); | |
220 | } | |
221 | } | |
222 | ||
223 | @Test | |
224 | public void arenaBlockSize() throws RocksDBException { | |
225 | try (final Options opt = new Options()) { | |
226 | final long longValue = rand.nextLong(); | |
227 | opt.setArenaBlockSize(longValue); | |
228 | assertThat(opt.arenaBlockSize()).isEqualTo(longValue); | |
229 | } | |
230 | } | |
231 | ||
232 | @Test | |
233 | public void disableAutoCompactions() { | |
234 | try (final Options opt = new Options()) { | |
235 | final boolean boolValue = rand.nextBoolean(); | |
236 | opt.setDisableAutoCompactions(boolValue); | |
237 | assertThat(opt.disableAutoCompactions()).isEqualTo(boolValue); | |
238 | } | |
239 | } | |
240 | ||
241 | @Test | |
242 | public void maxSequentialSkipInIterations() { | |
243 | try (final Options opt = new Options()) { | |
244 | final long longValue = rand.nextLong(); | |
245 | opt.setMaxSequentialSkipInIterations(longValue); | |
246 | assertThat(opt.maxSequentialSkipInIterations()).isEqualTo(longValue); | |
247 | } | |
248 | } | |
249 | ||
250 | @Test | |
251 | public void inplaceUpdateSupport() { | |
252 | try (final Options opt = new Options()) { | |
253 | final boolean boolValue = rand.nextBoolean(); | |
254 | opt.setInplaceUpdateSupport(boolValue); | |
255 | assertThat(opt.inplaceUpdateSupport()).isEqualTo(boolValue); | |
256 | } | |
257 | } | |
258 | ||
259 | @Test | |
260 | public void inplaceUpdateNumLocks() throws RocksDBException { | |
261 | try (final Options opt = new Options()) { | |
262 | final long longValue = rand.nextLong(); | |
263 | opt.setInplaceUpdateNumLocks(longValue); | |
264 | assertThat(opt.inplaceUpdateNumLocks()).isEqualTo(longValue); | |
265 | } | |
266 | } | |
267 | ||
268 | @Test | |
269 | public void memtablePrefixBloomSizeRatio() { | |
270 | try (final Options opt = new Options()) { | |
271 | final double doubleValue = rand.nextDouble(); | |
272 | opt.setMemtablePrefixBloomSizeRatio(doubleValue); | |
273 | assertThat(opt.memtablePrefixBloomSizeRatio()).isEqualTo(doubleValue); | |
274 | } | |
275 | } | |
276 | ||
1e59de90 TL |
277 | @Test |
278 | public void experimentalMempurgeThreshold() { | |
279 | try (final Options opt = new Options()) { | |
280 | final double doubleValue = rand.nextDouble(); | |
281 | opt.setExperimentalMempurgeThreshold(doubleValue); | |
282 | assertThat(opt.experimentalMempurgeThreshold()).isEqualTo(doubleValue); | |
283 | } | |
284 | } | |
285 | ||
286 | @Test | |
287 | public void memtableWholeKeyFiltering() { | |
288 | try (final Options opt = new Options()) { | |
289 | final boolean booleanValue = rand.nextBoolean(); | |
290 | opt.setMemtableWholeKeyFiltering(booleanValue); | |
291 | assertThat(opt.memtableWholeKeyFiltering()).isEqualTo(booleanValue); | |
292 | } | |
293 | } | |
294 | ||
7c673cae FG |
295 | @Test |
296 | public void memtableHugePageSize() { | |
297 | try (final Options opt = new Options()) { | |
298 | final long longValue = rand.nextLong(); | |
299 | opt.setMemtableHugePageSize(longValue); | |
300 | assertThat(opt.memtableHugePageSize()).isEqualTo(longValue); | |
301 | } | |
302 | } | |
303 | ||
304 | @Test | |
305 | public void bloomLocality() { | |
306 | try (final Options opt = new Options()) { | |
307 | final int intValue = rand.nextInt(); | |
308 | opt.setBloomLocality(intValue); | |
309 | assertThat(opt.bloomLocality()).isEqualTo(intValue); | |
310 | } | |
311 | } | |
312 | ||
313 | @Test | |
314 | public void maxSuccessiveMerges() throws RocksDBException { | |
315 | try (final Options opt = new Options()) { | |
316 | final long longValue = rand.nextLong(); | |
317 | opt.setMaxSuccessiveMerges(longValue); | |
318 | assertThat(opt.maxSuccessiveMerges()).isEqualTo(longValue); | |
319 | } | |
320 | } | |
321 | ||
322 | @Test | |
323 | public void optimizeFiltersForHits() { | |
324 | try (final Options opt = new Options()) { | |
325 | final boolean aBoolean = rand.nextBoolean(); | |
326 | opt.setOptimizeFiltersForHits(aBoolean); | |
327 | assertThat(opt.optimizeFiltersForHits()).isEqualTo(aBoolean); | |
328 | } | |
329 | } | |
330 | ||
331 | @Test | |
332 | public void createIfMissing() { | |
333 | try (final Options opt = new Options()) { | |
334 | final boolean boolValue = rand.nextBoolean(); | |
335 | opt.setCreateIfMissing(boolValue); | |
336 | assertThat(opt.createIfMissing()). | |
337 | isEqualTo(boolValue); | |
338 | } | |
339 | } | |
340 | ||
341 | @Test | |
342 | public void createMissingColumnFamilies() { | |
343 | try (final Options opt = new Options()) { | |
344 | final boolean boolValue = rand.nextBoolean(); | |
345 | opt.setCreateMissingColumnFamilies(boolValue); | |
346 | assertThat(opt.createMissingColumnFamilies()). | |
347 | isEqualTo(boolValue); | |
348 | } | |
349 | } | |
350 | ||
351 | @Test | |
352 | public void errorIfExists() { | |
353 | try (final Options opt = new Options()) { | |
354 | final boolean boolValue = rand.nextBoolean(); | |
355 | opt.setErrorIfExists(boolValue); | |
356 | assertThat(opt.errorIfExists()).isEqualTo(boolValue); | |
357 | } | |
358 | } | |
359 | ||
360 | @Test | |
361 | public void paranoidChecks() { | |
362 | try (final Options opt = new Options()) { | |
363 | final boolean boolValue = rand.nextBoolean(); | |
364 | opt.setParanoidChecks(boolValue); | |
365 | assertThat(opt.paranoidChecks()). | |
366 | isEqualTo(boolValue); | |
367 | } | |
368 | } | |
369 | ||
370 | @Test | |
371 | public void maxTotalWalSize() { | |
372 | try (final Options opt = new Options()) { | |
373 | final long longValue = rand.nextLong(); | |
374 | opt.setMaxTotalWalSize(longValue); | |
375 | assertThat(opt.maxTotalWalSize()). | |
376 | isEqualTo(longValue); | |
377 | } | |
378 | } | |
379 | ||
380 | @Test | |
381 | public void maxOpenFiles() { | |
382 | try (final Options opt = new Options()) { | |
383 | final int intValue = rand.nextInt(); | |
384 | opt.setMaxOpenFiles(intValue); | |
385 | assertThat(opt.maxOpenFiles()).isEqualTo(intValue); | |
386 | } | |
387 | } | |
388 | ||
389 | @Test | |
390 | public void maxFileOpeningThreads() { | |
391 | try (final Options opt = new Options()) { | |
392 | final int intValue = rand.nextInt(); | |
393 | opt.setMaxFileOpeningThreads(intValue); | |
394 | assertThat(opt.maxFileOpeningThreads()).isEqualTo(intValue); | |
395 | } | |
396 | } | |
397 | ||
398 | @Test | |
399 | public void useFsync() { | |
400 | try (final Options opt = new Options()) { | |
401 | final boolean boolValue = rand.nextBoolean(); | |
402 | opt.setUseFsync(boolValue); | |
403 | assertThat(opt.useFsync()).isEqualTo(boolValue); | |
404 | } | |
405 | } | |
406 | ||
407 | @Test | |
408 | public void dbPaths() { | |
409 | final List<DbPath> dbPaths = new ArrayList<>(); | |
410 | dbPaths.add(new DbPath(Paths.get("/a"), 10)); | |
411 | dbPaths.add(new DbPath(Paths.get("/b"), 100)); | |
412 | dbPaths.add(new DbPath(Paths.get("/c"), 1000)); | |
413 | ||
414 | try (final Options opt = new Options()) { | |
415 | assertThat(opt.dbPaths()).isEqualTo(Collections.emptyList()); | |
416 | ||
417 | opt.setDbPaths(dbPaths); | |
418 | ||
419 | assertThat(opt.dbPaths()).isEqualTo(dbPaths); | |
420 | } | |
421 | } | |
422 | ||
423 | @Test | |
424 | public void dbLogDir() { | |
425 | try (final Options opt = new Options()) { | |
426 | final String str = "path/to/DbLogDir"; | |
427 | opt.setDbLogDir(str); | |
428 | assertThat(opt.dbLogDir()).isEqualTo(str); | |
429 | } | |
430 | } | |
431 | ||
432 | @Test | |
433 | public void walDir() { | |
434 | try (final Options opt = new Options()) { | |
435 | final String str = "path/to/WalDir"; | |
436 | opt.setWalDir(str); | |
437 | assertThat(opt.walDir()).isEqualTo(str); | |
438 | } | |
439 | } | |
440 | ||
441 | @Test | |
442 | public void deleteObsoleteFilesPeriodMicros() { | |
443 | try (final Options opt = new Options()) { | |
444 | final long longValue = rand.nextLong(); | |
445 | opt.setDeleteObsoleteFilesPeriodMicros(longValue); | |
446 | assertThat(opt.deleteObsoleteFilesPeriodMicros()). | |
447 | isEqualTo(longValue); | |
448 | } | |
449 | } | |
450 | ||
f67539c2 | 451 | @SuppressWarnings("deprecated") |
7c673cae FG |
452 | @Test |
453 | public void maxBackgroundCompactions() { | |
454 | try (final Options opt = new Options()) { | |
455 | final int intValue = rand.nextInt(); | |
456 | opt.setMaxBackgroundCompactions(intValue); | |
457 | assertThat(opt.maxBackgroundCompactions()). | |
458 | isEqualTo(intValue); | |
459 | } | |
460 | } | |
461 | ||
462 | @Test | |
463 | public void maxSubcompactions() { | |
464 | try (final Options opt = new Options()) { | |
465 | final int intValue = rand.nextInt(); | |
466 | opt.setMaxSubcompactions(intValue); | |
467 | assertThat(opt.maxSubcompactions()). | |
468 | isEqualTo(intValue); | |
469 | } | |
470 | } | |
471 | ||
f67539c2 | 472 | @SuppressWarnings("deprecated") |
7c673cae FG |
473 | @Test |
474 | public void maxBackgroundFlushes() { | |
475 | try (final Options opt = new Options()) { | |
476 | final int intValue = rand.nextInt(); | |
477 | opt.setMaxBackgroundFlushes(intValue); | |
478 | assertThat(opt.maxBackgroundFlushes()). | |
479 | isEqualTo(intValue); | |
480 | } | |
481 | } | |
482 | ||
11fdf7f2 TL |
483 | @Test |
484 | public void maxBackgroundJobs() { | |
485 | try (final Options opt = new Options()) { | |
486 | final int intValue = rand.nextInt(); | |
487 | opt.setMaxBackgroundJobs(intValue); | |
488 | assertThat(opt.maxBackgroundJobs()).isEqualTo(intValue); | |
489 | } | |
490 | } | |
491 | ||
7c673cae FG |
492 | @Test |
493 | public void maxLogFileSize() throws RocksDBException { | |
494 | try (final Options opt = new Options()) { | |
495 | final long longValue = rand.nextLong(); | |
496 | opt.setMaxLogFileSize(longValue); | |
497 | assertThat(opt.maxLogFileSize()).isEqualTo(longValue); | |
498 | } | |
499 | } | |
500 | ||
501 | @Test | |
502 | public void logFileTimeToRoll() throws RocksDBException { | |
503 | try (final Options opt = new Options()) { | |
504 | final long longValue = rand.nextLong(); | |
505 | opt.setLogFileTimeToRoll(longValue); | |
506 | assertThat(opt.logFileTimeToRoll()). | |
507 | isEqualTo(longValue); | |
508 | } | |
509 | } | |
510 | ||
511 | @Test | |
512 | public void keepLogFileNum() throws RocksDBException { | |
513 | try (final Options opt = new Options()) { | |
514 | final long longValue = rand.nextLong(); | |
515 | opt.setKeepLogFileNum(longValue); | |
516 | assertThat(opt.keepLogFileNum()).isEqualTo(longValue); | |
517 | } | |
518 | } | |
519 | ||
520 | @Test | |
521 | public void recycleLogFileNum() throws RocksDBException { | |
522 | try (final Options opt = new Options()) { | |
523 | final long longValue = rand.nextLong(); | |
524 | opt.setRecycleLogFileNum(longValue); | |
525 | assertThat(opt.recycleLogFileNum()).isEqualTo(longValue); | |
526 | } | |
527 | } | |
528 | ||
529 | @Test | |
530 | public void maxManifestFileSize() { | |
531 | try (final Options opt = new Options()) { | |
532 | final long longValue = rand.nextLong(); | |
533 | opt.setMaxManifestFileSize(longValue); | |
534 | assertThat(opt.maxManifestFileSize()). | |
535 | isEqualTo(longValue); | |
536 | } | |
537 | } | |
538 | ||
539 | @Test | |
540 | public void tableCacheNumshardbits() { | |
541 | try (final Options opt = new Options()) { | |
542 | final int intValue = rand.nextInt(); | |
543 | opt.setTableCacheNumshardbits(intValue); | |
544 | assertThat(opt.tableCacheNumshardbits()). | |
545 | isEqualTo(intValue); | |
546 | } | |
547 | } | |
548 | ||
549 | @Test | |
550 | public void walSizeLimitMB() { | |
551 | try (final Options opt = new Options()) { | |
552 | final long longValue = rand.nextLong(); | |
553 | opt.setWalSizeLimitMB(longValue); | |
554 | assertThat(opt.walSizeLimitMB()).isEqualTo(longValue); | |
555 | } | |
556 | } | |
557 | ||
558 | @Test | |
559 | public void walTtlSeconds() { | |
560 | try (final Options opt = new Options()) { | |
561 | final long longValue = rand.nextLong(); | |
562 | opt.setWalTtlSeconds(longValue); | |
563 | assertThat(opt.walTtlSeconds()).isEqualTo(longValue); | |
564 | } | |
565 | } | |
566 | ||
567 | @Test | |
568 | public void manifestPreallocationSize() throws RocksDBException { | |
569 | try (final Options opt = new Options()) { | |
570 | final long longValue = rand.nextLong(); | |
571 | opt.setManifestPreallocationSize(longValue); | |
572 | assertThat(opt.manifestPreallocationSize()). | |
573 | isEqualTo(longValue); | |
574 | } | |
575 | } | |
576 | ||
577 | @Test | |
578 | public void useDirectReads() { | |
579 | try(final Options opt = new Options()) { | |
580 | final boolean boolValue = rand.nextBoolean(); | |
581 | opt.setUseDirectReads(boolValue); | |
582 | assertThat(opt.useDirectReads()).isEqualTo(boolValue); | |
583 | } | |
584 | } | |
585 | ||
586 | @Test | |
587 | public void useDirectIoForFlushAndCompaction() { | |
588 | try(final Options opt = new Options()) { | |
589 | final boolean boolValue = rand.nextBoolean(); | |
590 | opt.setUseDirectIoForFlushAndCompaction(boolValue); | |
591 | assertThat(opt.useDirectIoForFlushAndCompaction()).isEqualTo(boolValue); | |
592 | } | |
593 | } | |
594 | ||
595 | @Test | |
596 | public void allowFAllocate() { | |
597 | try (final Options opt = new Options()) { | |
598 | final boolean boolValue = rand.nextBoolean(); | |
599 | opt.setAllowFAllocate(boolValue); | |
600 | assertThat(opt.allowFAllocate()).isEqualTo(boolValue); | |
601 | } | |
602 | } | |
603 | ||
604 | @Test | |
605 | public void allowMmapReads() { | |
606 | try (final Options opt = new Options()) { | |
607 | final boolean boolValue = rand.nextBoolean(); | |
608 | opt.setAllowMmapReads(boolValue); | |
609 | assertThat(opt.allowMmapReads()).isEqualTo(boolValue); | |
610 | } | |
611 | } | |
612 | ||
613 | @Test | |
614 | public void allowMmapWrites() { | |
615 | try (final Options opt = new Options()) { | |
616 | final boolean boolValue = rand.nextBoolean(); | |
617 | opt.setAllowMmapWrites(boolValue); | |
618 | assertThat(opt.allowMmapWrites()).isEqualTo(boolValue); | |
619 | } | |
620 | } | |
621 | ||
622 | @Test | |
623 | public void isFdCloseOnExec() { | |
624 | try (final Options opt = new Options()) { | |
625 | final boolean boolValue = rand.nextBoolean(); | |
626 | opt.setIsFdCloseOnExec(boolValue); | |
627 | assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue); | |
628 | } | |
629 | } | |
630 | ||
631 | @Test | |
632 | public void statsDumpPeriodSec() { | |
633 | try (final Options opt = new Options()) { | |
634 | final int intValue = rand.nextInt(); | |
635 | opt.setStatsDumpPeriodSec(intValue); | |
636 | assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue); | |
637 | } | |
638 | } | |
639 | ||
f67539c2 TL |
640 | @Test |
641 | public void statsPersistPeriodSec() { | |
642 | try (final Options opt = new Options()) { | |
643 | final int intValue = rand.nextInt(); | |
644 | opt.setStatsPersistPeriodSec(intValue); | |
645 | assertThat(opt.statsPersistPeriodSec()).isEqualTo(intValue); | |
646 | } | |
647 | } | |
648 | ||
649 | @Test | |
650 | public void statsHistoryBufferSize() { | |
651 | try (final Options opt = new Options()) { | |
652 | final long longValue = rand.nextLong(); | |
653 | opt.setStatsHistoryBufferSize(longValue); | |
654 | assertThat(opt.statsHistoryBufferSize()).isEqualTo(longValue); | |
655 | } | |
656 | } | |
657 | ||
7c673cae FG |
658 | @Test |
659 | public void adviseRandomOnOpen() { | |
660 | try (final Options opt = new Options()) { | |
661 | final boolean boolValue = rand.nextBoolean(); | |
662 | opt.setAdviseRandomOnOpen(boolValue); | |
663 | assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue); | |
664 | } | |
665 | } | |
666 | ||
667 | @Test | |
668 | public void dbWriteBufferSize() { | |
669 | try (final Options opt = new Options()) { | |
670 | final long longValue = rand.nextLong(); | |
671 | opt.setDbWriteBufferSize(longValue); | |
672 | assertThat(opt.dbWriteBufferSize()).isEqualTo(longValue); | |
673 | } | |
674 | } | |
675 | ||
494da23a TL |
676 | @Test |
677 | public void setWriteBufferManager() throws RocksDBException { | |
678 | try (final Options opt = new Options(); | |
679 | final Cache cache = new LRUCache(1 * 1024 * 1024); | |
680 | final WriteBufferManager writeBufferManager = new WriteBufferManager(2000l, cache)) { | |
681 | opt.setWriteBufferManager(writeBufferManager); | |
682 | assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); | |
683 | } | |
684 | } | |
685 | ||
686 | @Test | |
687 | public void setWriteBufferManagerWithZeroBufferSize() throws RocksDBException { | |
688 | try (final Options opt = new Options(); | |
689 | final Cache cache = new LRUCache(1 * 1024 * 1024); | |
690 | final WriteBufferManager writeBufferManager = new WriteBufferManager(0l, cache)) { | |
691 | opt.setWriteBufferManager(writeBufferManager); | |
692 | assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); | |
693 | } | |
694 | } | |
695 | ||
7c673cae | 696 | @Test |
1e59de90 TL |
697 | public void setWriteBufferManagerWithAllowStall() throws RocksDBException { |
698 | try (final Options opt = new Options(); final Cache cache = new LRUCache(1 * 1024 * 1024); | |
699 | final WriteBufferManager writeBufferManager = new WriteBufferManager(2000l, cache, true)) { | |
700 | opt.setWriteBufferManager(writeBufferManager); | |
701 | assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); | |
702 | assertThat(opt.writeBufferManager().allowStall()).isEqualTo(true); | |
7c673cae FG |
703 | } |
704 | } | |
705 | ||
706 | @Test | |
1e59de90 | 707 | public void accessHintOnCompactionStart() { |
7c673cae | 708 | try (final Options opt = new Options()) { |
1e59de90 TL |
709 | final AccessHint accessHint = AccessHint.SEQUENTIAL; |
710 | opt.setAccessHintOnCompactionStart(accessHint); | |
711 | assertThat(opt.accessHintOnCompactionStart()).isEqualTo(accessHint); | |
7c673cae FG |
712 | } |
713 | } | |
714 | ||
715 | @Test | |
716 | public void compactionReadaheadSize() { | |
717 | try (final Options opt = new Options()) { | |
718 | final long longValue = rand.nextLong(); | |
719 | opt.setCompactionReadaheadSize(longValue); | |
720 | assertThat(opt.compactionReadaheadSize()).isEqualTo(longValue); | |
721 | } | |
722 | } | |
723 | ||
724 | @Test | |
725 | public void randomAccessMaxBufferSize() { | |
726 | try (final Options opt = new Options()) { | |
727 | final long longValue = rand.nextLong(); | |
728 | opt.setRandomAccessMaxBufferSize(longValue); | |
729 | assertThat(opt.randomAccessMaxBufferSize()).isEqualTo(longValue); | |
730 | } | |
731 | } | |
732 | ||
733 | @Test | |
734 | public void writableFileMaxBufferSize() { | |
735 | try (final Options opt = new Options()) { | |
736 | final long longValue = rand.nextLong(); | |
737 | opt.setWritableFileMaxBufferSize(longValue); | |
738 | assertThat(opt.writableFileMaxBufferSize()).isEqualTo(longValue); | |
739 | } | |
740 | } | |
741 | ||
742 | @Test | |
743 | public void useAdaptiveMutex() { | |
744 | try (final Options opt = new Options()) { | |
745 | final boolean boolValue = rand.nextBoolean(); | |
746 | opt.setUseAdaptiveMutex(boolValue); | |
747 | assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue); | |
748 | } | |
749 | } | |
750 | ||
751 | @Test | |
752 | public void bytesPerSync() { | |
753 | try (final Options opt = new Options()) { | |
754 | final long longValue = rand.nextLong(); | |
755 | opt.setBytesPerSync(longValue); | |
756 | assertThat(opt.bytesPerSync()).isEqualTo(longValue); | |
757 | } | |
758 | } | |
759 | ||
760 | @Test | |
761 | public void walBytesPerSync() { | |
762 | try (final Options opt = new Options()) { | |
763 | final long longValue = rand.nextLong(); | |
764 | opt.setWalBytesPerSync(longValue); | |
765 | assertThat(opt.walBytesPerSync()).isEqualTo(longValue); | |
766 | } | |
767 | } | |
768 | ||
f67539c2 TL |
769 | @Test |
770 | public void strictBytesPerSync() { | |
771 | try (final Options opt = new Options()) { | |
772 | assertThat(opt.strictBytesPerSync()).isFalse(); | |
773 | opt.setStrictBytesPerSync(true); | |
774 | assertThat(opt.strictBytesPerSync()).isTrue(); | |
775 | } | |
776 | } | |
777 | ||
7c673cae FG |
778 | @Test |
779 | public void enableThreadTracking() { | |
780 | try (final Options opt = new Options()) { | |
781 | final boolean boolValue = rand.nextBoolean(); | |
782 | opt.setEnableThreadTracking(boolValue); | |
783 | assertThat(opt.enableThreadTracking()).isEqualTo(boolValue); | |
784 | } | |
785 | } | |
786 | ||
787 | @Test | |
788 | public void delayedWriteRate() { | |
789 | try (final Options opt = new Options()) { | |
790 | final long longValue = rand.nextLong(); | |
791 | opt.setDelayedWriteRate(longValue); | |
792 | assertThat(opt.delayedWriteRate()).isEqualTo(longValue); | |
793 | } | |
794 | } | |
795 | ||
494da23a TL |
796 | @Test |
797 | public void enablePipelinedWrite() { | |
798 | try(final Options opt = new Options()) { | |
799 | assertThat(opt.enablePipelinedWrite()).isFalse(); | |
800 | opt.setEnablePipelinedWrite(true); | |
801 | assertThat(opt.enablePipelinedWrite()).isTrue(); | |
802 | } | |
803 | } | |
804 | ||
f67539c2 TL |
805 | @Test |
806 | public void unordredWrite() { | |
807 | try(final Options opt = new Options()) { | |
808 | assertThat(opt.unorderedWrite()).isFalse(); | |
809 | opt.setUnorderedWrite(true); | |
810 | assertThat(opt.unorderedWrite()).isTrue(); | |
811 | } | |
812 | } | |
813 | ||
7c673cae FG |
814 | @Test |
815 | public void allowConcurrentMemtableWrite() { | |
816 | try (final Options opt = new Options()) { | |
817 | final boolean boolValue = rand.nextBoolean(); | |
818 | opt.setAllowConcurrentMemtableWrite(boolValue); | |
819 | assertThat(opt.allowConcurrentMemtableWrite()).isEqualTo(boolValue); | |
820 | } | |
821 | } | |
822 | ||
823 | @Test | |
824 | public void enableWriteThreadAdaptiveYield() { | |
825 | try (final Options opt = new Options()) { | |
826 | final boolean boolValue = rand.nextBoolean(); | |
827 | opt.setEnableWriteThreadAdaptiveYield(boolValue); | |
828 | assertThat(opt.enableWriteThreadAdaptiveYield()).isEqualTo(boolValue); | |
829 | } | |
830 | } | |
831 | ||
832 | @Test | |
833 | public void writeThreadMaxYieldUsec() { | |
834 | try (final Options opt = new Options()) { | |
835 | final long longValue = rand.nextLong(); | |
836 | opt.setWriteThreadMaxYieldUsec(longValue); | |
837 | assertThat(opt.writeThreadMaxYieldUsec()).isEqualTo(longValue); | |
838 | } | |
839 | } | |
840 | ||
841 | @Test | |
842 | public void writeThreadSlowYieldUsec() { | |
843 | try (final Options opt = new Options()) { | |
844 | final long longValue = rand.nextLong(); | |
845 | opt.setWriteThreadSlowYieldUsec(longValue); | |
846 | assertThat(opt.writeThreadSlowYieldUsec()).isEqualTo(longValue); | |
847 | } | |
848 | } | |
849 | ||
850 | @Test | |
851 | public void skipStatsUpdateOnDbOpen() { | |
852 | try (final Options opt = new Options()) { | |
853 | final boolean boolValue = rand.nextBoolean(); | |
854 | opt.setSkipStatsUpdateOnDbOpen(boolValue); | |
855 | assertThat(opt.skipStatsUpdateOnDbOpen()).isEqualTo(boolValue); | |
856 | } | |
857 | } | |
858 | ||
859 | @Test | |
860 | public void walRecoveryMode() { | |
861 | try (final Options opt = new Options()) { | |
862 | for (final WALRecoveryMode walRecoveryMode : WALRecoveryMode.values()) { | |
863 | opt.setWalRecoveryMode(walRecoveryMode); | |
864 | assertThat(opt.walRecoveryMode()).isEqualTo(walRecoveryMode); | |
865 | } | |
866 | } | |
867 | } | |
868 | ||
869 | @Test | |
870 | public void allow2pc() { | |
871 | try (final Options opt = new Options()) { | |
872 | final boolean boolValue = rand.nextBoolean(); | |
873 | opt.setAllow2pc(boolValue); | |
874 | assertThat(opt.allow2pc()).isEqualTo(boolValue); | |
875 | } | |
876 | } | |
877 | ||
878 | @Test | |
879 | public void rowCache() { | |
880 | try (final Options opt = new Options()) { | |
881 | assertThat(opt.rowCache()).isNull(); | |
882 | ||
883 | try(final Cache lruCache = new LRUCache(1000)) { | |
884 | opt.setRowCache(lruCache); | |
885 | assertThat(opt.rowCache()).isEqualTo(lruCache); | |
886 | } | |
887 | ||
888 | try(final Cache clockCache = new ClockCache(1000)) { | |
889 | opt.setRowCache(clockCache); | |
890 | assertThat(opt.rowCache()).isEqualTo(clockCache); | |
891 | } | |
892 | } | |
893 | } | |
894 | ||
494da23a TL |
895 | @Test |
896 | public void walFilter() { | |
897 | try (final Options opt = new Options()) { | |
898 | assertThat(opt.walFilter()).isNull(); | |
899 | ||
900 | try (final AbstractWalFilter walFilter = new AbstractWalFilter() { | |
901 | @Override | |
902 | public void columnFamilyLogNumberMap( | |
903 | final Map<Integer, Long> cfLognumber, | |
904 | final Map<String, Integer> cfNameId) { | |
905 | // no-op | |
906 | } | |
907 | ||
908 | @Override | |
909 | public LogRecordFoundResult logRecordFound(final long logNumber, | |
910 | final String logFileName, final WriteBatch batch, | |
911 | final WriteBatch newBatch) { | |
912 | return new LogRecordFoundResult( | |
913 | WalProcessingOption.CONTINUE_PROCESSING, false); | |
914 | } | |
915 | ||
916 | @Override | |
917 | public String name() { | |
918 | return "test-wal-filter"; | |
919 | } | |
920 | }) { | |
921 | opt.setWalFilter(walFilter); | |
922 | assertThat(opt.walFilter()).isEqualTo(walFilter); | |
923 | } | |
924 | } | |
925 | } | |
926 | ||
7c673cae FG |
927 | @Test |
928 | public void failIfOptionsFileError() { | |
929 | try (final Options opt = new Options()) { | |
930 | final boolean boolValue = rand.nextBoolean(); | |
931 | opt.setFailIfOptionsFileError(boolValue); | |
932 | assertThat(opt.failIfOptionsFileError()).isEqualTo(boolValue); | |
933 | } | |
934 | } | |
935 | ||
936 | @Test | |
937 | public void dumpMallocStats() { | |
938 | try (final Options opt = new Options()) { | |
939 | final boolean boolValue = rand.nextBoolean(); | |
940 | opt.setDumpMallocStats(boolValue); | |
941 | assertThat(opt.dumpMallocStats()).isEqualTo(boolValue); | |
942 | } | |
943 | } | |
944 | ||
945 | @Test | |
946 | public void avoidFlushDuringRecovery() { | |
947 | try (final Options opt = new Options()) { | |
948 | final boolean boolValue = rand.nextBoolean(); | |
949 | opt.setAvoidFlushDuringRecovery(boolValue); | |
950 | assertThat(opt.avoidFlushDuringRecovery()).isEqualTo(boolValue); | |
951 | } | |
952 | } | |
953 | ||
954 | @Test | |
955 | public void avoidFlushDuringShutdown() { | |
956 | try (final Options opt = new Options()) { | |
957 | final boolean boolValue = rand.nextBoolean(); | |
958 | opt.setAvoidFlushDuringShutdown(boolValue); | |
959 | assertThat(opt.avoidFlushDuringShutdown()).isEqualTo(boolValue); | |
960 | } | |
961 | } | |
962 | ||
494da23a TL |
963 | |
964 | @Test | |
965 | public void allowIngestBehind() { | |
966 | try (final Options opt = new Options()) { | |
967 | assertThat(opt.allowIngestBehind()).isFalse(); | |
968 | opt.setAllowIngestBehind(true); | |
969 | assertThat(opt.allowIngestBehind()).isTrue(); | |
970 | } | |
971 | } | |
972 | ||
494da23a TL |
973 | @Test |
974 | public void twoWriteQueues() { | |
975 | try (final Options opt = new Options()) { | |
976 | assertThat(opt.twoWriteQueues()).isFalse(); | |
977 | opt.setTwoWriteQueues(true); | |
978 | assertThat(opt.twoWriteQueues()).isTrue(); | |
979 | } | |
980 | } | |
981 | ||
982 | @Test | |
983 | public void manualWalFlush() { | |
984 | try (final Options opt = new Options()) { | |
985 | assertThat(opt.manualWalFlush()).isFalse(); | |
986 | opt.setManualWalFlush(true); | |
987 | assertThat(opt.manualWalFlush()).isTrue(); | |
988 | } | |
989 | } | |
990 | ||
991 | @Test | |
992 | public void atomicFlush() { | |
993 | try (final Options opt = new Options()) { | |
994 | assertThat(opt.atomicFlush()).isFalse(); | |
995 | opt.setAtomicFlush(true); | |
996 | assertThat(opt.atomicFlush()).isTrue(); | |
997 | } | |
998 | } | |
999 | ||
7c673cae FG |
1000 | @Test |
1001 | public void env() { | |
1002 | try (final Options options = new Options(); | |
1003 | final Env env = Env.getDefault()) { | |
1004 | options.setEnv(env); | |
1005 | assertThat(options.getEnv()).isSameAs(env); | |
1006 | } | |
1007 | } | |
1008 | ||
1009 | @Test | |
1010 | public void linkageOfPrepMethods() { | |
1011 | try (final Options options = new Options()) { | |
1012 | options.optimizeUniversalStyleCompaction(); | |
1013 | options.optimizeUniversalStyleCompaction(4000); | |
1014 | options.optimizeLevelStyleCompaction(); | |
1015 | options.optimizeLevelStyleCompaction(3000); | |
1016 | options.optimizeForPointLookup(10); | |
1017 | options.optimizeForSmallDb(); | |
1018 | options.prepareForBulkLoad(); | |
1019 | } | |
1020 | } | |
1021 | ||
1022 | @Test | |
1023 | public void compressionTypes() { | |
1024 | try (final Options options = new Options()) { | |
1025 | for (final CompressionType compressionType : | |
1026 | CompressionType.values()) { | |
1027 | options.setCompressionType(compressionType); | |
1028 | assertThat(options.compressionType()). | |
1029 | isEqualTo(compressionType); | |
1030 | assertThat(CompressionType.valueOf("NO_COMPRESSION")). | |
1031 | isEqualTo(CompressionType.NO_COMPRESSION); | |
1032 | } | |
1033 | } | |
1034 | } | |
1035 | ||
1e59de90 TL |
1036 | @Test |
1037 | public void prepopulateBlobCache() { | |
1038 | try (final Options options = new Options()) { | |
1039 | for (final PrepopulateBlobCache prepopulateBlobCache : PrepopulateBlobCache.values()) { | |
1040 | options.setPrepopulateBlobCache(prepopulateBlobCache); | |
1041 | assertThat(options.prepopulateBlobCache()).isEqualTo(prepopulateBlobCache); | |
1042 | assertThat(PrepopulateBlobCache.valueOf("PREPOPULATE_BLOB_DISABLE")) | |
1043 | .isEqualTo(PrepopulateBlobCache.PREPOPULATE_BLOB_DISABLE); | |
1044 | } | |
1045 | } | |
1046 | } | |
1047 | ||
7c673cae FG |
1048 | @Test |
1049 | public void compressionPerLevel() { | |
1050 | try (final Options options = new Options()) { | |
1051 | assertThat(options.compressionPerLevel()).isEmpty(); | |
1052 | List<CompressionType> compressionTypeList = | |
1053 | new ArrayList<>(); | |
1054 | for (int i = 0; i < options.numLevels(); i++) { | |
1055 | compressionTypeList.add(CompressionType.NO_COMPRESSION); | |
1056 | } | |
1057 | options.setCompressionPerLevel(compressionTypeList); | |
1058 | compressionTypeList = options.compressionPerLevel(); | |
1059 | for (final CompressionType compressionType : compressionTypeList) { | |
1060 | assertThat(compressionType).isEqualTo( | |
1061 | CompressionType.NO_COMPRESSION); | |
1062 | } | |
1063 | } | |
1064 | } | |
1065 | ||
1066 | @Test | |
1067 | public void differentCompressionsPerLevel() { | |
1068 | try (final Options options = new Options()) { | |
1069 | options.setNumLevels(3); | |
1070 | ||
1071 | assertThat(options.compressionPerLevel()).isEmpty(); | |
1072 | List<CompressionType> compressionTypeList = new ArrayList<>(); | |
1073 | ||
1074 | compressionTypeList.add(CompressionType.BZLIB2_COMPRESSION); | |
1075 | compressionTypeList.add(CompressionType.SNAPPY_COMPRESSION); | |
1076 | compressionTypeList.add(CompressionType.LZ4_COMPRESSION); | |
1077 | ||
1078 | options.setCompressionPerLevel(compressionTypeList); | |
1079 | compressionTypeList = options.compressionPerLevel(); | |
1080 | ||
1081 | assertThat(compressionTypeList.size()).isEqualTo(3); | |
1082 | assertThat(compressionTypeList). | |
1083 | containsExactly( | |
1084 | CompressionType.BZLIB2_COMPRESSION, | |
1085 | CompressionType.SNAPPY_COMPRESSION, | |
1086 | CompressionType.LZ4_COMPRESSION); | |
1087 | ||
1088 | } | |
1089 | } | |
1090 | ||
1091 | @Test | |
1092 | public void bottommostCompressionType() { | |
1093 | try (final Options options = new Options()) { | |
1094 | assertThat(options.bottommostCompressionType()) | |
1095 | .isEqualTo(CompressionType.DISABLE_COMPRESSION_OPTION); | |
1096 | ||
1097 | for (final CompressionType compressionType : CompressionType.values()) { | |
1098 | options.setBottommostCompressionType(compressionType); | |
1099 | assertThat(options.bottommostCompressionType()) | |
1100 | .isEqualTo(compressionType); | |
1101 | } | |
1102 | } | |
1103 | } | |
1104 | ||
494da23a TL |
1105 | @Test |
1106 | public void bottommostCompressionOptions() { | |
1107 | try (final Options options = new Options(); | |
1108 | final CompressionOptions bottommostCompressionOptions = new CompressionOptions() | |
1109 | .setMaxDictBytes(123)) { | |
1110 | ||
1111 | options.setBottommostCompressionOptions(bottommostCompressionOptions); | |
1112 | assertThat(options.bottommostCompressionOptions()) | |
1113 | .isEqualTo(bottommostCompressionOptions); | |
1114 | assertThat(options.bottommostCompressionOptions().maxDictBytes()) | |
1115 | .isEqualTo(123); | |
1116 | } | |
1117 | } | |
1118 | ||
7c673cae FG |
1119 | @Test |
1120 | public void compressionOptions() { | |
1121 | try (final Options options = new Options(); | |
1122 | final CompressionOptions compressionOptions = new CompressionOptions() | |
1123 | .setMaxDictBytes(123)) { | |
1124 | ||
1125 | options.setCompressionOptions(compressionOptions); | |
1126 | assertThat(options.compressionOptions()) | |
1127 | .isEqualTo(compressionOptions); | |
1128 | assertThat(options.compressionOptions().maxDictBytes()) | |
1129 | .isEqualTo(123); | |
1130 | } | |
1131 | } | |
1132 | ||
1133 | @Test | |
1134 | public void compactionStyles() { | |
1135 | try (final Options options = new Options()) { | |
1136 | for (final CompactionStyle compactionStyle : | |
1137 | CompactionStyle.values()) { | |
1138 | options.setCompactionStyle(compactionStyle); | |
1139 | assertThat(options.compactionStyle()). | |
1140 | isEqualTo(compactionStyle); | |
1141 | assertThat(CompactionStyle.valueOf("FIFO")). | |
1142 | isEqualTo(CompactionStyle.FIFO); | |
1143 | } | |
1144 | } | |
1145 | } | |
1146 | ||
1147 | @Test | |
1148 | public void maxTableFilesSizeFIFO() { | |
1149 | try (final Options opt = new Options()) { | |
1150 | long longValue = rand.nextLong(); | |
1151 | // Size has to be positive | |
1152 | longValue = (longValue < 0) ? -longValue : longValue; | |
1153 | longValue = (longValue == 0) ? longValue + 1 : longValue; | |
1154 | opt.setMaxTableFilesSizeFIFO(longValue); | |
1155 | assertThat(opt.maxTableFilesSizeFIFO()). | |
1156 | isEqualTo(longValue); | |
1157 | } | |
1158 | } | |
1159 | ||
1160 | @Test | |
1161 | public void rateLimiter() { | |
1162 | try (final Options options = new Options(); | |
1163 | final Options anotherOptions = new Options(); | |
1164 | final RateLimiter rateLimiter = | |
1165 | new RateLimiter(1000, 100 * 1000, 1)) { | |
1166 | options.setRateLimiter(rateLimiter); | |
1167 | // Test with parameter initialization | |
1168 | anotherOptions.setRateLimiter( | |
1169 | new RateLimiter(1000)); | |
1170 | } | |
1171 | } | |
1172 | ||
11fdf7f2 TL |
1173 | @Test |
1174 | public void sstFileManager() throws RocksDBException { | |
1175 | try (final Options options = new Options(); | |
1176 | final SstFileManager sstFileManager = | |
1177 | new SstFileManager(Env.getDefault())) { | |
1178 | options.setSstFileManager(sstFileManager); | |
1179 | } | |
1180 | } | |
1181 | ||
7c673cae FG |
1182 | @Test |
1183 | public void shouldSetTestPrefixExtractor() { | |
1184 | try (final Options options = new Options()) { | |
1185 | options.useFixedLengthPrefixExtractor(100); | |
1186 | options.useFixedLengthPrefixExtractor(10); | |
1187 | } | |
1188 | } | |
1189 | ||
1190 | @Test | |
1191 | public void shouldSetTestCappedPrefixExtractor() { | |
1192 | try (final Options options = new Options()) { | |
1193 | options.useCappedPrefixExtractor(100); | |
1194 | options.useCappedPrefixExtractor(10); | |
1195 | } | |
1196 | } | |
1197 | ||
1198 | @Test | |
1199 | public void shouldTestMemTableFactoryName() | |
1200 | throws RocksDBException { | |
1201 | try (final Options options = new Options()) { | |
1202 | options.setMemTableConfig(new VectorMemTableConfig()); | |
1203 | assertThat(options.memTableFactoryName()). | |
1204 | isEqualTo("VectorRepFactory"); | |
1205 | options.setMemTableConfig( | |
1206 | new HashLinkedListMemTableConfig()); | |
1207 | assertThat(options.memTableFactoryName()). | |
1208 | isEqualTo("HashLinkedListRepFactory"); | |
1209 | } | |
1210 | } | |
1211 | ||
1212 | @Test | |
1213 | public void statistics() { | |
11fdf7f2 TL |
1214 | try(final Options options = new Options()) { |
1215 | final Statistics statistics = options.statistics(); | |
1216 | assertThat(statistics).isNull(); | |
1217 | } | |
1218 | ||
1219 | try(final Statistics statistics = new Statistics(); | |
1220 | final Options options = new Options().setStatistics(statistics); | |
1221 | final Statistics stats = options.statistics()) { | |
1222 | assertThat(stats).isNotNull(); | |
7c673cae FG |
1223 | } |
1224 | } | |
1225 | ||
1226 | @Test | |
1227 | public void maxWriteBufferNumberToMaintain() { | |
1228 | try (final Options options = new Options()) { | |
1229 | int intValue = rand.nextInt(); | |
1230 | // Size has to be positive | |
1231 | intValue = (intValue < 0) ? -intValue : intValue; | |
1232 | intValue = (intValue == 0) ? intValue + 1 : intValue; | |
1233 | options.setMaxWriteBufferNumberToMaintain(intValue); | |
1234 | assertThat(options.maxWriteBufferNumberToMaintain()). | |
1235 | isEqualTo(intValue); | |
1236 | } | |
1237 | } | |
1238 | ||
1239 | @Test | |
1240 | public void compactionPriorities() { | |
1241 | try (final Options options = new Options()) { | |
1242 | for (final CompactionPriority compactionPriority : | |
1243 | CompactionPriority.values()) { | |
1244 | options.setCompactionPriority(compactionPriority); | |
1245 | assertThat(options.compactionPriority()). | |
1246 | isEqualTo(compactionPriority); | |
1247 | } | |
1248 | } | |
1249 | } | |
1250 | ||
1251 | @Test | |
1252 | public void reportBgIoStats() { | |
1253 | try (final Options options = new Options()) { | |
1254 | final boolean booleanValue = true; | |
1255 | options.setReportBgIoStats(booleanValue); | |
1256 | assertThat(options.reportBgIoStats()). | |
1257 | isEqualTo(booleanValue); | |
1258 | } | |
1259 | } | |
1260 | ||
494da23a TL |
1261 | @Test |
1262 | public void ttl() { | |
1263 | try (final Options options = new Options()) { | |
1264 | options.setTtl(1000 * 60); | |
1265 | assertThat(options.ttl()). | |
1266 | isEqualTo(1000 * 60); | |
1267 | } | |
1268 | } | |
1269 | ||
1e59de90 TL |
1270 | @Test |
1271 | public void periodicCompactionSeconds() { | |
1272 | try (final Options options = new Options()) { | |
1273 | options.setPeriodicCompactionSeconds(1000 * 60); | |
1274 | assertThat(options.periodicCompactionSeconds()).isEqualTo(1000 * 60); | |
1275 | } | |
1276 | } | |
1277 | ||
7c673cae FG |
1278 | @Test |
1279 | public void compactionOptionsUniversal() { | |
1280 | try (final Options options = new Options(); | |
1281 | final CompactionOptionsUniversal optUni = new CompactionOptionsUniversal() | |
1282 | .setCompressionSizePercent(7)) { | |
1283 | options.setCompactionOptionsUniversal(optUni); | |
1284 | assertThat(options.compactionOptionsUniversal()). | |
1285 | isEqualTo(optUni); | |
1286 | assertThat(options.compactionOptionsUniversal().compressionSizePercent()) | |
1287 | .isEqualTo(7); | |
1288 | } | |
1289 | } | |
1290 | ||
1291 | @Test | |
1292 | public void compactionOptionsFIFO() { | |
1293 | try (final Options options = new Options(); | |
1294 | final CompactionOptionsFIFO optFifo = new CompactionOptionsFIFO() | |
1295 | .setMaxTableFilesSize(2000)) { | |
1296 | options.setCompactionOptionsFIFO(optFifo); | |
1297 | assertThat(options.compactionOptionsFIFO()). | |
1298 | isEqualTo(optFifo); | |
1299 | assertThat(options.compactionOptionsFIFO().maxTableFilesSize()) | |
1300 | .isEqualTo(2000); | |
1301 | } | |
1302 | } | |
1303 | ||
1304 | @Test | |
1305 | public void forceConsistencyChecks() { | |
1306 | try (final Options options = new Options()) { | |
1307 | final boolean booleanValue = true; | |
1308 | options.setForceConsistencyChecks(booleanValue); | |
1309 | assertThat(options.forceConsistencyChecks()). | |
1310 | isEqualTo(booleanValue); | |
1311 | } | |
1312 | } | |
494da23a TL |
1313 | |
1314 | @Test | |
1315 | public void compactionFilter() { | |
1316 | try(final Options options = new Options(); | |
1317 | final RemoveEmptyValueCompactionFilter cf = new RemoveEmptyValueCompactionFilter()) { | |
1318 | options.setCompactionFilter(cf); | |
1319 | assertThat(options.compactionFilter()).isEqualTo(cf); | |
1320 | } | |
1321 | } | |
1322 | ||
1323 | @Test | |
1324 | public void compactionFilterFactory() { | |
1325 | try(final Options options = new Options(); | |
1326 | final RemoveEmptyValueCompactionFilterFactory cff = new RemoveEmptyValueCompactionFilterFactory()) { | |
1327 | options.setCompactionFilterFactory(cff); | |
1328 | assertThat(options.compactionFilterFactory()).isEqualTo(cff); | |
1329 | } | |
1330 | } | |
1331 | ||
20effc67 TL |
1332 | @Test |
1333 | public void compactionThreadLimiter() { | |
1334 | try (final Options options = new Options(); | |
1335 | final ConcurrentTaskLimiter compactionThreadLimiter = | |
1336 | new ConcurrentTaskLimiterImpl("name", 3)) { | |
1337 | options.setCompactionThreadLimiter(compactionThreadLimiter); | |
1338 | assertThat(options.compactionThreadLimiter()).isEqualTo(compactionThreadLimiter); | |
1339 | } | |
1340 | } | |
1341 | ||
1342 | @Test | |
1343 | public void oldDefaults() { | |
1344 | try (final Options options = new Options()) { | |
1345 | options.oldDefaults(4, 6); | |
1346 | assertThat(options.writeBufferSize()).isEqualTo(4 << 20); | |
1347 | assertThat(options.compactionPriority()).isEqualTo(CompactionPriority.ByCompensatedSize); | |
1348 | assertThat(options.targetFileSizeBase()).isEqualTo(2 * 1048576); | |
1349 | assertThat(options.maxBytesForLevelBase()).isEqualTo(10 * 1048576); | |
1350 | assertThat(options.softPendingCompactionBytesLimit()).isEqualTo(0); | |
1351 | assertThat(options.hardPendingCompactionBytesLimit()).isEqualTo(0); | |
1352 | assertThat(options.level0StopWritesTrigger()).isEqualTo(24); | |
1353 | } | |
1354 | } | |
1355 | ||
1356 | @Test | |
1357 | public void optimizeForSmallDbWithCache() { | |
1358 | try (final Options options = new Options(); final Cache cache = new LRUCache(1024)) { | |
1359 | assertThat(options.optimizeForSmallDb(cache)).isEqualTo(options); | |
1360 | } | |
1361 | } | |
1362 | ||
1363 | @Test | |
1364 | public void cfPaths() { | |
1365 | try (final Options options = new Options()) { | |
1366 | final List<DbPath> paths = Arrays.asList( | |
1367 | new DbPath(Paths.get("test1"), 2 << 25), new DbPath(Paths.get("/test2/path"), 2 << 25)); | |
1368 | assertThat(options.cfPaths()).isEqualTo(Collections.emptyList()); | |
1369 | assertThat(options.setCfPaths(paths)).isEqualTo(options); | |
1370 | assertThat(options.cfPaths()).isEqualTo(paths); | |
1371 | } | |
1372 | } | |
1373 | ||
1374 | @Test | |
1375 | public void avoidUnnecessaryBlockingIO() { | |
1376 | try (final Options options = new Options()) { | |
1377 | assertThat(options.avoidUnnecessaryBlockingIO()).isEqualTo(false); | |
1378 | assertThat(options.setAvoidUnnecessaryBlockingIO(true)).isEqualTo(options); | |
1379 | assertThat(options.avoidUnnecessaryBlockingIO()).isEqualTo(true); | |
1380 | } | |
1381 | } | |
1382 | ||
1383 | @Test | |
1384 | public void persistStatsToDisk() { | |
1385 | try (final Options options = new Options()) { | |
1386 | assertThat(options.persistStatsToDisk()).isEqualTo(false); | |
1387 | assertThat(options.setPersistStatsToDisk(true)).isEqualTo(options); | |
1388 | assertThat(options.persistStatsToDisk()).isEqualTo(true); | |
1389 | } | |
1390 | } | |
1391 | ||
1392 | @Test | |
1393 | public void writeDbidToManifest() { | |
1394 | try (final Options options = new Options()) { | |
1395 | assertThat(options.writeDbidToManifest()).isEqualTo(false); | |
1396 | assertThat(options.setWriteDbidToManifest(true)).isEqualTo(options); | |
1397 | assertThat(options.writeDbidToManifest()).isEqualTo(true); | |
1398 | } | |
1399 | } | |
1400 | ||
1401 | @Test | |
1402 | public void logReadaheadSize() { | |
1403 | try (final Options options = new Options()) { | |
1404 | assertThat(options.logReadaheadSize()).isEqualTo(0); | |
1405 | final int size = 1024 * 1024 * 100; | |
1406 | assertThat(options.setLogReadaheadSize(size)).isEqualTo(options); | |
1407 | assertThat(options.logReadaheadSize()).isEqualTo(size); | |
1408 | } | |
1409 | } | |
1410 | ||
1411 | @Test | |
1412 | public void bestEffortsRecovery() { | |
1413 | try (final Options options = new Options()) { | |
1414 | assertThat(options.bestEffortsRecovery()).isEqualTo(false); | |
1415 | assertThat(options.setBestEffortsRecovery(true)).isEqualTo(options); | |
1416 | assertThat(options.bestEffortsRecovery()).isEqualTo(true); | |
1417 | } | |
1418 | } | |
1419 | ||
1420 | @Test | |
1421 | public void maxBgerrorResumeCount() { | |
1422 | try (final Options options = new Options()) { | |
1423 | final int INT_MAX = 2147483647; | |
1424 | assertThat(options.maxBgerrorResumeCount()).isEqualTo(INT_MAX); | |
1425 | assertThat(options.setMaxBgErrorResumeCount(-1)).isEqualTo(options); | |
1426 | assertThat(options.maxBgerrorResumeCount()).isEqualTo(-1); | |
1427 | } | |
1428 | } | |
1429 | ||
1430 | @Test | |
1431 | public void bgerrorResumeRetryInterval() { | |
1432 | try (final Options options = new Options()) { | |
1433 | assertThat(options.bgerrorResumeRetryInterval()).isEqualTo(1000000); | |
1434 | final long newRetryInterval = 24 * 3600 * 1000000L; | |
1435 | assertThat(options.setBgerrorResumeRetryInterval(newRetryInterval)).isEqualTo(options); | |
1436 | assertThat(options.bgerrorResumeRetryInterval()).isEqualTo(newRetryInterval); | |
1437 | } | |
1438 | } | |
1439 | ||
1440 | @Test | |
1441 | public void maxWriteBatchGroupSizeBytes() { | |
1442 | try (final Options options = new Options()) { | |
1443 | assertThat(options.maxWriteBatchGroupSizeBytes()).isEqualTo(1024 * 1024); | |
1444 | final long size = 1024 * 1024 * 1024 * 10L; | |
1445 | assertThat(options.setMaxWriteBatchGroupSizeBytes(size)).isEqualTo(options); | |
1446 | assertThat(options.maxWriteBatchGroupSizeBytes()).isEqualTo(size); | |
1447 | } | |
1448 | } | |
1449 | ||
1450 | @Test | |
1451 | public void skipCheckingSstFileSizesOnDbOpen() { | |
1452 | try (final Options options = new Options()) { | |
1453 | assertThat(options.skipCheckingSstFileSizesOnDbOpen()).isEqualTo(false); | |
1454 | assertThat(options.setSkipCheckingSstFileSizesOnDbOpen(true)).isEqualTo(options); | |
1455 | assertThat(options.skipCheckingSstFileSizesOnDbOpen()).isEqualTo(true); | |
1456 | } | |
1457 | } | |
1458 | ||
1459 | @Test | |
1460 | public void eventListeners() { | |
1461 | final AtomicBoolean wasCalled1 = new AtomicBoolean(); | |
1462 | final AtomicBoolean wasCalled2 = new AtomicBoolean(); | |
1463 | try (final Options options = new Options(); | |
1464 | final AbstractEventListener el1 = | |
1465 | new AbstractEventListener() { | |
1466 | @Override | |
1467 | public void onTableFileDeleted(final TableFileDeletionInfo tableFileDeletionInfo) { | |
1468 | wasCalled1.set(true); | |
1469 | } | |
1470 | }; | |
1471 | final AbstractEventListener el2 = | |
1472 | new AbstractEventListener() { | |
1473 | @Override | |
1474 | public void onMemTableSealed(final MemTableInfo memTableInfo) { | |
1475 | wasCalled2.set(true); | |
1476 | } | |
1477 | }) { | |
1478 | assertThat(options.setListeners(Arrays.asList(el1, el2))).isEqualTo(options); | |
1479 | List<AbstractEventListener> listeners = options.listeners(); | |
1480 | assertEquals(el1, listeners.get(0)); | |
1481 | assertEquals(el2, listeners.get(1)); | |
1482 | options.setListeners(Collections.<AbstractEventListener>emptyList()); | |
1483 | listeners.get(0).onTableFileDeleted(null); | |
1484 | assertTrue(wasCalled1.get()); | |
1485 | listeners.get(1).onMemTableSealed(null); | |
1486 | assertTrue(wasCalled2.get()); | |
1487 | List<AbstractEventListener> listeners2 = options.listeners(); | |
1488 | assertNotNull(listeners2); | |
1489 | assertEquals(0, listeners2.size()); | |
1490 | } | |
1491 | } | |
7c673cae | 1492 | } |