1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 package org.rocksdb;
7 
8 import java.nio.file.Paths;
9 import java.util.*;
10 
11 import org.junit.ClassRule;
12 import org.junit.Test;
13 import org.rocksdb.test.RemoveEmptyValueCompactionFilterFactory;
14 
15 import static org.assertj.core.api.Assertions.assertThat;
16 
17 
18 public class OptionsTest {
19 
20   @ClassRule
21   public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE =
22       new RocksNativeLibraryResource();
23 
24   public static final Random rand = PlatformRandomHelper.
25       getPlatformSpecificRandomFactory();
26 
27   @Test
copyConstructor()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());
37   }
38 
39   @Test
setIncreaseParallelism()40   public void setIncreaseParallelism() {
41     try (final Options opt = new Options()) {
42       final int threads = Runtime.getRuntime().availableProcessors() * 2;
43       opt.setIncreaseParallelism(threads);
44     }
45   }
46 
47   @Test
writeBufferSize()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);
53     }
54   }
55 
56   @Test
maxWriteBufferNumber()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);
62     }
63   }
64 
65   @Test
minWriteBufferNumberToMerge()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);
71     }
72   }
73 
74   @Test
numLevels()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);
80     }
81   }
82 
83   @Test
levelZeroFileNumCompactionTrigger()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);
89     }
90   }
91 
92   @Test
levelZeroSlowdownWritesTrigger()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);
98     }
99   }
100 
101   @Test
levelZeroStopWritesTrigger()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);
107     }
108   }
109 
110   @Test
targetFileSizeBase()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);
116     }
117   }
118 
119   @Test
targetFileSizeMultiplier()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);
125     }
126   }
127 
128   @Test
maxBytesForLevelBase()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);
134     }
135   }
136 
137   @Test
levelCompactionDynamicLevelBytes()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);
144     }
145   }
146 
147   @Test
maxBytesForLevelMultiplier()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);
153     }
154   }
155 
156   @Test
maxBytesForLevelMultiplierAdditional()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);
164     }
165   }
166 
167   @Test
maxCompactionBytes()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);
173     }
174   }
175 
176   @Test
softPendingCompactionBytesLimit()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);
182     }
183   }
184 
185   @Test
hardPendingCompactionBytesLimit()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);
191     }
192   }
193 
194   @Test
level0FileNumCompactionTrigger()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);
200     }
201   }
202 
203   @Test
level0SlowdownWritesTrigger()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);
209     }
210   }
211 
212   @Test
level0StopWritesTrigger()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);
218     }
219   }
220 
221   @Test
arenaBlockSize()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);
227     }
228   }
229 
230   @Test
disableAutoCompactions()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);
236     }
237   }
238 
239   @Test
maxSequentialSkipInIterations()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);
245     }
246   }
247 
248   @Test
inplaceUpdateSupport()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);
254     }
255   }
256 
257   @Test
inplaceUpdateNumLocks()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);
263     }
264   }
265 
266   @Test
memtablePrefixBloomSizeRatio()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);
272     }
273   }
274 
275   @Test
memtableHugePageSize()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);
281     }
282   }
283 
284   @Test
bloomLocality()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);
290     }
291   }
292 
293   @Test
maxSuccessiveMerges()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);
299     }
300   }
301 
302   @Test
optimizeFiltersForHits()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);
308     }
309   }
310 
311   @Test
createIfMissing()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);
318     }
319   }
320 
321   @Test
createMissingColumnFamilies()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);
328     }
329   }
330 
331   @Test
errorIfExists()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);
337     }
338   }
339 
340   @Test
paranoidChecks()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);
347     }
348   }
349 
350   @Test
maxTotalWalSize()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);
357     }
358   }
359 
360   @Test
maxOpenFiles()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);
366     }
367   }
368 
369   @Test
maxFileOpeningThreads()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);
375     }
376   }
377 
378   @Test
useFsync()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);
384     }
385   }
386 
387   @Test
dbPaths()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));
393 
394     try (final Options opt = new Options()) {
395       assertThat(opt.dbPaths()).isEqualTo(Collections.emptyList());
396 
397       opt.setDbPaths(dbPaths);
398 
399       assertThat(opt.dbPaths()).isEqualTo(dbPaths);
400     }
401   }
402 
403   @Test
dbLogDir()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);
409     }
410   }
411 
412   @Test
walDir()413   public void walDir() {
414     try (final Options opt = new Options()) {
415       final String str = "path/to/WalDir";
416       opt.setWalDir(str);
417       assertThat(opt.walDir()).isEqualTo(str);
418     }
419   }
420 
421   @Test
deleteObsoleteFilesPeriodMicros()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);
428     }
429   }
430 
431   @SuppressWarnings("deprecated")
432   @Test
baseBackgroundCompactions()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()).
438           isEqualTo(intValue);
439     }
440   }
441 
442   @SuppressWarnings("deprecated")
443   @Test
maxBackgroundCompactions()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()).
449           isEqualTo(intValue);
450     }
451   }
452 
453   @Test
maxSubcompactions()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()).
459           isEqualTo(intValue);
460     }
461   }
462 
463   @SuppressWarnings("deprecated")
464   @Test
maxBackgroundFlushes()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()).
470           isEqualTo(intValue);
471     }
472   }
473 
474   @Test
maxBackgroundJobs()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);
480     }
481   }
482 
483   @Test
maxLogFileSize()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);
489     }
490   }
491 
492   @Test
logFileTimeToRoll()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);
499     }
500   }
501 
502   @Test
keepLogFileNum()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);
508     }
509   }
510 
511   @Test
recycleLogFileNum()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);
517     }
518   }
519 
520   @Test
maxManifestFileSize()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);
527     }
528   }
529 
530   @Test
tableCacheNumshardbits()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()).
536           isEqualTo(intValue);
537     }
538   }
539 
540   @Test
walSizeLimitMB()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);
546     }
547   }
548 
549   @Test
walTtlSeconds()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);
555     }
556   }
557 
558   @Test
manifestPreallocationSize()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);
565     }
566   }
567 
568   @Test
useDirectReads()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);
574     }
575   }
576 
577   @Test
useDirectIoForFlushAndCompaction()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);
583     }
584   }
585 
586   @Test
allowFAllocate()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);
592     }
593   }
594 
595   @Test
allowMmapReads()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);
601     }
602   }
603 
604   @Test
allowMmapWrites()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);
610     }
611   }
612 
613   @Test
isFdCloseOnExec()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);
619     }
620   }
621 
622   @Test
statsDumpPeriodSec()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);
628     }
629   }
630 
631   @Test
statsPersistPeriodSec()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);
637     }
638   }
639 
640   @Test
statsHistoryBufferSize()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);
646     }
647   }
648 
649   @Test
adviseRandomOnOpen()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);
655     }
656   }
657 
658   @Test
dbWriteBufferSize()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);
664     }
665   }
666 
667   @Test
setWriteBufferManager()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);
674     }
675   }
676 
677   @Test
setWriteBufferManagerWithZeroBufferSize()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);
684     }
685   }
686 
687   @Test
accessHintOnCompactionStart()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);
693     }
694   }
695 
696   @Test
newTableReaderForCompactionInputs()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);
702     }
703   }
704 
705   @Test
compactionReadaheadSize()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);
711     }
712   }
713 
714   @Test
randomAccessMaxBufferSize()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);
720     }
721   }
722 
723   @Test
writableFileMaxBufferSize()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);
729     }
730   }
731 
732   @Test
useAdaptiveMutex()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);
738     }
739   }
740 
741   @Test
bytesPerSync()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);
747     }
748   }
749 
750   @Test
walBytesPerSync()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);
756     }
757   }
758 
759   @Test
strictBytesPerSync()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();
765     }
766   }
767 
768   @Test
enableThreadTracking()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);
774     }
775   }
776 
777   @Test
delayedWriteRate()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);
783     }
784   }
785 
786   @Test
enablePipelinedWrite()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();
792     }
793   }
794 
795   @Test
unordredWrite()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();
801     }
802   }
803 
804   @Test
allowConcurrentMemtableWrite()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);
810     }
811   }
812 
813   @Test
enableWriteThreadAdaptiveYield()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);
819     }
820   }
821 
822   @Test
writeThreadMaxYieldUsec()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);
828     }
829   }
830 
831   @Test
writeThreadSlowYieldUsec()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);
837     }
838   }
839 
840   @Test
skipStatsUpdateOnDbOpen()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);
846     }
847   }
848 
849   @Test
walRecoveryMode()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);
855       }
856     }
857   }
858 
859   @Test
allow2pc()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);
865     }
866   }
867 
868   @Test
rowCache()869   public void rowCache() {
870     try (final Options opt = new Options()) {
871       assertThat(opt.rowCache()).isNull();
872 
873       try(final Cache lruCache = new LRUCache(1000)) {
874         opt.setRowCache(lruCache);
875         assertThat(opt.rowCache()).isEqualTo(lruCache);
876       }
877 
878       try(final Cache clockCache = new ClockCache(1000)) {
879         opt.setRowCache(clockCache);
880         assertThat(opt.rowCache()).isEqualTo(clockCache);
881       }
882     }
883   }
884 
885   @Test
walFilter()886   public void walFilter() {
887     try (final Options opt = new Options()) {
888       assertThat(opt.walFilter()).isNull();
889 
890       try (final AbstractWalFilter walFilter = new AbstractWalFilter() {
891         @Override
892         public void columnFamilyLogNumberMap(
893             final Map<Integer, Long> cfLognumber,
894             final Map<String, Integer> cfNameId) {
895           // no-op
896         }
897 
898         @Override
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);
904         }
905 
906         @Override
907         public String name() {
908           return "test-wal-filter";
909         }
910       }) {
911         opt.setWalFilter(walFilter);
912         assertThat(opt.walFilter()).isEqualTo(walFilter);
913       }
914     }
915   }
916 
917   @Test
failIfOptionsFileError()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);
923     }
924   }
925 
926   @Test
dumpMallocStats()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);
932     }
933   }
934 
935   @Test
avoidFlushDuringRecovery()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);
941     }
942   }
943 
944   @Test
avoidFlushDuringShutdown()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);
950     }
951   }
952 
953 
954   @Test
allowIngestBehind()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();
960     }
961   }
962 
963   @Test
preserveDeletes()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();
969     }
970   }
971 
972   @Test
twoWriteQueues()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();
978     }
979   }
980 
981   @Test
manualWalFlush()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();
987     }
988   }
989 
990   @Test
atomicFlush()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();
996     }
997   }
998 
999   @Test
env()1000   public void env() {
1001     try (final Options options = new Options();
1002          final Env env = Env.getDefault()) {
1003       options.setEnv(env);
1004       assertThat(options.getEnv()).isSameAs(env);
1005     }
1006   }
1007 
1008   @Test
linkageOfPrepMethods()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();
1018     }
1019   }
1020 
1021   @Test
compressionTypes()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);
1031       }
1032     }
1033   }
1034 
1035   @Test
compressionPerLevel()1036   public void compressionPerLevel() {
1037     try (final Options options = new Options()) {
1038       assertThat(options.compressionPerLevel()).isEmpty();
1039       List<CompressionType> compressionTypeList =
1040           new ArrayList<>();
1041       for (int i = 0; i < options.numLevels(); i++) {
1042         compressionTypeList.add(CompressionType.NO_COMPRESSION);
1043       }
1044       options.setCompressionPerLevel(compressionTypeList);
1045       compressionTypeList = options.compressionPerLevel();
1046       for (final CompressionType compressionType : compressionTypeList) {
1047         assertThat(compressionType).isEqualTo(
1048             CompressionType.NO_COMPRESSION);
1049       }
1050     }
1051   }
1052 
1053   @Test
differentCompressionsPerLevel()1054   public void differentCompressionsPerLevel() {
1055     try (final Options options = new Options()) {
1056       options.setNumLevels(3);
1057 
1058       assertThat(options.compressionPerLevel()).isEmpty();
1059       List<CompressionType> compressionTypeList = new ArrayList<>();
1060 
1061       compressionTypeList.add(CompressionType.BZLIB2_COMPRESSION);
1062       compressionTypeList.add(CompressionType.SNAPPY_COMPRESSION);
1063       compressionTypeList.add(CompressionType.LZ4_COMPRESSION);
1064 
1065       options.setCompressionPerLevel(compressionTypeList);
1066       compressionTypeList = options.compressionPerLevel();
1067 
1068       assertThat(compressionTypeList.size()).isEqualTo(3);
1069       assertThat(compressionTypeList).
1070           containsExactly(
1071               CompressionType.BZLIB2_COMPRESSION,
1072               CompressionType.SNAPPY_COMPRESSION,
1073               CompressionType.LZ4_COMPRESSION);
1074 
1075     }
1076   }
1077 
1078   @Test
bottommostCompressionType()1079   public void bottommostCompressionType() {
1080     try (final Options options = new Options()) {
1081       assertThat(options.bottommostCompressionType())
1082           .isEqualTo(CompressionType.DISABLE_COMPRESSION_OPTION);
1083 
1084       for (final CompressionType compressionType : CompressionType.values()) {
1085         options.setBottommostCompressionType(compressionType);
1086         assertThat(options.bottommostCompressionType())
1087             .isEqualTo(compressionType);
1088       }
1089     }
1090   }
1091 
1092   @Test
bottommostCompressionOptions()1093   public void bottommostCompressionOptions() {
1094     try (final Options options = new Options();
1095          final CompressionOptions bottommostCompressionOptions = new CompressionOptions()
1096              .setMaxDictBytes(123)) {
1097 
1098       options.setBottommostCompressionOptions(bottommostCompressionOptions);
1099       assertThat(options.bottommostCompressionOptions())
1100           .isEqualTo(bottommostCompressionOptions);
1101       assertThat(options.bottommostCompressionOptions().maxDictBytes())
1102           .isEqualTo(123);
1103     }
1104   }
1105 
1106   @Test
compressionOptions()1107   public void compressionOptions() {
1108     try (final Options options = new Options();
1109          final CompressionOptions compressionOptions = new CompressionOptions()
1110              .setMaxDictBytes(123)) {
1111 
1112       options.setCompressionOptions(compressionOptions);
1113       assertThat(options.compressionOptions())
1114           .isEqualTo(compressionOptions);
1115       assertThat(options.compressionOptions().maxDictBytes())
1116           .isEqualTo(123);
1117     }
1118   }
1119 
1120   @Test
compactionStyles()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);
1130       }
1131     }
1132   }
1133 
1134   @Test
maxTableFilesSizeFIFO()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);
1144     }
1145   }
1146 
1147   @Test
rateLimiter()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));
1157     }
1158   }
1159 
1160   @Test
sstFileManager()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);
1166     }
1167   }
1168 
1169   @Test
shouldSetTestPrefixExtractor()1170   public void shouldSetTestPrefixExtractor() {
1171     try (final Options options = new Options()) {
1172       options.useFixedLengthPrefixExtractor(100);
1173       options.useFixedLengthPrefixExtractor(10);
1174     }
1175   }
1176 
1177   @Test
shouldSetTestCappedPrefixExtractor()1178   public void shouldSetTestCappedPrefixExtractor() {
1179     try (final Options options = new Options()) {
1180       options.useCappedPrefixExtractor(100);
1181       options.useCappedPrefixExtractor(10);
1182     }
1183   }
1184 
1185   @Test
shouldTestMemTableFactoryName()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");
1196     }
1197   }
1198 
1199   @Test
statistics()1200   public void statistics() {
1201     try(final Options options = new Options()) {
1202       final Statistics statistics = options.statistics();
1203       assertThat(statistics).isNull();
1204     }
1205 
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();
1210     }
1211   }
1212 
1213   @Test
maxWriteBufferNumberToMaintain()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);
1223     }
1224   }
1225 
1226   @Test
compactionPriorities()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);
1234       }
1235     }
1236   }
1237 
1238   @Test
reportBgIoStats()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);
1245     }
1246   }
1247 
1248   @Test
ttl()1249   public void ttl() {
1250     try (final Options options = new Options()) {
1251       options.setTtl(1000 * 60);
1252       assertThat(options.ttl()).
1253           isEqualTo(1000 * 60);
1254     }
1255   }
1256 
1257   @Test
compactionOptionsUniversal()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()).
1264           isEqualTo(optUni);
1265       assertThat(options.compactionOptionsUniversal().compressionSizePercent())
1266           .isEqualTo(7);
1267     }
1268   }
1269 
1270   @Test
compactionOptionsFIFO()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()).
1277           isEqualTo(optFifo);
1278       assertThat(options.compactionOptionsFIFO().maxTableFilesSize())
1279           .isEqualTo(2000);
1280     }
1281   }
1282 
1283   @Test
forceConsistencyChecks()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);
1290     }
1291   }
1292 
1293   @Test
compactionFilter()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);
1299     }
1300   }
1301 
1302   @Test
compactionFilterFactory()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);
1308     }
1309   }
1310 
1311 }
1312