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 static org
.assertj
.core
.api
.Assertions
.assertThat
;
9 import static org
.junit
.Assert
.assertEquals
;
10 import static org
.junit
.Assert
.assertNotNull
;
11 import static org
.junit
.Assert
.assertTrue
;
13 import java
.nio
.file
.Paths
;
15 import java
.util
.concurrent
.atomic
.AtomicBoolean
;
16 import org
.junit
.ClassRule
;
17 import org
.junit
.Test
;
19 public class DBOptionsTest
{
22 public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE
=
23 new RocksNativeLibraryResource();
25 public static final Random rand
= PlatformRandomHelper
.
26 getPlatformSpecificRandomFactory();
29 public void copyConstructor() {
30 DBOptions origOpts
= new DBOptions();
31 origOpts
.setCreateIfMissing(rand
.nextBoolean());
32 origOpts
.setAllow2pc(rand
.nextBoolean());
33 origOpts
.setMaxBackgroundJobs(rand
.nextInt(10));
34 DBOptions copyOpts
= new DBOptions(origOpts
);
35 assertThat(origOpts
.createIfMissing()).isEqualTo(copyOpts
.createIfMissing());
36 assertThat(origOpts
.allow2pc()).isEqualTo(copyOpts
.allow2pc());
40 public void getDBOptionsFromProps() {
41 // setup sample properties
42 final Properties properties
= new Properties();
43 properties
.put("allow_mmap_reads", "true");
44 properties
.put("bytes_per_sync", "13");
45 try(final DBOptions opt
= DBOptions
.getDBOptionsFromProps(properties
)) {
46 assertThat(opt
).isNotNull();
47 assertThat(String
.valueOf(opt
.allowMmapReads())).
48 isEqualTo(properties
.get("allow_mmap_reads"));
49 assertThat(String
.valueOf(opt
.bytesPerSync())).
50 isEqualTo(properties
.get("bytes_per_sync"));
55 public void failDBOptionsFromPropsWithIllegalValue() {
56 // setup sample properties
57 final Properties properties
= new Properties();
58 properties
.put("tomato", "1024");
59 properties
.put("burger", "2");
60 try(final DBOptions opt
= DBOptions
.getDBOptionsFromProps(properties
)) {
61 assertThat(opt
).isNull();
65 @Test(expected
= IllegalArgumentException
.class)
66 public void failDBOptionsFromPropsWithNullValue() {
67 try(final DBOptions opt
= DBOptions
.getDBOptionsFromProps(null)) {
72 @Test(expected
= IllegalArgumentException
.class)
73 public void failDBOptionsFromPropsWithEmptyProps() {
74 try(final DBOptions opt
= DBOptions
.getDBOptionsFromProps(
81 public void linkageOfPrepMethods() {
82 try (final DBOptions opt
= new DBOptions()) {
83 opt
.optimizeForSmallDb();
89 try (final DBOptions opt
= new DBOptions();
90 final Env env
= Env
.getDefault()) {
92 assertThat(opt
.getEnv()).isSameAs(env
);
97 public void setIncreaseParallelism() {
98 try(final DBOptions opt
= new DBOptions()) {
99 final int threads
= Runtime
.getRuntime().availableProcessors() * 2;
100 opt
.setIncreaseParallelism(threads
);
105 public void createIfMissing() {
106 try(final DBOptions opt
= new DBOptions()) {
107 final boolean boolValue
= rand
.nextBoolean();
108 opt
.setCreateIfMissing(boolValue
);
109 assertThat(opt
.createIfMissing()).isEqualTo(boolValue
);
114 public void createMissingColumnFamilies() {
115 try(final DBOptions opt
= new DBOptions()) {
116 final boolean boolValue
= rand
.nextBoolean();
117 opt
.setCreateMissingColumnFamilies(boolValue
);
118 assertThat(opt
.createMissingColumnFamilies()).isEqualTo(boolValue
);
123 public void errorIfExists() {
124 try(final DBOptions opt
= new DBOptions()) {
125 final boolean boolValue
= rand
.nextBoolean();
126 opt
.setErrorIfExists(boolValue
);
127 assertThat(opt
.errorIfExists()).isEqualTo(boolValue
);
132 public void paranoidChecks() {
133 try(final DBOptions opt
= new DBOptions()) {
134 final boolean boolValue
= rand
.nextBoolean();
135 opt
.setParanoidChecks(boolValue
);
136 assertThat(opt
.paranoidChecks()).isEqualTo(boolValue
);
141 public void maxTotalWalSize() {
142 try(final DBOptions opt
= new DBOptions()) {
143 final long longValue
= rand
.nextLong();
144 opt
.setMaxTotalWalSize(longValue
);
145 assertThat(opt
.maxTotalWalSize()).isEqualTo(longValue
);
150 public void maxOpenFiles() {
151 try(final DBOptions opt
= new DBOptions()) {
152 final int intValue
= rand
.nextInt();
153 opt
.setMaxOpenFiles(intValue
);
154 assertThat(opt
.maxOpenFiles()).isEqualTo(intValue
);
159 public void maxFileOpeningThreads() {
160 try(final DBOptions opt
= new DBOptions()) {
161 final int intValue
= rand
.nextInt();
162 opt
.setMaxFileOpeningThreads(intValue
);
163 assertThat(opt
.maxFileOpeningThreads()).isEqualTo(intValue
);
168 public void useFsync() {
169 try(final DBOptions opt
= new DBOptions()) {
170 final boolean boolValue
= rand
.nextBoolean();
171 opt
.setUseFsync(boolValue
);
172 assertThat(opt
.useFsync()).isEqualTo(boolValue
);
177 public void dbPaths() {
178 final List
<DbPath
> dbPaths
= new ArrayList
<>();
179 dbPaths
.add(new DbPath(Paths
.get("/a"), 10));
180 dbPaths
.add(new DbPath(Paths
.get("/b"), 100));
181 dbPaths
.add(new DbPath(Paths
.get("/c"), 1000));
183 try(final DBOptions opt
= new DBOptions()) {
184 assertThat(opt
.dbPaths()).isEqualTo(Collections
.emptyList());
186 opt
.setDbPaths(dbPaths
);
188 assertThat(opt
.dbPaths()).isEqualTo(dbPaths
);
193 public void dbLogDir() {
194 try(final DBOptions opt
= new DBOptions()) {
195 final String str
= "path/to/DbLogDir";
196 opt
.setDbLogDir(str
);
197 assertThat(opt
.dbLogDir()).isEqualTo(str
);
202 public void walDir() {
203 try(final DBOptions opt
= new DBOptions()) {
204 final String str
= "path/to/WalDir";
206 assertThat(opt
.walDir()).isEqualTo(str
);
211 public void deleteObsoleteFilesPeriodMicros() {
212 try(final DBOptions opt
= new DBOptions()) {
213 final long longValue
= rand
.nextLong();
214 opt
.setDeleteObsoleteFilesPeriodMicros(longValue
);
215 assertThat(opt
.deleteObsoleteFilesPeriodMicros()).isEqualTo(longValue
);
219 @SuppressWarnings("deprecated")
221 public void maxBackgroundCompactions() {
222 try(final DBOptions opt
= new DBOptions()) {
223 final int intValue
= rand
.nextInt();
224 opt
.setMaxBackgroundCompactions(intValue
);
225 assertThat(opt
.maxBackgroundCompactions()).isEqualTo(intValue
);
230 public void maxSubcompactions() {
231 try (final DBOptions opt
= new DBOptions()) {
232 final int intValue
= rand
.nextInt();
233 opt
.setMaxSubcompactions(intValue
);
234 assertThat(opt
.maxSubcompactions()).
239 @SuppressWarnings("deprecated")
241 public void maxBackgroundFlushes() {
242 try(final DBOptions opt
= new DBOptions()) {
243 final int intValue
= rand
.nextInt();
244 opt
.setMaxBackgroundFlushes(intValue
);
245 assertThat(opt
.maxBackgroundFlushes()).isEqualTo(intValue
);
250 public void maxBackgroundJobs() {
251 try (final DBOptions opt
= new DBOptions()) {
252 final int intValue
= rand
.nextInt();
253 opt
.setMaxBackgroundJobs(intValue
);
254 assertThat(opt
.maxBackgroundJobs()).isEqualTo(intValue
);
259 public void maxLogFileSize() throws RocksDBException
{
260 try(final DBOptions opt
= new DBOptions()) {
261 final long longValue
= rand
.nextLong();
262 opt
.setMaxLogFileSize(longValue
);
263 assertThat(opt
.maxLogFileSize()).isEqualTo(longValue
);
268 public void logFileTimeToRoll() throws RocksDBException
{
269 try(final DBOptions opt
= new DBOptions()) {
270 final long longValue
= rand
.nextLong();
271 opt
.setLogFileTimeToRoll(longValue
);
272 assertThat(opt
.logFileTimeToRoll()).isEqualTo(longValue
);
277 public void keepLogFileNum() throws RocksDBException
{
278 try(final DBOptions opt
= new DBOptions()) {
279 final long longValue
= rand
.nextLong();
280 opt
.setKeepLogFileNum(longValue
);
281 assertThat(opt
.keepLogFileNum()).isEqualTo(longValue
);
286 public void recycleLogFileNum() throws RocksDBException
{
287 try(final DBOptions opt
= new DBOptions()) {
288 final long longValue
= rand
.nextLong();
289 opt
.setRecycleLogFileNum(longValue
);
290 assertThat(opt
.recycleLogFileNum()).isEqualTo(longValue
);
295 public void maxManifestFileSize() {
296 try(final DBOptions opt
= new DBOptions()) {
297 final long longValue
= rand
.nextLong();
298 opt
.setMaxManifestFileSize(longValue
);
299 assertThat(opt
.maxManifestFileSize()).isEqualTo(longValue
);
304 public void tableCacheNumshardbits() {
305 try(final DBOptions opt
= new DBOptions()) {
306 final int intValue
= rand
.nextInt();
307 opt
.setTableCacheNumshardbits(intValue
);
308 assertThat(opt
.tableCacheNumshardbits()).isEqualTo(intValue
);
313 public void walSizeLimitMB() {
314 try(final DBOptions opt
= new DBOptions()) {
315 final long longValue
= rand
.nextLong();
316 opt
.setWalSizeLimitMB(longValue
);
317 assertThat(opt
.walSizeLimitMB()).isEqualTo(longValue
);
322 public void walTtlSeconds() {
323 try(final DBOptions opt
= new DBOptions()) {
324 final long longValue
= rand
.nextLong();
325 opt
.setWalTtlSeconds(longValue
);
326 assertThat(opt
.walTtlSeconds()).isEqualTo(longValue
);
331 public void manifestPreallocationSize() throws RocksDBException
{
332 try(final DBOptions opt
= new DBOptions()) {
333 final long longValue
= rand
.nextLong();
334 opt
.setManifestPreallocationSize(longValue
);
335 assertThat(opt
.manifestPreallocationSize()).isEqualTo(longValue
);
340 public void useDirectReads() {
341 try(final DBOptions opt
= new DBOptions()) {
342 final boolean boolValue
= rand
.nextBoolean();
343 opt
.setUseDirectReads(boolValue
);
344 assertThat(opt
.useDirectReads()).isEqualTo(boolValue
);
349 public void useDirectIoForFlushAndCompaction() {
350 try(final DBOptions opt
= new DBOptions()) {
351 final boolean boolValue
= rand
.nextBoolean();
352 opt
.setUseDirectIoForFlushAndCompaction(boolValue
);
353 assertThat(opt
.useDirectIoForFlushAndCompaction()).isEqualTo(boolValue
);
358 public void allowFAllocate() {
359 try(final DBOptions opt
= new DBOptions()) {
360 final boolean boolValue
= rand
.nextBoolean();
361 opt
.setAllowFAllocate(boolValue
);
362 assertThat(opt
.allowFAllocate()).isEqualTo(boolValue
);
367 public void allowMmapReads() {
368 try(final DBOptions opt
= new DBOptions()) {
369 final boolean boolValue
= rand
.nextBoolean();
370 opt
.setAllowMmapReads(boolValue
);
371 assertThat(opt
.allowMmapReads()).isEqualTo(boolValue
);
376 public void allowMmapWrites() {
377 try(final DBOptions opt
= new DBOptions()) {
378 final boolean boolValue
= rand
.nextBoolean();
379 opt
.setAllowMmapWrites(boolValue
);
380 assertThat(opt
.allowMmapWrites()).isEqualTo(boolValue
);
385 public void isFdCloseOnExec() {
386 try(final DBOptions opt
= new DBOptions()) {
387 final boolean boolValue
= rand
.nextBoolean();
388 opt
.setIsFdCloseOnExec(boolValue
);
389 assertThat(opt
.isFdCloseOnExec()).isEqualTo(boolValue
);
394 public void statsDumpPeriodSec() {
395 try(final DBOptions opt
= new DBOptions()) {
396 final int intValue
= rand
.nextInt();
397 opt
.setStatsDumpPeriodSec(intValue
);
398 assertThat(opt
.statsDumpPeriodSec()).isEqualTo(intValue
);
403 public void statsPersistPeriodSec() {
404 try (final DBOptions opt
= new DBOptions()) {
405 final int intValue
= rand
.nextInt();
406 opt
.setStatsPersistPeriodSec(intValue
);
407 assertThat(opt
.statsPersistPeriodSec()).isEqualTo(intValue
);
412 public void statsHistoryBufferSize() {
413 try (final DBOptions opt
= new DBOptions()) {
414 final long longValue
= rand
.nextLong();
415 opt
.setStatsHistoryBufferSize(longValue
);
416 assertThat(opt
.statsHistoryBufferSize()).isEqualTo(longValue
);
421 public void adviseRandomOnOpen() {
422 try(final DBOptions opt
= new DBOptions()) {
423 final boolean boolValue
= rand
.nextBoolean();
424 opt
.setAdviseRandomOnOpen(boolValue
);
425 assertThat(opt
.adviseRandomOnOpen()).isEqualTo(boolValue
);
430 public void dbWriteBufferSize() {
431 try(final DBOptions opt
= new DBOptions()) {
432 final long longValue
= rand
.nextLong();
433 opt
.setDbWriteBufferSize(longValue
);
434 assertThat(opt
.dbWriteBufferSize()).isEqualTo(longValue
);
439 public void setWriteBufferManager() throws RocksDBException
{
440 try (final DBOptions opt
= new DBOptions();
441 final Cache cache
= new LRUCache(1 * 1024 * 1024);
442 final WriteBufferManager writeBufferManager
= new WriteBufferManager(2000l, cache
)) {
443 opt
.setWriteBufferManager(writeBufferManager
);
444 assertThat(opt
.writeBufferManager()).isEqualTo(writeBufferManager
);
449 public void setWriteBufferManagerWithZeroBufferSize() throws RocksDBException
{
450 try (final DBOptions opt
= new DBOptions();
451 final Cache cache
= new LRUCache(1 * 1024 * 1024);
452 final WriteBufferManager writeBufferManager
= new WriteBufferManager(0l, cache
)) {
453 opt
.setWriteBufferManager(writeBufferManager
);
454 assertThat(opt
.writeBufferManager()).isEqualTo(writeBufferManager
);
459 public void accessHintOnCompactionStart() {
460 try(final DBOptions opt
= new DBOptions()) {
461 final AccessHint accessHint
= AccessHint
.SEQUENTIAL
;
462 opt
.setAccessHintOnCompactionStart(accessHint
);
463 assertThat(opt
.accessHintOnCompactionStart()).isEqualTo(accessHint
);
468 public void compactionReadaheadSize() {
469 try(final DBOptions opt
= new DBOptions()) {
470 final long longValue
= rand
.nextLong();
471 opt
.setCompactionReadaheadSize(longValue
);
472 assertThat(opt
.compactionReadaheadSize()).isEqualTo(longValue
);
477 public void randomAccessMaxBufferSize() {
478 try(final DBOptions opt
= new DBOptions()) {
479 final long longValue
= rand
.nextLong();
480 opt
.setRandomAccessMaxBufferSize(longValue
);
481 assertThat(opt
.randomAccessMaxBufferSize()).isEqualTo(longValue
);
486 public void writableFileMaxBufferSize() {
487 try(final DBOptions opt
= new DBOptions()) {
488 final long longValue
= rand
.nextLong();
489 opt
.setWritableFileMaxBufferSize(longValue
);
490 assertThat(opt
.writableFileMaxBufferSize()).isEqualTo(longValue
);
495 public void useAdaptiveMutex() {
496 try(final DBOptions opt
= new DBOptions()) {
497 final boolean boolValue
= rand
.nextBoolean();
498 opt
.setUseAdaptiveMutex(boolValue
);
499 assertThat(opt
.useAdaptiveMutex()).isEqualTo(boolValue
);
504 public void bytesPerSync() {
505 try(final DBOptions opt
= new DBOptions()) {
506 final long longValue
= rand
.nextLong();
507 opt
.setBytesPerSync(longValue
);
508 assertThat(opt
.bytesPerSync()).isEqualTo(longValue
);
513 public void walBytesPerSync() {
514 try(final DBOptions opt
= new DBOptions()) {
515 final long longValue
= rand
.nextLong();
516 opt
.setWalBytesPerSync(longValue
);
517 assertThat(opt
.walBytesPerSync()).isEqualTo(longValue
);
522 public void strictBytesPerSync() {
523 try (final DBOptions opt
= new DBOptions()) {
524 assertThat(opt
.strictBytesPerSync()).isFalse();
525 opt
.setStrictBytesPerSync(true);
526 assertThat(opt
.strictBytesPerSync()).isTrue();
531 public void enableThreadTracking() {
532 try (final DBOptions opt
= new DBOptions()) {
533 final boolean boolValue
= rand
.nextBoolean();
534 opt
.setEnableThreadTracking(boolValue
);
535 assertThat(opt
.enableThreadTracking()).isEqualTo(boolValue
);
540 public void delayedWriteRate() {
541 try(final DBOptions opt
= new DBOptions()) {
542 final long longValue
= rand
.nextLong();
543 opt
.setDelayedWriteRate(longValue
);
544 assertThat(opt
.delayedWriteRate()).isEqualTo(longValue
);
549 public void enablePipelinedWrite() {
550 try(final DBOptions opt
= new DBOptions()) {
551 assertThat(opt
.enablePipelinedWrite()).isFalse();
552 opt
.setEnablePipelinedWrite(true);
553 assertThat(opt
.enablePipelinedWrite()).isTrue();
558 public void unordredWrite() {
559 try(final DBOptions opt
= new DBOptions()) {
560 assertThat(opt
.unorderedWrite()).isFalse();
561 opt
.setUnorderedWrite(true);
562 assertThat(opt
.unorderedWrite()).isTrue();
567 public void allowConcurrentMemtableWrite() {
568 try (final DBOptions opt
= new DBOptions()) {
569 final boolean boolValue
= rand
.nextBoolean();
570 opt
.setAllowConcurrentMemtableWrite(boolValue
);
571 assertThat(opt
.allowConcurrentMemtableWrite()).isEqualTo(boolValue
);
576 public void enableWriteThreadAdaptiveYield() {
577 try (final DBOptions opt
= new DBOptions()) {
578 final boolean boolValue
= rand
.nextBoolean();
579 opt
.setEnableWriteThreadAdaptiveYield(boolValue
);
580 assertThat(opt
.enableWriteThreadAdaptiveYield()).isEqualTo(boolValue
);
585 public void writeThreadMaxYieldUsec() {
586 try (final DBOptions opt
= new DBOptions()) {
587 final long longValue
= rand
.nextLong();
588 opt
.setWriteThreadMaxYieldUsec(longValue
);
589 assertThat(opt
.writeThreadMaxYieldUsec()).isEqualTo(longValue
);
594 public void writeThreadSlowYieldUsec() {
595 try (final DBOptions opt
= new DBOptions()) {
596 final long longValue
= rand
.nextLong();
597 opt
.setWriteThreadSlowYieldUsec(longValue
);
598 assertThat(opt
.writeThreadSlowYieldUsec()).isEqualTo(longValue
);
603 public void skipStatsUpdateOnDbOpen() {
604 try (final DBOptions opt
= new DBOptions()) {
605 final boolean boolValue
= rand
.nextBoolean();
606 opt
.setSkipStatsUpdateOnDbOpen(boolValue
);
607 assertThat(opt
.skipStatsUpdateOnDbOpen()).isEqualTo(boolValue
);
612 public void walRecoveryMode() {
613 try (final DBOptions opt
= new DBOptions()) {
614 for (final WALRecoveryMode walRecoveryMode
: WALRecoveryMode
.values()) {
615 opt
.setWalRecoveryMode(walRecoveryMode
);
616 assertThat(opt
.walRecoveryMode()).isEqualTo(walRecoveryMode
);
622 public void allow2pc() {
623 try (final DBOptions opt
= new DBOptions()) {
624 final boolean boolValue
= rand
.nextBoolean();
625 opt
.setAllow2pc(boolValue
);
626 assertThat(opt
.allow2pc()).isEqualTo(boolValue
);
631 public void rowCache() {
632 try (final DBOptions opt
= new DBOptions()) {
633 assertThat(opt
.rowCache()).isNull();
635 try(final Cache lruCache
= new LRUCache(1000)) {
636 opt
.setRowCache(lruCache
);
637 assertThat(opt
.rowCache()).isEqualTo(lruCache
);
640 try(final Cache clockCache
= new ClockCache(1000)) {
641 opt
.setRowCache(clockCache
);
642 assertThat(opt
.rowCache()).isEqualTo(clockCache
);
648 public void walFilter() {
649 try (final DBOptions opt
= new DBOptions()) {
650 assertThat(opt
.walFilter()).isNull();
652 try (final AbstractWalFilter walFilter
= new AbstractWalFilter() {
654 public void columnFamilyLogNumberMap(
655 final Map
<Integer
, Long
> cfLognumber
,
656 final Map
<String
, Integer
> cfNameId
) {
661 public LogRecordFoundResult
logRecordFound(final long logNumber
,
662 final String logFileName
, final WriteBatch batch
,
663 final WriteBatch newBatch
) {
664 return new LogRecordFoundResult(
665 WalProcessingOption
.CONTINUE_PROCESSING
, false);
669 public String
name() {
670 return "test-wal-filter";
673 opt
.setWalFilter(walFilter
);
674 assertThat(opt
.walFilter()).isEqualTo(walFilter
);
680 public void failIfOptionsFileError() {
681 try (final DBOptions opt
= new DBOptions()) {
682 final boolean boolValue
= rand
.nextBoolean();
683 opt
.setFailIfOptionsFileError(boolValue
);
684 assertThat(opt
.failIfOptionsFileError()).isEqualTo(boolValue
);
689 public void dumpMallocStats() {
690 try (final DBOptions opt
= new DBOptions()) {
691 final boolean boolValue
= rand
.nextBoolean();
692 opt
.setDumpMallocStats(boolValue
);
693 assertThat(opt
.dumpMallocStats()).isEqualTo(boolValue
);
698 public void avoidFlushDuringRecovery() {
699 try (final DBOptions opt
= new DBOptions()) {
700 final boolean boolValue
= rand
.nextBoolean();
701 opt
.setAvoidFlushDuringRecovery(boolValue
);
702 assertThat(opt
.avoidFlushDuringRecovery()).isEqualTo(boolValue
);
707 public void avoidFlushDuringShutdown() {
708 try (final DBOptions opt
= new DBOptions()) {
709 final boolean boolValue
= rand
.nextBoolean();
710 opt
.setAvoidFlushDuringShutdown(boolValue
);
711 assertThat(opt
.avoidFlushDuringShutdown()).isEqualTo(boolValue
);
716 public void allowIngestBehind() {
717 try (final DBOptions opt
= new DBOptions()) {
718 assertThat(opt
.allowIngestBehind()).isFalse();
719 opt
.setAllowIngestBehind(true);
720 assertThat(opt
.allowIngestBehind()).isTrue();
725 public void twoWriteQueues() {
726 try (final DBOptions opt
= new DBOptions()) {
727 assertThat(opt
.twoWriteQueues()).isFalse();
728 opt
.setTwoWriteQueues(true);
729 assertThat(opt
.twoWriteQueues()).isTrue();
734 public void manualWalFlush() {
735 try (final DBOptions opt
= new DBOptions()) {
736 assertThat(opt
.manualWalFlush()).isFalse();
737 opt
.setManualWalFlush(true);
738 assertThat(opt
.manualWalFlush()).isTrue();
743 public void atomicFlush() {
744 try (final DBOptions opt
= new DBOptions()) {
745 assertThat(opt
.atomicFlush()).isFalse();
746 opt
.setAtomicFlush(true);
747 assertThat(opt
.atomicFlush()).isTrue();
752 public void rateLimiter() {
753 try(final DBOptions options
= new DBOptions();
754 final DBOptions anotherOptions
= new DBOptions();
755 final RateLimiter rateLimiter
= new RateLimiter(1000, 100 * 1000, 1)) {
756 options
.setRateLimiter(rateLimiter
);
757 // Test with parameter initialization
758 anotherOptions
.setRateLimiter(
759 new RateLimiter(1000));
764 public void sstFileManager() throws RocksDBException
{
765 try (final DBOptions options
= new DBOptions();
766 final SstFileManager sstFileManager
=
767 new SstFileManager(Env
.getDefault())) {
768 options
.setSstFileManager(sstFileManager
);
773 public void statistics() {
774 try(final DBOptions options
= new DBOptions()) {
775 final Statistics statistics
= options
.statistics();
776 assertThat(statistics
).isNull();
779 try(final Statistics statistics
= new Statistics();
780 final DBOptions options
= new DBOptions().setStatistics(statistics
);
781 final Statistics stats
= options
.statistics()) {
782 assertThat(stats
).isNotNull();
787 public void avoidUnnecessaryBlockingIO() {
788 try (final DBOptions options
= new DBOptions()) {
789 assertThat(options
.avoidUnnecessaryBlockingIO()).isEqualTo(false);
790 assertThat(options
.setAvoidUnnecessaryBlockingIO(true)).isEqualTo(options
);
791 assertThat(options
.avoidUnnecessaryBlockingIO()).isEqualTo(true);
796 public void persistStatsToDisk() {
797 try (final DBOptions options
= new DBOptions()) {
798 assertThat(options
.persistStatsToDisk()).isEqualTo(false);
799 assertThat(options
.setPersistStatsToDisk(true)).isEqualTo(options
);
800 assertThat(options
.persistStatsToDisk()).isEqualTo(true);
805 public void writeDbidToManifest() {
806 try (final DBOptions options
= new DBOptions()) {
807 assertThat(options
.writeDbidToManifest()).isEqualTo(false);
808 assertThat(options
.setWriteDbidToManifest(true)).isEqualTo(options
);
809 assertThat(options
.writeDbidToManifest()).isEqualTo(true);
814 public void logReadaheadSize() {
815 try (final DBOptions options
= new DBOptions()) {
816 assertThat(options
.logReadaheadSize()).isEqualTo(0);
817 final int size
= 1024 * 1024 * 100;
818 assertThat(options
.setLogReadaheadSize(size
)).isEqualTo(options
);
819 assertThat(options
.logReadaheadSize()).isEqualTo(size
);
824 public void bestEffortsRecovery() {
825 try (final DBOptions options
= new DBOptions()) {
826 assertThat(options
.bestEffortsRecovery()).isEqualTo(false);
827 assertThat(options
.setBestEffortsRecovery(true)).isEqualTo(options
);
828 assertThat(options
.bestEffortsRecovery()).isEqualTo(true);
833 public void maxBgerrorResumeCount() {
834 try (final DBOptions options
= new DBOptions()) {
835 final int INT_MAX
= 2147483647;
836 assertThat(options
.maxBgerrorResumeCount()).isEqualTo(INT_MAX
);
837 assertThat(options
.setMaxBgErrorResumeCount(-1)).isEqualTo(options
);
838 assertThat(options
.maxBgerrorResumeCount()).isEqualTo(-1);
843 public void bgerrorResumeRetryInterval() {
844 try (final DBOptions options
= new DBOptions()) {
845 assertThat(options
.bgerrorResumeRetryInterval()).isEqualTo(1000000);
846 final long newRetryInterval
= 24 * 3600 * 1000000L;
847 assertThat(options
.setBgerrorResumeRetryInterval(newRetryInterval
)).isEqualTo(options
);
848 assertThat(options
.bgerrorResumeRetryInterval()).isEqualTo(newRetryInterval
);
853 public void maxWriteBatchGroupSizeBytes() {
854 try (final DBOptions options
= new DBOptions()) {
855 assertThat(options
.maxWriteBatchGroupSizeBytes()).isEqualTo(1024 * 1024);
856 final long size
= 1024 * 1024 * 1024 * 10L;
857 assertThat(options
.setMaxWriteBatchGroupSizeBytes(size
)).isEqualTo(options
);
858 assertThat(options
.maxWriteBatchGroupSizeBytes()).isEqualTo(size
);
863 public void skipCheckingSstFileSizesOnDbOpen() {
864 try (final DBOptions options
= new DBOptions()) {
865 assertThat(options
.skipCheckingSstFileSizesOnDbOpen()).isEqualTo(false);
866 assertThat(options
.setSkipCheckingSstFileSizesOnDbOpen(true)).isEqualTo(options
);
867 assertThat(options
.skipCheckingSstFileSizesOnDbOpen()).isEqualTo(true);
872 public void eventListeners() {
873 final AtomicBoolean wasCalled1
= new AtomicBoolean();
874 final AtomicBoolean wasCalled2
= new AtomicBoolean();
875 try (final DBOptions options
= new DBOptions();
876 final AbstractEventListener el1
=
877 new AbstractEventListener() {
879 public void onTableFileDeleted(final TableFileDeletionInfo tableFileDeletionInfo
) {
880 wasCalled1
.set(true);
883 final AbstractEventListener el2
=
884 new AbstractEventListener() {
886 public void onMemTableSealed(final MemTableInfo memTableInfo
) {
887 wasCalled2
.set(true);
890 assertThat(options
.setListeners(Arrays
.asList(el1
, el2
))).isEqualTo(options
);
891 List
<AbstractEventListener
> listeners
= options
.listeners();
892 assertEquals(el1
, listeners
.get(0));
893 assertEquals(el2
, listeners
.get(1));
894 options
.setListeners(Collections
.<AbstractEventListener
>emptyList());
895 listeners
.get(0).onTableFileDeleted(null);
896 assertTrue(wasCalled1
.get());
897 listeners
.get(1).onMemTableSealed(null);
898 assertTrue(wasCalled2
.get());
899 List
<AbstractEventListener
> listeners2
= options
.listeners();
900 assertNotNull(listeners2
);
901 assertEquals(0, listeners2
.size());