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 java
.nio
.file
.Paths
;
11 import org
.junit
.ClassRule
;
12 import org
.junit
.Test
;
13 import org
.rocksdb
.test
.RemoveEmptyValueCompactionFilterFactory
;
15 import static org
.assertj
.core
.api
.Assertions
.assertThat
;
18 public class OptionsTest
{
21 public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE
=
22 new RocksNativeLibraryResource();
24 public static final Random rand
= PlatformRandomHelper
.
25 getPlatformSpecificRandomFactory();
28 public void copyConstructor() {
29 Options origOpts
= new Options();
30 origOpts
.setNumLevels(rand
.nextInt(8));
31 origOpts
.setTargetFileSizeMultiplier(rand
.nextInt(100));
32 origOpts
.setLevel0StopWritesTrigger(rand
.nextInt(50));
33 Options copyOpts
= new Options(origOpts
);
34 assertThat(origOpts
.numLevels()).isEqualTo(copyOpts
.numLevels());
35 assertThat(origOpts
.targetFileSizeMultiplier()).isEqualTo(copyOpts
.targetFileSizeMultiplier());
36 assertThat(origOpts
.level0StopWritesTrigger()).isEqualTo(copyOpts
.level0StopWritesTrigger());
40 public void setIncreaseParallelism() {
41 try (final Options opt
= new Options()) {
42 final int threads
= Runtime
.getRuntime().availableProcessors() * 2;
43 opt
.setIncreaseParallelism(threads
);
48 public void writeBufferSize() throws RocksDBException
{
49 try (final Options opt
= new Options()) {
50 final long longValue
= rand
.nextLong();
51 opt
.setWriteBufferSize(longValue
);
52 assertThat(opt
.writeBufferSize()).isEqualTo(longValue
);
57 public void maxWriteBufferNumber() {
58 try (final Options opt
= new Options()) {
59 final int intValue
= rand
.nextInt();
60 opt
.setMaxWriteBufferNumber(intValue
);
61 assertThat(opt
.maxWriteBufferNumber()).isEqualTo(intValue
);
66 public void minWriteBufferNumberToMerge() {
67 try (final Options opt
= new Options()) {
68 final int intValue
= rand
.nextInt();
69 opt
.setMinWriteBufferNumberToMerge(intValue
);
70 assertThat(opt
.minWriteBufferNumberToMerge()).isEqualTo(intValue
);
75 public void numLevels() {
76 try (final Options opt
= new Options()) {
77 final int intValue
= rand
.nextInt();
78 opt
.setNumLevels(intValue
);
79 assertThat(opt
.numLevels()).isEqualTo(intValue
);
84 public void levelZeroFileNumCompactionTrigger() {
85 try (final Options opt
= new Options()) {
86 final int intValue
= rand
.nextInt();
87 opt
.setLevelZeroFileNumCompactionTrigger(intValue
);
88 assertThat(opt
.levelZeroFileNumCompactionTrigger()).isEqualTo(intValue
);
93 public void levelZeroSlowdownWritesTrigger() {
94 try (final Options opt
= new Options()) {
95 final int intValue
= rand
.nextInt();
96 opt
.setLevelZeroSlowdownWritesTrigger(intValue
);
97 assertThat(opt
.levelZeroSlowdownWritesTrigger()).isEqualTo(intValue
);
102 public void levelZeroStopWritesTrigger() {
103 try (final Options opt
= new Options()) {
104 final int intValue
= rand
.nextInt();
105 opt
.setLevelZeroStopWritesTrigger(intValue
);
106 assertThat(opt
.levelZeroStopWritesTrigger()).isEqualTo(intValue
);
111 public void targetFileSizeBase() {
112 try (final Options opt
= new Options()) {
113 final long longValue
= rand
.nextLong();
114 opt
.setTargetFileSizeBase(longValue
);
115 assertThat(opt
.targetFileSizeBase()).isEqualTo(longValue
);
120 public void targetFileSizeMultiplier() {
121 try (final Options opt
= new Options()) {
122 final int intValue
= rand
.nextInt();
123 opt
.setTargetFileSizeMultiplier(intValue
);
124 assertThat(opt
.targetFileSizeMultiplier()).isEqualTo(intValue
);
129 public void maxBytesForLevelBase() {
130 try (final Options opt
= new Options()) {
131 final long longValue
= rand
.nextLong();
132 opt
.setMaxBytesForLevelBase(longValue
);
133 assertThat(opt
.maxBytesForLevelBase()).isEqualTo(longValue
);
138 public void levelCompactionDynamicLevelBytes() {
139 try (final Options opt
= new Options()) {
140 final boolean boolValue
= rand
.nextBoolean();
141 opt
.setLevelCompactionDynamicLevelBytes(boolValue
);
142 assertThat(opt
.levelCompactionDynamicLevelBytes())
143 .isEqualTo(boolValue
);
148 public void maxBytesForLevelMultiplier() {
149 try (final Options opt
= new Options()) {
150 final double doubleValue
= rand
.nextDouble();
151 opt
.setMaxBytesForLevelMultiplier(doubleValue
);
152 assertThat(opt
.maxBytesForLevelMultiplier()).isEqualTo(doubleValue
);
157 public void maxBytesForLevelMultiplierAdditional() {
158 try (final Options opt
= new Options()) {
159 final int intValue1
= rand
.nextInt();
160 final int intValue2
= rand
.nextInt();
161 final int[] ints
= new int[]{intValue1
, intValue2
};
162 opt
.setMaxBytesForLevelMultiplierAdditional(ints
);
163 assertThat(opt
.maxBytesForLevelMultiplierAdditional()).isEqualTo(ints
);
168 public void maxCompactionBytes() {
169 try (final Options opt
= new Options()) {
170 final long longValue
= rand
.nextLong();
171 opt
.setMaxCompactionBytes(longValue
);
172 assertThat(opt
.maxCompactionBytes()).isEqualTo(longValue
);
177 public void softPendingCompactionBytesLimit() {
178 try (final Options opt
= new Options()) {
179 final long longValue
= rand
.nextLong();
180 opt
.setSoftPendingCompactionBytesLimit(longValue
);
181 assertThat(opt
.softPendingCompactionBytesLimit()).isEqualTo(longValue
);
186 public void hardPendingCompactionBytesLimit() {
187 try (final Options opt
= new Options()) {
188 final long longValue
= rand
.nextLong();
189 opt
.setHardPendingCompactionBytesLimit(longValue
);
190 assertThat(opt
.hardPendingCompactionBytesLimit()).isEqualTo(longValue
);
195 public void level0FileNumCompactionTrigger() {
196 try (final Options opt
= new Options()) {
197 final int intValue
= rand
.nextInt();
198 opt
.setLevel0FileNumCompactionTrigger(intValue
);
199 assertThat(opt
.level0FileNumCompactionTrigger()).isEqualTo(intValue
);
204 public void level0SlowdownWritesTrigger() {
205 try (final Options opt
= new Options()) {
206 final int intValue
= rand
.nextInt();
207 opt
.setLevel0SlowdownWritesTrigger(intValue
);
208 assertThat(opt
.level0SlowdownWritesTrigger()).isEqualTo(intValue
);
213 public void level0StopWritesTrigger() {
214 try (final Options opt
= new Options()) {
215 final int intValue
= rand
.nextInt();
216 opt
.setLevel0StopWritesTrigger(intValue
);
217 assertThat(opt
.level0StopWritesTrigger()).isEqualTo(intValue
);
222 public void arenaBlockSize() throws RocksDBException
{
223 try (final Options opt
= new Options()) {
224 final long longValue
= rand
.nextLong();
225 opt
.setArenaBlockSize(longValue
);
226 assertThat(opt
.arenaBlockSize()).isEqualTo(longValue
);
231 public void disableAutoCompactions() {
232 try (final Options opt
= new Options()) {
233 final boolean boolValue
= rand
.nextBoolean();
234 opt
.setDisableAutoCompactions(boolValue
);
235 assertThat(opt
.disableAutoCompactions()).isEqualTo(boolValue
);
240 public void maxSequentialSkipInIterations() {
241 try (final Options opt
= new Options()) {
242 final long longValue
= rand
.nextLong();
243 opt
.setMaxSequentialSkipInIterations(longValue
);
244 assertThat(opt
.maxSequentialSkipInIterations()).isEqualTo(longValue
);
249 public void inplaceUpdateSupport() {
250 try (final Options opt
= new Options()) {
251 final boolean boolValue
= rand
.nextBoolean();
252 opt
.setInplaceUpdateSupport(boolValue
);
253 assertThat(opt
.inplaceUpdateSupport()).isEqualTo(boolValue
);
258 public void inplaceUpdateNumLocks() throws RocksDBException
{
259 try (final Options opt
= new Options()) {
260 final long longValue
= rand
.nextLong();
261 opt
.setInplaceUpdateNumLocks(longValue
);
262 assertThat(opt
.inplaceUpdateNumLocks()).isEqualTo(longValue
);
267 public void memtablePrefixBloomSizeRatio() {
268 try (final Options opt
= new Options()) {
269 final double doubleValue
= rand
.nextDouble();
270 opt
.setMemtablePrefixBloomSizeRatio(doubleValue
);
271 assertThat(opt
.memtablePrefixBloomSizeRatio()).isEqualTo(doubleValue
);
276 public void memtableHugePageSize() {
277 try (final Options opt
= new Options()) {
278 final long longValue
= rand
.nextLong();
279 opt
.setMemtableHugePageSize(longValue
);
280 assertThat(opt
.memtableHugePageSize()).isEqualTo(longValue
);
285 public void bloomLocality() {
286 try (final Options opt
= new Options()) {
287 final int intValue
= rand
.nextInt();
288 opt
.setBloomLocality(intValue
);
289 assertThat(opt
.bloomLocality()).isEqualTo(intValue
);
294 public void maxSuccessiveMerges() throws RocksDBException
{
295 try (final Options opt
= new Options()) {
296 final long longValue
= rand
.nextLong();
297 opt
.setMaxSuccessiveMerges(longValue
);
298 assertThat(opt
.maxSuccessiveMerges()).isEqualTo(longValue
);
303 public void optimizeFiltersForHits() {
304 try (final Options opt
= new Options()) {
305 final boolean aBoolean
= rand
.nextBoolean();
306 opt
.setOptimizeFiltersForHits(aBoolean
);
307 assertThat(opt
.optimizeFiltersForHits()).isEqualTo(aBoolean
);
312 public void createIfMissing() {
313 try (final Options opt
= new Options()) {
314 final boolean boolValue
= rand
.nextBoolean();
315 opt
.setCreateIfMissing(boolValue
);
316 assertThat(opt
.createIfMissing()).
317 isEqualTo(boolValue
);
322 public void createMissingColumnFamilies() {
323 try (final Options opt
= new Options()) {
324 final boolean boolValue
= rand
.nextBoolean();
325 opt
.setCreateMissingColumnFamilies(boolValue
);
326 assertThat(opt
.createMissingColumnFamilies()).
327 isEqualTo(boolValue
);
332 public void errorIfExists() {
333 try (final Options opt
= new Options()) {
334 final boolean boolValue
= rand
.nextBoolean();
335 opt
.setErrorIfExists(boolValue
);
336 assertThat(opt
.errorIfExists()).isEqualTo(boolValue
);
341 public void paranoidChecks() {
342 try (final Options opt
= new Options()) {
343 final boolean boolValue
= rand
.nextBoolean();
344 opt
.setParanoidChecks(boolValue
);
345 assertThat(opt
.paranoidChecks()).
346 isEqualTo(boolValue
);
351 public void maxTotalWalSize() {
352 try (final Options opt
= new Options()) {
353 final long longValue
= rand
.nextLong();
354 opt
.setMaxTotalWalSize(longValue
);
355 assertThat(opt
.maxTotalWalSize()).
356 isEqualTo(longValue
);
361 public void maxOpenFiles() {
362 try (final Options opt
= new Options()) {
363 final int intValue
= rand
.nextInt();
364 opt
.setMaxOpenFiles(intValue
);
365 assertThat(opt
.maxOpenFiles()).isEqualTo(intValue
);
370 public void maxFileOpeningThreads() {
371 try (final Options opt
= new Options()) {
372 final int intValue
= rand
.nextInt();
373 opt
.setMaxFileOpeningThreads(intValue
);
374 assertThat(opt
.maxFileOpeningThreads()).isEqualTo(intValue
);
379 public void useFsync() {
380 try (final Options opt
= new Options()) {
381 final boolean boolValue
= rand
.nextBoolean();
382 opt
.setUseFsync(boolValue
);
383 assertThat(opt
.useFsync()).isEqualTo(boolValue
);
388 public void dbPaths() {
389 final List
<DbPath
> dbPaths
= new ArrayList
<>();
390 dbPaths
.add(new DbPath(Paths
.get("/a"), 10));
391 dbPaths
.add(new DbPath(Paths
.get("/b"), 100));
392 dbPaths
.add(new DbPath(Paths
.get("/c"), 1000));
394 try (final Options opt
= new Options()) {
395 assertThat(opt
.dbPaths()).isEqualTo(Collections
.emptyList());
397 opt
.setDbPaths(dbPaths
);
399 assertThat(opt
.dbPaths()).isEqualTo(dbPaths
);
404 public void dbLogDir() {
405 try (final Options opt
= new Options()) {
406 final String str
= "path/to/DbLogDir";
407 opt
.setDbLogDir(str
);
408 assertThat(opt
.dbLogDir()).isEqualTo(str
);
413 public void walDir() {
414 try (final Options opt
= new Options()) {
415 final String str
= "path/to/WalDir";
417 assertThat(opt
.walDir()).isEqualTo(str
);
422 public void deleteObsoleteFilesPeriodMicros() {
423 try (final Options opt
= new Options()) {
424 final long longValue
= rand
.nextLong();
425 opt
.setDeleteObsoleteFilesPeriodMicros(longValue
);
426 assertThat(opt
.deleteObsoleteFilesPeriodMicros()).
427 isEqualTo(longValue
);
431 @SuppressWarnings("deprecated")
433 public void baseBackgroundCompactions() {
434 try (final Options opt
= new Options()) {
435 final int intValue
= rand
.nextInt();
436 opt
.setBaseBackgroundCompactions(intValue
);
437 assertThat(opt
.baseBackgroundCompactions()).
442 @SuppressWarnings("deprecated")
444 public void maxBackgroundCompactions() {
445 try (final Options opt
= new Options()) {
446 final int intValue
= rand
.nextInt();
447 opt
.setMaxBackgroundCompactions(intValue
);
448 assertThat(opt
.maxBackgroundCompactions()).
454 public void maxSubcompactions() {
455 try (final Options opt
= new Options()) {
456 final int intValue
= rand
.nextInt();
457 opt
.setMaxSubcompactions(intValue
);
458 assertThat(opt
.maxSubcompactions()).
463 @SuppressWarnings("deprecated")
465 public void maxBackgroundFlushes() {
466 try (final Options opt
= new Options()) {
467 final int intValue
= rand
.nextInt();
468 opt
.setMaxBackgroundFlushes(intValue
);
469 assertThat(opt
.maxBackgroundFlushes()).
475 public void maxBackgroundJobs() {
476 try (final Options opt
= new Options()) {
477 final int intValue
= rand
.nextInt();
478 opt
.setMaxBackgroundJobs(intValue
);
479 assertThat(opt
.maxBackgroundJobs()).isEqualTo(intValue
);
484 public void maxLogFileSize() throws RocksDBException
{
485 try (final Options opt
= new Options()) {
486 final long longValue
= rand
.nextLong();
487 opt
.setMaxLogFileSize(longValue
);
488 assertThat(opt
.maxLogFileSize()).isEqualTo(longValue
);
493 public void logFileTimeToRoll() throws RocksDBException
{
494 try (final Options opt
= new Options()) {
495 final long longValue
= rand
.nextLong();
496 opt
.setLogFileTimeToRoll(longValue
);
497 assertThat(opt
.logFileTimeToRoll()).
498 isEqualTo(longValue
);
503 public void keepLogFileNum() throws RocksDBException
{
504 try (final Options opt
= new Options()) {
505 final long longValue
= rand
.nextLong();
506 opt
.setKeepLogFileNum(longValue
);
507 assertThat(opt
.keepLogFileNum()).isEqualTo(longValue
);
512 public void recycleLogFileNum() throws RocksDBException
{
513 try (final Options opt
= new Options()) {
514 final long longValue
= rand
.nextLong();
515 opt
.setRecycleLogFileNum(longValue
);
516 assertThat(opt
.recycleLogFileNum()).isEqualTo(longValue
);
521 public void maxManifestFileSize() {
522 try (final Options opt
= new Options()) {
523 final long longValue
= rand
.nextLong();
524 opt
.setMaxManifestFileSize(longValue
);
525 assertThat(opt
.maxManifestFileSize()).
526 isEqualTo(longValue
);
531 public void tableCacheNumshardbits() {
532 try (final Options opt
= new Options()) {
533 final int intValue
= rand
.nextInt();
534 opt
.setTableCacheNumshardbits(intValue
);
535 assertThat(opt
.tableCacheNumshardbits()).
541 public void walSizeLimitMB() {
542 try (final Options opt
= new Options()) {
543 final long longValue
= rand
.nextLong();
544 opt
.setWalSizeLimitMB(longValue
);
545 assertThat(opt
.walSizeLimitMB()).isEqualTo(longValue
);
550 public void walTtlSeconds() {
551 try (final Options opt
= new Options()) {
552 final long longValue
= rand
.nextLong();
553 opt
.setWalTtlSeconds(longValue
);
554 assertThat(opt
.walTtlSeconds()).isEqualTo(longValue
);
559 public void manifestPreallocationSize() throws RocksDBException
{
560 try (final Options opt
= new Options()) {
561 final long longValue
= rand
.nextLong();
562 opt
.setManifestPreallocationSize(longValue
);
563 assertThat(opt
.manifestPreallocationSize()).
564 isEqualTo(longValue
);
569 public void useDirectReads() {
570 try(final Options opt
= new Options()) {
571 final boolean boolValue
= rand
.nextBoolean();
572 opt
.setUseDirectReads(boolValue
);
573 assertThat(opt
.useDirectReads()).isEqualTo(boolValue
);
578 public void useDirectIoForFlushAndCompaction() {
579 try(final Options opt
= new Options()) {
580 final boolean boolValue
= rand
.nextBoolean();
581 opt
.setUseDirectIoForFlushAndCompaction(boolValue
);
582 assertThat(opt
.useDirectIoForFlushAndCompaction()).isEqualTo(boolValue
);
587 public void allowFAllocate() {
588 try (final Options opt
= new Options()) {
589 final boolean boolValue
= rand
.nextBoolean();
590 opt
.setAllowFAllocate(boolValue
);
591 assertThat(opt
.allowFAllocate()).isEqualTo(boolValue
);
596 public void allowMmapReads() {
597 try (final Options opt
= new Options()) {
598 final boolean boolValue
= rand
.nextBoolean();
599 opt
.setAllowMmapReads(boolValue
);
600 assertThat(opt
.allowMmapReads()).isEqualTo(boolValue
);
605 public void allowMmapWrites() {
606 try (final Options opt
= new Options()) {
607 final boolean boolValue
= rand
.nextBoolean();
608 opt
.setAllowMmapWrites(boolValue
);
609 assertThat(opt
.allowMmapWrites()).isEqualTo(boolValue
);
614 public void isFdCloseOnExec() {
615 try (final Options opt
= new Options()) {
616 final boolean boolValue
= rand
.nextBoolean();
617 opt
.setIsFdCloseOnExec(boolValue
);
618 assertThat(opt
.isFdCloseOnExec()).isEqualTo(boolValue
);
623 public void statsDumpPeriodSec() {
624 try (final Options opt
= new Options()) {
625 final int intValue
= rand
.nextInt();
626 opt
.setStatsDumpPeriodSec(intValue
);
627 assertThat(opt
.statsDumpPeriodSec()).isEqualTo(intValue
);
632 public void statsPersistPeriodSec() {
633 try (final Options opt
= new Options()) {
634 final int intValue
= rand
.nextInt();
635 opt
.setStatsPersistPeriodSec(intValue
);
636 assertThat(opt
.statsPersistPeriodSec()).isEqualTo(intValue
);
641 public void statsHistoryBufferSize() {
642 try (final Options opt
= new Options()) {
643 final long longValue
= rand
.nextLong();
644 opt
.setStatsHistoryBufferSize(longValue
);
645 assertThat(opt
.statsHistoryBufferSize()).isEqualTo(longValue
);
650 public void adviseRandomOnOpen() {
651 try (final Options opt
= new Options()) {
652 final boolean boolValue
= rand
.nextBoolean();
653 opt
.setAdviseRandomOnOpen(boolValue
);
654 assertThat(opt
.adviseRandomOnOpen()).isEqualTo(boolValue
);
659 public void dbWriteBufferSize() {
660 try (final Options opt
= new Options()) {
661 final long longValue
= rand
.nextLong();
662 opt
.setDbWriteBufferSize(longValue
);
663 assertThat(opt
.dbWriteBufferSize()).isEqualTo(longValue
);
668 public void setWriteBufferManager() throws RocksDBException
{
669 try (final Options opt
= new Options();
670 final Cache cache
= new LRUCache(1 * 1024 * 1024);
671 final WriteBufferManager writeBufferManager
= new WriteBufferManager(2000l, cache
)) {
672 opt
.setWriteBufferManager(writeBufferManager
);
673 assertThat(opt
.writeBufferManager()).isEqualTo(writeBufferManager
);
678 public void setWriteBufferManagerWithZeroBufferSize() throws RocksDBException
{
679 try (final Options opt
= new Options();
680 final Cache cache
= new LRUCache(1 * 1024 * 1024);
681 final WriteBufferManager writeBufferManager
= new WriteBufferManager(0l, cache
)) {
682 opt
.setWriteBufferManager(writeBufferManager
);
683 assertThat(opt
.writeBufferManager()).isEqualTo(writeBufferManager
);
688 public void accessHintOnCompactionStart() {
689 try (final Options opt
= new Options()) {
690 final AccessHint accessHint
= AccessHint
.SEQUENTIAL
;
691 opt
.setAccessHintOnCompactionStart(accessHint
);
692 assertThat(opt
.accessHintOnCompactionStart()).isEqualTo(accessHint
);
697 public void newTableReaderForCompactionInputs() {
698 try (final Options opt
= new Options()) {
699 final boolean boolValue
= rand
.nextBoolean();
700 opt
.setNewTableReaderForCompactionInputs(boolValue
);
701 assertThat(opt
.newTableReaderForCompactionInputs()).isEqualTo(boolValue
);
706 public void compactionReadaheadSize() {
707 try (final Options opt
= new Options()) {
708 final long longValue
= rand
.nextLong();
709 opt
.setCompactionReadaheadSize(longValue
);
710 assertThat(opt
.compactionReadaheadSize()).isEqualTo(longValue
);
715 public void randomAccessMaxBufferSize() {
716 try (final Options opt
= new Options()) {
717 final long longValue
= rand
.nextLong();
718 opt
.setRandomAccessMaxBufferSize(longValue
);
719 assertThat(opt
.randomAccessMaxBufferSize()).isEqualTo(longValue
);
724 public void writableFileMaxBufferSize() {
725 try (final Options opt
= new Options()) {
726 final long longValue
= rand
.nextLong();
727 opt
.setWritableFileMaxBufferSize(longValue
);
728 assertThat(opt
.writableFileMaxBufferSize()).isEqualTo(longValue
);
733 public void useAdaptiveMutex() {
734 try (final Options opt
= new Options()) {
735 final boolean boolValue
= rand
.nextBoolean();
736 opt
.setUseAdaptiveMutex(boolValue
);
737 assertThat(opt
.useAdaptiveMutex()).isEqualTo(boolValue
);
742 public void bytesPerSync() {
743 try (final Options opt
= new Options()) {
744 final long longValue
= rand
.nextLong();
745 opt
.setBytesPerSync(longValue
);
746 assertThat(opt
.bytesPerSync()).isEqualTo(longValue
);
751 public void walBytesPerSync() {
752 try (final Options opt
= new Options()) {
753 final long longValue
= rand
.nextLong();
754 opt
.setWalBytesPerSync(longValue
);
755 assertThat(opt
.walBytesPerSync()).isEqualTo(longValue
);
760 public void strictBytesPerSync() {
761 try (final Options opt
= new Options()) {
762 assertThat(opt
.strictBytesPerSync()).isFalse();
763 opt
.setStrictBytesPerSync(true);
764 assertThat(opt
.strictBytesPerSync()).isTrue();
769 public void enableThreadTracking() {
770 try (final Options opt
= new Options()) {
771 final boolean boolValue
= rand
.nextBoolean();
772 opt
.setEnableThreadTracking(boolValue
);
773 assertThat(opt
.enableThreadTracking()).isEqualTo(boolValue
);
778 public void delayedWriteRate() {
779 try (final Options opt
= new Options()) {
780 final long longValue
= rand
.nextLong();
781 opt
.setDelayedWriteRate(longValue
);
782 assertThat(opt
.delayedWriteRate()).isEqualTo(longValue
);
787 public void enablePipelinedWrite() {
788 try(final Options opt
= new Options()) {
789 assertThat(opt
.enablePipelinedWrite()).isFalse();
790 opt
.setEnablePipelinedWrite(true);
791 assertThat(opt
.enablePipelinedWrite()).isTrue();
796 public void unordredWrite() {
797 try(final Options opt
= new Options()) {
798 assertThat(opt
.unorderedWrite()).isFalse();
799 opt
.setUnorderedWrite(true);
800 assertThat(opt
.unorderedWrite()).isTrue();
805 public void allowConcurrentMemtableWrite() {
806 try (final Options opt
= new Options()) {
807 final boolean boolValue
= rand
.nextBoolean();
808 opt
.setAllowConcurrentMemtableWrite(boolValue
);
809 assertThat(opt
.allowConcurrentMemtableWrite()).isEqualTo(boolValue
);
814 public void enableWriteThreadAdaptiveYield() {
815 try (final Options opt
= new Options()) {
816 final boolean boolValue
= rand
.nextBoolean();
817 opt
.setEnableWriteThreadAdaptiveYield(boolValue
);
818 assertThat(opt
.enableWriteThreadAdaptiveYield()).isEqualTo(boolValue
);
823 public void writeThreadMaxYieldUsec() {
824 try (final Options opt
= new Options()) {
825 final long longValue
= rand
.nextLong();
826 opt
.setWriteThreadMaxYieldUsec(longValue
);
827 assertThat(opt
.writeThreadMaxYieldUsec()).isEqualTo(longValue
);
832 public void writeThreadSlowYieldUsec() {
833 try (final Options opt
= new Options()) {
834 final long longValue
= rand
.nextLong();
835 opt
.setWriteThreadSlowYieldUsec(longValue
);
836 assertThat(opt
.writeThreadSlowYieldUsec()).isEqualTo(longValue
);
841 public void skipStatsUpdateOnDbOpen() {
842 try (final Options opt
= new Options()) {
843 final boolean boolValue
= rand
.nextBoolean();
844 opt
.setSkipStatsUpdateOnDbOpen(boolValue
);
845 assertThat(opt
.skipStatsUpdateOnDbOpen()).isEqualTo(boolValue
);
850 public void walRecoveryMode() {
851 try (final Options opt
= new Options()) {
852 for (final WALRecoveryMode walRecoveryMode
: WALRecoveryMode
.values()) {
853 opt
.setWalRecoveryMode(walRecoveryMode
);
854 assertThat(opt
.walRecoveryMode()).isEqualTo(walRecoveryMode
);
860 public void allow2pc() {
861 try (final Options opt
= new Options()) {
862 final boolean boolValue
= rand
.nextBoolean();
863 opt
.setAllow2pc(boolValue
);
864 assertThat(opt
.allow2pc()).isEqualTo(boolValue
);
869 public void rowCache() {
870 try (final Options opt
= new Options()) {
871 assertThat(opt
.rowCache()).isNull();
873 try(final Cache lruCache
= new LRUCache(1000)) {
874 opt
.setRowCache(lruCache
);
875 assertThat(opt
.rowCache()).isEqualTo(lruCache
);
878 try(final Cache clockCache
= new ClockCache(1000)) {
879 opt
.setRowCache(clockCache
);
880 assertThat(opt
.rowCache()).isEqualTo(clockCache
);
886 public void walFilter() {
887 try (final Options opt
= new Options()) {
888 assertThat(opt
.walFilter()).isNull();
890 try (final AbstractWalFilter walFilter
= new AbstractWalFilter() {
892 public void columnFamilyLogNumberMap(
893 final Map
<Integer
, Long
> cfLognumber
,
894 final Map
<String
, Integer
> cfNameId
) {
899 public LogRecordFoundResult
logRecordFound(final long logNumber
,
900 final String logFileName
, final WriteBatch batch
,
901 final WriteBatch newBatch
) {
902 return new LogRecordFoundResult(
903 WalProcessingOption
.CONTINUE_PROCESSING
, false);
907 public String
name() {
908 return "test-wal-filter";
911 opt
.setWalFilter(walFilter
);
912 assertThat(opt
.walFilter()).isEqualTo(walFilter
);
918 public void failIfOptionsFileError() {
919 try (final Options opt
= new Options()) {
920 final boolean boolValue
= rand
.nextBoolean();
921 opt
.setFailIfOptionsFileError(boolValue
);
922 assertThat(opt
.failIfOptionsFileError()).isEqualTo(boolValue
);
927 public void dumpMallocStats() {
928 try (final Options opt
= new Options()) {
929 final boolean boolValue
= rand
.nextBoolean();
930 opt
.setDumpMallocStats(boolValue
);
931 assertThat(opt
.dumpMallocStats()).isEqualTo(boolValue
);
936 public void avoidFlushDuringRecovery() {
937 try (final Options opt
= new Options()) {
938 final boolean boolValue
= rand
.nextBoolean();
939 opt
.setAvoidFlushDuringRecovery(boolValue
);
940 assertThat(opt
.avoidFlushDuringRecovery()).isEqualTo(boolValue
);
945 public void avoidFlushDuringShutdown() {
946 try (final Options opt
= new Options()) {
947 final boolean boolValue
= rand
.nextBoolean();
948 opt
.setAvoidFlushDuringShutdown(boolValue
);
949 assertThat(opt
.avoidFlushDuringShutdown()).isEqualTo(boolValue
);
955 public void allowIngestBehind() {
956 try (final Options opt
= new Options()) {
957 assertThat(opt
.allowIngestBehind()).isFalse();
958 opt
.setAllowIngestBehind(true);
959 assertThat(opt
.allowIngestBehind()).isTrue();
964 public void preserveDeletes() {
965 try (final Options opt
= new Options()) {
966 assertThat(opt
.preserveDeletes()).isFalse();
967 opt
.setPreserveDeletes(true);
968 assertThat(opt
.preserveDeletes()).isTrue();
973 public void twoWriteQueues() {
974 try (final Options opt
= new Options()) {
975 assertThat(opt
.twoWriteQueues()).isFalse();
976 opt
.setTwoWriteQueues(true);
977 assertThat(opt
.twoWriteQueues()).isTrue();
982 public void manualWalFlush() {
983 try (final Options opt
= new Options()) {
984 assertThat(opt
.manualWalFlush()).isFalse();
985 opt
.setManualWalFlush(true);
986 assertThat(opt
.manualWalFlush()).isTrue();
991 public void atomicFlush() {
992 try (final Options opt
= new Options()) {
993 assertThat(opt
.atomicFlush()).isFalse();
994 opt
.setAtomicFlush(true);
995 assertThat(opt
.atomicFlush()).isTrue();
1001 try (final Options options
= new Options();
1002 final Env env
= Env
.getDefault()) {
1003 options
.setEnv(env
);
1004 assertThat(options
.getEnv()).isSameAs(env
);
1009 public void linkageOfPrepMethods() {
1010 try (final Options options
= new Options()) {
1011 options
.optimizeUniversalStyleCompaction();
1012 options
.optimizeUniversalStyleCompaction(4000);
1013 options
.optimizeLevelStyleCompaction();
1014 options
.optimizeLevelStyleCompaction(3000);
1015 options
.optimizeForPointLookup(10);
1016 options
.optimizeForSmallDb();
1017 options
.prepareForBulkLoad();
1022 public void compressionTypes() {
1023 try (final Options options
= new Options()) {
1024 for (final CompressionType compressionType
:
1025 CompressionType
.values()) {
1026 options
.setCompressionType(compressionType
);
1027 assertThat(options
.compressionType()).
1028 isEqualTo(compressionType
);
1029 assertThat(CompressionType
.valueOf("NO_COMPRESSION")).
1030 isEqualTo(CompressionType
.NO_COMPRESSION
);
1036 public void compressionPerLevel() {
1037 try (final Options options
= new Options()) {
1038 assertThat(options
.compressionPerLevel()).isEmpty();
1039 List
<CompressionType
> compressionTypeList
=
1041 for (int i
= 0; i
< options
.numLevels(); i
++) {
1042 compressionTypeList
.add(CompressionType
.NO_COMPRESSION
);
1044 options
.setCompressionPerLevel(compressionTypeList
);
1045 compressionTypeList
= options
.compressionPerLevel();
1046 for (final CompressionType compressionType
: compressionTypeList
) {
1047 assertThat(compressionType
).isEqualTo(
1048 CompressionType
.NO_COMPRESSION
);
1054 public void differentCompressionsPerLevel() {
1055 try (final Options options
= new Options()) {
1056 options
.setNumLevels(3);
1058 assertThat(options
.compressionPerLevel()).isEmpty();
1059 List
<CompressionType
> compressionTypeList
= new ArrayList
<>();
1061 compressionTypeList
.add(CompressionType
.BZLIB2_COMPRESSION
);
1062 compressionTypeList
.add(CompressionType
.SNAPPY_COMPRESSION
);
1063 compressionTypeList
.add(CompressionType
.LZ4_COMPRESSION
);
1065 options
.setCompressionPerLevel(compressionTypeList
);
1066 compressionTypeList
= options
.compressionPerLevel();
1068 assertThat(compressionTypeList
.size()).isEqualTo(3);
1069 assertThat(compressionTypeList
).
1071 CompressionType
.BZLIB2_COMPRESSION
,
1072 CompressionType
.SNAPPY_COMPRESSION
,
1073 CompressionType
.LZ4_COMPRESSION
);
1079 public void bottommostCompressionType() {
1080 try (final Options options
= new Options()) {
1081 assertThat(options
.bottommostCompressionType())
1082 .isEqualTo(CompressionType
.DISABLE_COMPRESSION_OPTION
);
1084 for (final CompressionType compressionType
: CompressionType
.values()) {
1085 options
.setBottommostCompressionType(compressionType
);
1086 assertThat(options
.bottommostCompressionType())
1087 .isEqualTo(compressionType
);
1093 public void bottommostCompressionOptions() {
1094 try (final Options options
= new Options();
1095 final CompressionOptions bottommostCompressionOptions
= new CompressionOptions()
1096 .setMaxDictBytes(123)) {
1098 options
.setBottommostCompressionOptions(bottommostCompressionOptions
);
1099 assertThat(options
.bottommostCompressionOptions())
1100 .isEqualTo(bottommostCompressionOptions
);
1101 assertThat(options
.bottommostCompressionOptions().maxDictBytes())
1107 public void compressionOptions() {
1108 try (final Options options
= new Options();
1109 final CompressionOptions compressionOptions
= new CompressionOptions()
1110 .setMaxDictBytes(123)) {
1112 options
.setCompressionOptions(compressionOptions
);
1113 assertThat(options
.compressionOptions())
1114 .isEqualTo(compressionOptions
);
1115 assertThat(options
.compressionOptions().maxDictBytes())
1121 public void compactionStyles() {
1122 try (final Options options
= new Options()) {
1123 for (final CompactionStyle compactionStyle
:
1124 CompactionStyle
.values()) {
1125 options
.setCompactionStyle(compactionStyle
);
1126 assertThat(options
.compactionStyle()).
1127 isEqualTo(compactionStyle
);
1128 assertThat(CompactionStyle
.valueOf("FIFO")).
1129 isEqualTo(CompactionStyle
.FIFO
);
1135 public void maxTableFilesSizeFIFO() {
1136 try (final Options opt
= new Options()) {
1137 long longValue
= rand
.nextLong();
1138 // Size has to be positive
1139 longValue
= (longValue
< 0) ?
-longValue
: longValue
;
1140 longValue
= (longValue
== 0) ? longValue
+ 1 : longValue
;
1141 opt
.setMaxTableFilesSizeFIFO(longValue
);
1142 assertThat(opt
.maxTableFilesSizeFIFO()).
1143 isEqualTo(longValue
);
1148 public void rateLimiter() {
1149 try (final Options options
= new Options();
1150 final Options anotherOptions
= new Options();
1151 final RateLimiter rateLimiter
=
1152 new RateLimiter(1000, 100 * 1000, 1)) {
1153 options
.setRateLimiter(rateLimiter
);
1154 // Test with parameter initialization
1155 anotherOptions
.setRateLimiter(
1156 new RateLimiter(1000));
1161 public void sstFileManager() throws RocksDBException
{
1162 try (final Options options
= new Options();
1163 final SstFileManager sstFileManager
=
1164 new SstFileManager(Env
.getDefault())) {
1165 options
.setSstFileManager(sstFileManager
);
1170 public void shouldSetTestPrefixExtractor() {
1171 try (final Options options
= new Options()) {
1172 options
.useFixedLengthPrefixExtractor(100);
1173 options
.useFixedLengthPrefixExtractor(10);
1178 public void shouldSetTestCappedPrefixExtractor() {
1179 try (final Options options
= new Options()) {
1180 options
.useCappedPrefixExtractor(100);
1181 options
.useCappedPrefixExtractor(10);
1186 public void shouldTestMemTableFactoryName()
1187 throws RocksDBException
{
1188 try (final Options options
= new Options()) {
1189 options
.setMemTableConfig(new VectorMemTableConfig());
1190 assertThat(options
.memTableFactoryName()).
1191 isEqualTo("VectorRepFactory");
1192 options
.setMemTableConfig(
1193 new HashLinkedListMemTableConfig());
1194 assertThat(options
.memTableFactoryName()).
1195 isEqualTo("HashLinkedListRepFactory");
1200 public void statistics() {
1201 try(final Options options
= new Options()) {
1202 final Statistics statistics
= options
.statistics();
1203 assertThat(statistics
).isNull();
1206 try(final Statistics statistics
= new Statistics();
1207 final Options options
= new Options().setStatistics(statistics
);
1208 final Statistics stats
= options
.statistics()) {
1209 assertThat(stats
).isNotNull();
1214 public void maxWriteBufferNumberToMaintain() {
1215 try (final Options options
= new Options()) {
1216 int intValue
= rand
.nextInt();
1217 // Size has to be positive
1218 intValue
= (intValue
< 0) ?
-intValue
: intValue
;
1219 intValue
= (intValue
== 0) ? intValue
+ 1 : intValue
;
1220 options
.setMaxWriteBufferNumberToMaintain(intValue
);
1221 assertThat(options
.maxWriteBufferNumberToMaintain()).
1222 isEqualTo(intValue
);
1227 public void compactionPriorities() {
1228 try (final Options options
= new Options()) {
1229 for (final CompactionPriority compactionPriority
:
1230 CompactionPriority
.values()) {
1231 options
.setCompactionPriority(compactionPriority
);
1232 assertThat(options
.compactionPriority()).
1233 isEqualTo(compactionPriority
);
1239 public void reportBgIoStats() {
1240 try (final Options options
= new Options()) {
1241 final boolean booleanValue
= true;
1242 options
.setReportBgIoStats(booleanValue
);
1243 assertThat(options
.reportBgIoStats()).
1244 isEqualTo(booleanValue
);
1250 try (final Options options
= new Options()) {
1251 options
.setTtl(1000 * 60);
1252 assertThat(options
.ttl()).
1253 isEqualTo(1000 * 60);
1258 public void compactionOptionsUniversal() {
1259 try (final Options options
= new Options();
1260 final CompactionOptionsUniversal optUni
= new CompactionOptionsUniversal()
1261 .setCompressionSizePercent(7)) {
1262 options
.setCompactionOptionsUniversal(optUni
);
1263 assertThat(options
.compactionOptionsUniversal()).
1265 assertThat(options
.compactionOptionsUniversal().compressionSizePercent())
1271 public void compactionOptionsFIFO() {
1272 try (final Options options
= new Options();
1273 final CompactionOptionsFIFO optFifo
= new CompactionOptionsFIFO()
1274 .setMaxTableFilesSize(2000)) {
1275 options
.setCompactionOptionsFIFO(optFifo
);
1276 assertThat(options
.compactionOptionsFIFO()).
1278 assertThat(options
.compactionOptionsFIFO().maxTableFilesSize())
1284 public void forceConsistencyChecks() {
1285 try (final Options options
= new Options()) {
1286 final boolean booleanValue
= true;
1287 options
.setForceConsistencyChecks(booleanValue
);
1288 assertThat(options
.forceConsistencyChecks()).
1289 isEqualTo(booleanValue
);
1294 public void compactionFilter() {
1295 try(final Options options
= new Options();
1296 final RemoveEmptyValueCompactionFilter cf
= new RemoveEmptyValueCompactionFilter()) {
1297 options
.setCompactionFilter(cf
);
1298 assertThat(options
.compactionFilter()).isEqualTo(cf
);
1303 public void compactionFilterFactory() {
1304 try(final Options options
= new Options();
1305 final RemoveEmptyValueCompactionFilterFactory cff
= new RemoveEmptyValueCompactionFilterFactory()) {
1306 options
.setCompactionFilterFactory(cff
);
1307 assertThat(options
.compactionFilterFactory()).isEqualTo(cff
);