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 org.junit.ClassRule; 9 import org.junit.Test; 10 11 import java.nio.file.Paths; 12 import java.util.*; 13 14 import static org.assertj.core.api.Assertions.assertThat; 15 16 public class DBOptionsTest { 17 18 @ClassRule 19 public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE = 20 new RocksNativeLibraryResource(); 21 22 public static final Random rand = PlatformRandomHelper. 23 getPlatformSpecificRandomFactory(); 24 25 @Test copyConstructor()26 public void copyConstructor() { 27 DBOptions origOpts = new DBOptions(); 28 origOpts.setCreateIfMissing(rand.nextBoolean()); 29 origOpts.setAllow2pc(rand.nextBoolean()); 30 origOpts.setMaxBackgroundJobs(rand.nextInt(10)); 31 DBOptions copyOpts = new DBOptions(origOpts); 32 assertThat(origOpts.createIfMissing()).isEqualTo(copyOpts.createIfMissing()); 33 assertThat(origOpts.allow2pc()).isEqualTo(copyOpts.allow2pc()); 34 assertThat(origOpts.baseBackgroundCompactions()).isEqualTo( 35 copyOpts.baseBackgroundCompactions()); 36 } 37 38 @Test getDBOptionsFromProps()39 public void getDBOptionsFromProps() { 40 // setup sample properties 41 final Properties properties = new Properties(); 42 properties.put("allow_mmap_reads", "true"); 43 properties.put("bytes_per_sync", "13"); 44 try(final DBOptions opt = DBOptions.getDBOptionsFromProps(properties)) { 45 assertThat(opt).isNotNull(); 46 assertThat(String.valueOf(opt.allowMmapReads())). 47 isEqualTo(properties.get("allow_mmap_reads")); 48 assertThat(String.valueOf(opt.bytesPerSync())). 49 isEqualTo(properties.get("bytes_per_sync")); 50 } 51 } 52 53 @Test failDBOptionsFromPropsWithIllegalValue()54 public void failDBOptionsFromPropsWithIllegalValue() { 55 // setup sample properties 56 final Properties properties = new Properties(); 57 properties.put("tomato", "1024"); 58 properties.put("burger", "2"); 59 try(final DBOptions opt = DBOptions.getDBOptionsFromProps(properties)) { 60 assertThat(opt).isNull(); 61 } 62 } 63 64 @Test(expected = IllegalArgumentException.class) failDBOptionsFromPropsWithNullValue()65 public void failDBOptionsFromPropsWithNullValue() { 66 try(final DBOptions opt = DBOptions.getDBOptionsFromProps(null)) { 67 //no-op 68 } 69 } 70 71 @Test(expected = IllegalArgumentException.class) failDBOptionsFromPropsWithEmptyProps()72 public void failDBOptionsFromPropsWithEmptyProps() { 73 try(final DBOptions opt = DBOptions.getDBOptionsFromProps( 74 new Properties())) { 75 //no-op 76 } 77 } 78 79 @Test linkageOfPrepMethods()80 public void linkageOfPrepMethods() { 81 try (final DBOptions opt = new DBOptions()) { 82 opt.optimizeForSmallDb(); 83 } 84 } 85 86 @Test env()87 public void env() { 88 try (final DBOptions opt = new DBOptions(); 89 final Env env = Env.getDefault()) { 90 opt.setEnv(env); 91 assertThat(opt.getEnv()).isSameAs(env); 92 } 93 } 94 95 @Test setIncreaseParallelism()96 public void setIncreaseParallelism() { 97 try(final DBOptions opt = new DBOptions()) { 98 final int threads = Runtime.getRuntime().availableProcessors() * 2; 99 opt.setIncreaseParallelism(threads); 100 } 101 } 102 103 @Test createIfMissing()104 public void createIfMissing() { 105 try(final DBOptions opt = new DBOptions()) { 106 final boolean boolValue = rand.nextBoolean(); 107 opt.setCreateIfMissing(boolValue); 108 assertThat(opt.createIfMissing()).isEqualTo(boolValue); 109 } 110 } 111 112 @Test createMissingColumnFamilies()113 public void createMissingColumnFamilies() { 114 try(final DBOptions opt = new DBOptions()) { 115 final boolean boolValue = rand.nextBoolean(); 116 opt.setCreateMissingColumnFamilies(boolValue); 117 assertThat(opt.createMissingColumnFamilies()).isEqualTo(boolValue); 118 } 119 } 120 121 @Test errorIfExists()122 public void errorIfExists() { 123 try(final DBOptions opt = new DBOptions()) { 124 final boolean boolValue = rand.nextBoolean(); 125 opt.setErrorIfExists(boolValue); 126 assertThat(opt.errorIfExists()).isEqualTo(boolValue); 127 } 128 } 129 130 @Test paranoidChecks()131 public void paranoidChecks() { 132 try(final DBOptions opt = new DBOptions()) { 133 final boolean boolValue = rand.nextBoolean(); 134 opt.setParanoidChecks(boolValue); 135 assertThat(opt.paranoidChecks()).isEqualTo(boolValue); 136 } 137 } 138 139 @Test maxTotalWalSize()140 public void maxTotalWalSize() { 141 try(final DBOptions opt = new DBOptions()) { 142 final long longValue = rand.nextLong(); 143 opt.setMaxTotalWalSize(longValue); 144 assertThat(opt.maxTotalWalSize()).isEqualTo(longValue); 145 } 146 } 147 148 @Test maxOpenFiles()149 public void maxOpenFiles() { 150 try(final DBOptions opt = new DBOptions()) { 151 final int intValue = rand.nextInt(); 152 opt.setMaxOpenFiles(intValue); 153 assertThat(opt.maxOpenFiles()).isEqualTo(intValue); 154 } 155 } 156 157 @Test maxFileOpeningThreads()158 public void maxFileOpeningThreads() { 159 try(final DBOptions opt = new DBOptions()) { 160 final int intValue = rand.nextInt(); 161 opt.setMaxFileOpeningThreads(intValue); 162 assertThat(opt.maxFileOpeningThreads()).isEqualTo(intValue); 163 } 164 } 165 166 @Test useFsync()167 public void useFsync() { 168 try(final DBOptions opt = new DBOptions()) { 169 final boolean boolValue = rand.nextBoolean(); 170 opt.setUseFsync(boolValue); 171 assertThat(opt.useFsync()).isEqualTo(boolValue); 172 } 173 } 174 175 @Test dbPaths()176 public void dbPaths() { 177 final List<DbPath> dbPaths = new ArrayList<>(); 178 dbPaths.add(new DbPath(Paths.get("/a"), 10)); 179 dbPaths.add(new DbPath(Paths.get("/b"), 100)); 180 dbPaths.add(new DbPath(Paths.get("/c"), 1000)); 181 182 try(final DBOptions opt = new DBOptions()) { 183 assertThat(opt.dbPaths()).isEqualTo(Collections.emptyList()); 184 185 opt.setDbPaths(dbPaths); 186 187 assertThat(opt.dbPaths()).isEqualTo(dbPaths); 188 } 189 } 190 191 @Test dbLogDir()192 public void dbLogDir() { 193 try(final DBOptions opt = new DBOptions()) { 194 final String str = "path/to/DbLogDir"; 195 opt.setDbLogDir(str); 196 assertThat(opt.dbLogDir()).isEqualTo(str); 197 } 198 } 199 200 @Test walDir()201 public void walDir() { 202 try(final DBOptions opt = new DBOptions()) { 203 final String str = "path/to/WalDir"; 204 opt.setWalDir(str); 205 assertThat(opt.walDir()).isEqualTo(str); 206 } 207 } 208 209 @Test deleteObsoleteFilesPeriodMicros()210 public void deleteObsoleteFilesPeriodMicros() { 211 try(final DBOptions opt = new DBOptions()) { 212 final long longValue = rand.nextLong(); 213 opt.setDeleteObsoleteFilesPeriodMicros(longValue); 214 assertThat(opt.deleteObsoleteFilesPeriodMicros()).isEqualTo(longValue); 215 } 216 } 217 218 @SuppressWarnings("deprecated") 219 @Test baseBackgroundCompactions()220 public void baseBackgroundCompactions() { 221 try (final DBOptions opt = new DBOptions()) { 222 final int intValue = rand.nextInt(); 223 opt.setBaseBackgroundCompactions(intValue); 224 assertThat(opt.baseBackgroundCompactions()). 225 isEqualTo(intValue); 226 } 227 } 228 229 @SuppressWarnings("deprecated") 230 @Test maxBackgroundCompactions()231 public void maxBackgroundCompactions() { 232 try(final DBOptions opt = new DBOptions()) { 233 final int intValue = rand.nextInt(); 234 opt.setMaxBackgroundCompactions(intValue); 235 assertThat(opt.maxBackgroundCompactions()).isEqualTo(intValue); 236 } 237 } 238 239 @Test maxSubcompactions()240 public void maxSubcompactions() { 241 try (final DBOptions opt = new DBOptions()) { 242 final int intValue = rand.nextInt(); 243 opt.setMaxSubcompactions(intValue); 244 assertThat(opt.maxSubcompactions()). 245 isEqualTo(intValue); 246 } 247 } 248 249 @SuppressWarnings("deprecated") 250 @Test maxBackgroundFlushes()251 public void maxBackgroundFlushes() { 252 try(final DBOptions opt = new DBOptions()) { 253 final int intValue = rand.nextInt(); 254 opt.setMaxBackgroundFlushes(intValue); 255 assertThat(opt.maxBackgroundFlushes()).isEqualTo(intValue); 256 } 257 } 258 259 @Test maxBackgroundJobs()260 public void maxBackgroundJobs() { 261 try (final DBOptions opt = new DBOptions()) { 262 final int intValue = rand.nextInt(); 263 opt.setMaxBackgroundJobs(intValue); 264 assertThat(opt.maxBackgroundJobs()).isEqualTo(intValue); 265 } 266 } 267 268 @Test maxLogFileSize()269 public void maxLogFileSize() throws RocksDBException { 270 try(final DBOptions opt = new DBOptions()) { 271 final long longValue = rand.nextLong(); 272 opt.setMaxLogFileSize(longValue); 273 assertThat(opt.maxLogFileSize()).isEqualTo(longValue); 274 } 275 } 276 277 @Test logFileTimeToRoll()278 public void logFileTimeToRoll() throws RocksDBException { 279 try(final DBOptions opt = new DBOptions()) { 280 final long longValue = rand.nextLong(); 281 opt.setLogFileTimeToRoll(longValue); 282 assertThat(opt.logFileTimeToRoll()).isEqualTo(longValue); 283 } 284 } 285 286 @Test keepLogFileNum()287 public void keepLogFileNum() throws RocksDBException { 288 try(final DBOptions opt = new DBOptions()) { 289 final long longValue = rand.nextLong(); 290 opt.setKeepLogFileNum(longValue); 291 assertThat(opt.keepLogFileNum()).isEqualTo(longValue); 292 } 293 } 294 295 @Test recycleLogFileNum()296 public void recycleLogFileNum() throws RocksDBException { 297 try(final DBOptions opt = new DBOptions()) { 298 final long longValue = rand.nextLong(); 299 opt.setRecycleLogFileNum(longValue); 300 assertThat(opt.recycleLogFileNum()).isEqualTo(longValue); 301 } 302 } 303 304 @Test maxManifestFileSize()305 public void maxManifestFileSize() { 306 try(final DBOptions opt = new DBOptions()) { 307 final long longValue = rand.nextLong(); 308 opt.setMaxManifestFileSize(longValue); 309 assertThat(opt.maxManifestFileSize()).isEqualTo(longValue); 310 } 311 } 312 313 @Test tableCacheNumshardbits()314 public void tableCacheNumshardbits() { 315 try(final DBOptions opt = new DBOptions()) { 316 final int intValue = rand.nextInt(); 317 opt.setTableCacheNumshardbits(intValue); 318 assertThat(opt.tableCacheNumshardbits()).isEqualTo(intValue); 319 } 320 } 321 322 @Test walSizeLimitMB()323 public void walSizeLimitMB() { 324 try(final DBOptions opt = new DBOptions()) { 325 final long longValue = rand.nextLong(); 326 opt.setWalSizeLimitMB(longValue); 327 assertThat(opt.walSizeLimitMB()).isEqualTo(longValue); 328 } 329 } 330 331 @Test walTtlSeconds()332 public void walTtlSeconds() { 333 try(final DBOptions opt = new DBOptions()) { 334 final long longValue = rand.nextLong(); 335 opt.setWalTtlSeconds(longValue); 336 assertThat(opt.walTtlSeconds()).isEqualTo(longValue); 337 } 338 } 339 340 @Test manifestPreallocationSize()341 public void manifestPreallocationSize() throws RocksDBException { 342 try(final DBOptions opt = new DBOptions()) { 343 final long longValue = rand.nextLong(); 344 opt.setManifestPreallocationSize(longValue); 345 assertThat(opt.manifestPreallocationSize()).isEqualTo(longValue); 346 } 347 } 348 349 @Test useDirectReads()350 public void useDirectReads() { 351 try(final DBOptions opt = new DBOptions()) { 352 final boolean boolValue = rand.nextBoolean(); 353 opt.setUseDirectReads(boolValue); 354 assertThat(opt.useDirectReads()).isEqualTo(boolValue); 355 } 356 } 357 358 @Test useDirectIoForFlushAndCompaction()359 public void useDirectIoForFlushAndCompaction() { 360 try(final DBOptions opt = new DBOptions()) { 361 final boolean boolValue = rand.nextBoolean(); 362 opt.setUseDirectIoForFlushAndCompaction(boolValue); 363 assertThat(opt.useDirectIoForFlushAndCompaction()).isEqualTo(boolValue); 364 } 365 } 366 367 @Test allowFAllocate()368 public void allowFAllocate() { 369 try(final DBOptions opt = new DBOptions()) { 370 final boolean boolValue = rand.nextBoolean(); 371 opt.setAllowFAllocate(boolValue); 372 assertThat(opt.allowFAllocate()).isEqualTo(boolValue); 373 } 374 } 375 376 @Test allowMmapReads()377 public void allowMmapReads() { 378 try(final DBOptions opt = new DBOptions()) { 379 final boolean boolValue = rand.nextBoolean(); 380 opt.setAllowMmapReads(boolValue); 381 assertThat(opt.allowMmapReads()).isEqualTo(boolValue); 382 } 383 } 384 385 @Test allowMmapWrites()386 public void allowMmapWrites() { 387 try(final DBOptions opt = new DBOptions()) { 388 final boolean boolValue = rand.nextBoolean(); 389 opt.setAllowMmapWrites(boolValue); 390 assertThat(opt.allowMmapWrites()).isEqualTo(boolValue); 391 } 392 } 393 394 @Test isFdCloseOnExec()395 public void isFdCloseOnExec() { 396 try(final DBOptions opt = new DBOptions()) { 397 final boolean boolValue = rand.nextBoolean(); 398 opt.setIsFdCloseOnExec(boolValue); 399 assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue); 400 } 401 } 402 403 @Test statsDumpPeriodSec()404 public void statsDumpPeriodSec() { 405 try(final DBOptions opt = new DBOptions()) { 406 final int intValue = rand.nextInt(); 407 opt.setStatsDumpPeriodSec(intValue); 408 assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue); 409 } 410 } 411 412 @Test statsPersistPeriodSec()413 public void statsPersistPeriodSec() { 414 try (final DBOptions opt = new DBOptions()) { 415 final int intValue = rand.nextInt(); 416 opt.setStatsPersistPeriodSec(intValue); 417 assertThat(opt.statsPersistPeriodSec()).isEqualTo(intValue); 418 } 419 } 420 421 @Test statsHistoryBufferSize()422 public void statsHistoryBufferSize() { 423 try (final DBOptions opt = new DBOptions()) { 424 final long longValue = rand.nextLong(); 425 opt.setStatsHistoryBufferSize(longValue); 426 assertThat(opt.statsHistoryBufferSize()).isEqualTo(longValue); 427 } 428 } 429 430 @Test adviseRandomOnOpen()431 public void adviseRandomOnOpen() { 432 try(final DBOptions opt = new DBOptions()) { 433 final boolean boolValue = rand.nextBoolean(); 434 opt.setAdviseRandomOnOpen(boolValue); 435 assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue); 436 } 437 } 438 439 @Test dbWriteBufferSize()440 public void dbWriteBufferSize() { 441 try(final DBOptions opt = new DBOptions()) { 442 final long longValue = rand.nextLong(); 443 opt.setDbWriteBufferSize(longValue); 444 assertThat(opt.dbWriteBufferSize()).isEqualTo(longValue); 445 } 446 } 447 448 @Test setWriteBufferManager()449 public void setWriteBufferManager() throws RocksDBException { 450 try (final DBOptions opt = new DBOptions(); 451 final Cache cache = new LRUCache(1 * 1024 * 1024); 452 final WriteBufferManager writeBufferManager = new WriteBufferManager(2000l, cache)) { 453 opt.setWriteBufferManager(writeBufferManager); 454 assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); 455 } 456 } 457 458 @Test setWriteBufferManagerWithZeroBufferSize()459 public void setWriteBufferManagerWithZeroBufferSize() throws RocksDBException { 460 try (final DBOptions opt = new DBOptions(); 461 final Cache cache = new LRUCache(1 * 1024 * 1024); 462 final WriteBufferManager writeBufferManager = new WriteBufferManager(0l, cache)) { 463 opt.setWriteBufferManager(writeBufferManager); 464 assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); 465 } 466 } 467 468 @Test accessHintOnCompactionStart()469 public void accessHintOnCompactionStart() { 470 try(final DBOptions opt = new DBOptions()) { 471 final AccessHint accessHint = AccessHint.SEQUENTIAL; 472 opt.setAccessHintOnCompactionStart(accessHint); 473 assertThat(opt.accessHintOnCompactionStart()).isEqualTo(accessHint); 474 } 475 } 476 477 @Test newTableReaderForCompactionInputs()478 public void newTableReaderForCompactionInputs() { 479 try(final DBOptions opt = new DBOptions()) { 480 final boolean boolValue = rand.nextBoolean(); 481 opt.setNewTableReaderForCompactionInputs(boolValue); 482 assertThat(opt.newTableReaderForCompactionInputs()).isEqualTo(boolValue); 483 } 484 } 485 486 @Test compactionReadaheadSize()487 public void compactionReadaheadSize() { 488 try(final DBOptions opt = new DBOptions()) { 489 final long longValue = rand.nextLong(); 490 opt.setCompactionReadaheadSize(longValue); 491 assertThat(opt.compactionReadaheadSize()).isEqualTo(longValue); 492 } 493 } 494 495 @Test randomAccessMaxBufferSize()496 public void randomAccessMaxBufferSize() { 497 try(final DBOptions opt = new DBOptions()) { 498 final long longValue = rand.nextLong(); 499 opt.setRandomAccessMaxBufferSize(longValue); 500 assertThat(opt.randomAccessMaxBufferSize()).isEqualTo(longValue); 501 } 502 } 503 504 @Test writableFileMaxBufferSize()505 public void writableFileMaxBufferSize() { 506 try(final DBOptions opt = new DBOptions()) { 507 final long longValue = rand.nextLong(); 508 opt.setWritableFileMaxBufferSize(longValue); 509 assertThat(opt.writableFileMaxBufferSize()).isEqualTo(longValue); 510 } 511 } 512 513 @Test useAdaptiveMutex()514 public void useAdaptiveMutex() { 515 try(final DBOptions opt = new DBOptions()) { 516 final boolean boolValue = rand.nextBoolean(); 517 opt.setUseAdaptiveMutex(boolValue); 518 assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue); 519 } 520 } 521 522 @Test bytesPerSync()523 public void bytesPerSync() { 524 try(final DBOptions opt = new DBOptions()) { 525 final long longValue = rand.nextLong(); 526 opt.setBytesPerSync(longValue); 527 assertThat(opt.bytesPerSync()).isEqualTo(longValue); 528 } 529 } 530 531 @Test walBytesPerSync()532 public void walBytesPerSync() { 533 try(final DBOptions opt = new DBOptions()) { 534 final long longValue = rand.nextLong(); 535 opt.setWalBytesPerSync(longValue); 536 assertThat(opt.walBytesPerSync()).isEqualTo(longValue); 537 } 538 } 539 540 @Test strictBytesPerSync()541 public void strictBytesPerSync() { 542 try (final DBOptions opt = new DBOptions()) { 543 assertThat(opt.strictBytesPerSync()).isFalse(); 544 opt.setStrictBytesPerSync(true); 545 assertThat(opt.strictBytesPerSync()).isTrue(); 546 } 547 } 548 549 @Test enableThreadTracking()550 public void enableThreadTracking() { 551 try (final DBOptions opt = new DBOptions()) { 552 final boolean boolValue = rand.nextBoolean(); 553 opt.setEnableThreadTracking(boolValue); 554 assertThat(opt.enableThreadTracking()).isEqualTo(boolValue); 555 } 556 } 557 558 @Test delayedWriteRate()559 public void delayedWriteRate() { 560 try(final DBOptions opt = new DBOptions()) { 561 final long longValue = rand.nextLong(); 562 opt.setDelayedWriteRate(longValue); 563 assertThat(opt.delayedWriteRate()).isEqualTo(longValue); 564 } 565 } 566 567 @Test enablePipelinedWrite()568 public void enablePipelinedWrite() { 569 try(final DBOptions opt = new DBOptions()) { 570 assertThat(opt.enablePipelinedWrite()).isFalse(); 571 opt.setEnablePipelinedWrite(true); 572 assertThat(opt.enablePipelinedWrite()).isTrue(); 573 } 574 } 575 576 @Test unordredWrite()577 public void unordredWrite() { 578 try(final DBOptions opt = new DBOptions()) { 579 assertThat(opt.unorderedWrite()).isFalse(); 580 opt.setUnorderedWrite(true); 581 assertThat(opt.unorderedWrite()).isTrue(); 582 } 583 } 584 585 @Test allowConcurrentMemtableWrite()586 public void allowConcurrentMemtableWrite() { 587 try (final DBOptions opt = new DBOptions()) { 588 final boolean boolValue = rand.nextBoolean(); 589 opt.setAllowConcurrentMemtableWrite(boolValue); 590 assertThat(opt.allowConcurrentMemtableWrite()).isEqualTo(boolValue); 591 } 592 } 593 594 @Test enableWriteThreadAdaptiveYield()595 public void enableWriteThreadAdaptiveYield() { 596 try (final DBOptions opt = new DBOptions()) { 597 final boolean boolValue = rand.nextBoolean(); 598 opt.setEnableWriteThreadAdaptiveYield(boolValue); 599 assertThat(opt.enableWriteThreadAdaptiveYield()).isEqualTo(boolValue); 600 } 601 } 602 603 @Test writeThreadMaxYieldUsec()604 public void writeThreadMaxYieldUsec() { 605 try (final DBOptions opt = new DBOptions()) { 606 final long longValue = rand.nextLong(); 607 opt.setWriteThreadMaxYieldUsec(longValue); 608 assertThat(opt.writeThreadMaxYieldUsec()).isEqualTo(longValue); 609 } 610 } 611 612 @Test writeThreadSlowYieldUsec()613 public void writeThreadSlowYieldUsec() { 614 try (final DBOptions opt = new DBOptions()) { 615 final long longValue = rand.nextLong(); 616 opt.setWriteThreadSlowYieldUsec(longValue); 617 assertThat(opt.writeThreadSlowYieldUsec()).isEqualTo(longValue); 618 } 619 } 620 621 @Test skipStatsUpdateOnDbOpen()622 public void skipStatsUpdateOnDbOpen() { 623 try (final DBOptions opt = new DBOptions()) { 624 final boolean boolValue = rand.nextBoolean(); 625 opt.setSkipStatsUpdateOnDbOpen(boolValue); 626 assertThat(opt.skipStatsUpdateOnDbOpen()).isEqualTo(boolValue); 627 } 628 } 629 630 @Test walRecoveryMode()631 public void walRecoveryMode() { 632 try (final DBOptions opt = new DBOptions()) { 633 for (final WALRecoveryMode walRecoveryMode : WALRecoveryMode.values()) { 634 opt.setWalRecoveryMode(walRecoveryMode); 635 assertThat(opt.walRecoveryMode()).isEqualTo(walRecoveryMode); 636 } 637 } 638 } 639 640 @Test allow2pc()641 public void allow2pc() { 642 try (final DBOptions opt = new DBOptions()) { 643 final boolean boolValue = rand.nextBoolean(); 644 opt.setAllow2pc(boolValue); 645 assertThat(opt.allow2pc()).isEqualTo(boolValue); 646 } 647 } 648 649 @Test rowCache()650 public void rowCache() { 651 try (final DBOptions opt = new DBOptions()) { 652 assertThat(opt.rowCache()).isNull(); 653 654 try(final Cache lruCache = new LRUCache(1000)) { 655 opt.setRowCache(lruCache); 656 assertThat(opt.rowCache()).isEqualTo(lruCache); 657 } 658 659 try(final Cache clockCache = new ClockCache(1000)) { 660 opt.setRowCache(clockCache); 661 assertThat(opt.rowCache()).isEqualTo(clockCache); 662 } 663 } 664 } 665 666 @Test walFilter()667 public void walFilter() { 668 try (final DBOptions opt = new DBOptions()) { 669 assertThat(opt.walFilter()).isNull(); 670 671 try (final AbstractWalFilter walFilter = new AbstractWalFilter() { 672 @Override 673 public void columnFamilyLogNumberMap( 674 final Map<Integer, Long> cfLognumber, 675 final Map<String, Integer> cfNameId) { 676 // no-op 677 } 678 679 @Override 680 public LogRecordFoundResult logRecordFound(final long logNumber, 681 final String logFileName, final WriteBatch batch, 682 final WriteBatch newBatch) { 683 return new LogRecordFoundResult( 684 WalProcessingOption.CONTINUE_PROCESSING, false); 685 } 686 687 @Override 688 public String name() { 689 return "test-wal-filter"; 690 } 691 }) { 692 opt.setWalFilter(walFilter); 693 assertThat(opt.walFilter()).isEqualTo(walFilter); 694 } 695 } 696 } 697 698 @Test failIfOptionsFileError()699 public void failIfOptionsFileError() { 700 try (final DBOptions opt = new DBOptions()) { 701 final boolean boolValue = rand.nextBoolean(); 702 opt.setFailIfOptionsFileError(boolValue); 703 assertThat(opt.failIfOptionsFileError()).isEqualTo(boolValue); 704 } 705 } 706 707 @Test dumpMallocStats()708 public void dumpMallocStats() { 709 try (final DBOptions opt = new DBOptions()) { 710 final boolean boolValue = rand.nextBoolean(); 711 opt.setDumpMallocStats(boolValue); 712 assertThat(opt.dumpMallocStats()).isEqualTo(boolValue); 713 } 714 } 715 716 @Test avoidFlushDuringRecovery()717 public void avoidFlushDuringRecovery() { 718 try (final DBOptions opt = new DBOptions()) { 719 final boolean boolValue = rand.nextBoolean(); 720 opt.setAvoidFlushDuringRecovery(boolValue); 721 assertThat(opt.avoidFlushDuringRecovery()).isEqualTo(boolValue); 722 } 723 } 724 725 @Test avoidFlushDuringShutdown()726 public void avoidFlushDuringShutdown() { 727 try (final DBOptions opt = new DBOptions()) { 728 final boolean boolValue = rand.nextBoolean(); 729 opt.setAvoidFlushDuringShutdown(boolValue); 730 assertThat(opt.avoidFlushDuringShutdown()).isEqualTo(boolValue); 731 } 732 } 733 734 @Test allowIngestBehind()735 public void allowIngestBehind() { 736 try (final DBOptions opt = new DBOptions()) { 737 assertThat(opt.allowIngestBehind()).isFalse(); 738 opt.setAllowIngestBehind(true); 739 assertThat(opt.allowIngestBehind()).isTrue(); 740 } 741 } 742 743 @Test preserveDeletes()744 public void preserveDeletes() { 745 try (final DBOptions opt = new DBOptions()) { 746 assertThat(opt.preserveDeletes()).isFalse(); 747 opt.setPreserveDeletes(true); 748 assertThat(opt.preserveDeletes()).isTrue(); 749 } 750 } 751 752 @Test twoWriteQueues()753 public void twoWriteQueues() { 754 try (final DBOptions opt = new DBOptions()) { 755 assertThat(opt.twoWriteQueues()).isFalse(); 756 opt.setTwoWriteQueues(true); 757 assertThat(opt.twoWriteQueues()).isTrue(); 758 } 759 } 760 761 @Test manualWalFlush()762 public void manualWalFlush() { 763 try (final DBOptions opt = new DBOptions()) { 764 assertThat(opt.manualWalFlush()).isFalse(); 765 opt.setManualWalFlush(true); 766 assertThat(opt.manualWalFlush()).isTrue(); 767 } 768 } 769 770 @Test atomicFlush()771 public void atomicFlush() { 772 try (final DBOptions opt = new DBOptions()) { 773 assertThat(opt.atomicFlush()).isFalse(); 774 opt.setAtomicFlush(true); 775 assertThat(opt.atomicFlush()).isTrue(); 776 } 777 } 778 779 @Test rateLimiter()780 public void rateLimiter() { 781 try(final DBOptions options = new DBOptions(); 782 final DBOptions anotherOptions = new DBOptions(); 783 final RateLimiter rateLimiter = new RateLimiter(1000, 100 * 1000, 1)) { 784 options.setRateLimiter(rateLimiter); 785 // Test with parameter initialization 786 anotherOptions.setRateLimiter( 787 new RateLimiter(1000)); 788 } 789 } 790 791 @Test sstFileManager()792 public void sstFileManager() throws RocksDBException { 793 try (final DBOptions options = new DBOptions(); 794 final SstFileManager sstFileManager = 795 new SstFileManager(Env.getDefault())) { 796 options.setSstFileManager(sstFileManager); 797 } 798 } 799 800 @Test statistics()801 public void statistics() { 802 try(final DBOptions options = new DBOptions()) { 803 final Statistics statistics = options.statistics(); 804 assertThat(statistics).isNull(); 805 } 806 807 try(final Statistics statistics = new Statistics(); 808 final DBOptions options = new DBOptions().setStatistics(statistics); 809 final Statistics stats = options.statistics()) { 810 assertThat(stats).isNotNull(); 811 } 812 } 813 } 814