]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/java/src/test/java/org/rocksdb/DBOptionsTest.java
build: use dgit for download target
[ceph.git] / ceph / src / rocksdb / java / src / test / java / org / rocksdb / DBOptionsTest.java
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
5
6package org.rocksdb;
7
8import org.junit.ClassRule;
9import org.junit.Test;
10
11import java.nio.file.Paths;
12import java.util.*;
13
14import static org.assertj.core.api.Assertions.assertThat;
15
16public class DBOptionsTest {
17
18 @ClassRule
19 public static final RocksMemoryResource rocksMemoryResource =
20 new RocksMemoryResource();
21
22 public static final Random rand = PlatformRandomHelper.
23 getPlatformSpecificRandomFactory();
24
11fdf7f2
TL
25 @Test
26 public void copyConstructor() {
27 DBOptions origOpts = new DBOptions();
28 origOpts.setCreateIfMissing(rand.nextBoolean());
29 origOpts.setAllow2pc(rand.nextBoolean());
30 origOpts.setBaseBackgroundCompactions(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
7c673cae
FG
38 @Test
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
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)
65 public void failDBOptionsFromPropsWithNullValue() {
66 try(final DBOptions opt = DBOptions.getDBOptionsFromProps(null)) {
67 //no-op
68 }
69 }
70
71 @Test(expected = IllegalArgumentException.class)
72 public void failDBOptionsFromPropsWithEmptyProps() {
73 try(final DBOptions opt = DBOptions.getDBOptionsFromProps(
74 new Properties())) {
75 //no-op
76 }
77 }
78
79 @Test
80 public void linkageOfPrepMethods() {
81 try (final DBOptions opt = new DBOptions()) {
82 opt.optimizeForSmallDb();
83 }
84 }
85
86 @Test
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
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
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
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
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
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
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
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
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
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
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
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
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
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 @Test
219 public void baseBackgroundCompactions() {
220 try (final DBOptions opt = new DBOptions()) {
221 final int intValue = rand.nextInt();
222 opt.setBaseBackgroundCompactions(intValue);
223 assertThat(opt.baseBackgroundCompactions()).
224 isEqualTo(intValue);
225 }
226 }
227
228 @Test
229 public void maxBackgroundCompactions() {
230 try(final DBOptions opt = new DBOptions()) {
231 final int intValue = rand.nextInt();
232 opt.setMaxBackgroundCompactions(intValue);
233 assertThat(opt.maxBackgroundCompactions()).isEqualTo(intValue);
234 }
235 }
236
237 @Test
238 public void maxSubcompactions() {
239 try (final DBOptions opt = new DBOptions()) {
240 final int intValue = rand.nextInt();
241 opt.setMaxSubcompactions(intValue);
242 assertThat(opt.maxSubcompactions()).
243 isEqualTo(intValue);
244 }
245 }
246
247 @Test
248 public void maxBackgroundFlushes() {
249 try(final DBOptions opt = new DBOptions()) {
250 final int intValue = rand.nextInt();
251 opt.setMaxBackgroundFlushes(intValue);
252 assertThat(opt.maxBackgroundFlushes()).isEqualTo(intValue);
253 }
254 }
255
11fdf7f2
TL
256 @Test
257 public void maxBackgroundJobs() {
258 try (final DBOptions opt = new DBOptions()) {
259 final int intValue = rand.nextInt();
260 opt.setMaxBackgroundJobs(intValue);
261 assertThat(opt.maxBackgroundJobs()).isEqualTo(intValue);
262 }
263 }
264
7c673cae
FG
265 @Test
266 public void maxLogFileSize() throws RocksDBException {
267 try(final DBOptions opt = new DBOptions()) {
268 final long longValue = rand.nextLong();
269 opt.setMaxLogFileSize(longValue);
270 assertThat(opt.maxLogFileSize()).isEqualTo(longValue);
271 }
272 }
273
274 @Test
275 public void logFileTimeToRoll() throws RocksDBException {
276 try(final DBOptions opt = new DBOptions()) {
277 final long longValue = rand.nextLong();
278 opt.setLogFileTimeToRoll(longValue);
279 assertThat(opt.logFileTimeToRoll()).isEqualTo(longValue);
280 }
281 }
282
283 @Test
284 public void keepLogFileNum() throws RocksDBException {
285 try(final DBOptions opt = new DBOptions()) {
286 final long longValue = rand.nextLong();
287 opt.setKeepLogFileNum(longValue);
288 assertThat(opt.keepLogFileNum()).isEqualTo(longValue);
289 }
290 }
291
292 @Test
293 public void recycleLogFileNum() throws RocksDBException {
294 try(final DBOptions opt = new DBOptions()) {
295 final long longValue = rand.nextLong();
296 opt.setRecycleLogFileNum(longValue);
297 assertThat(opt.recycleLogFileNum()).isEqualTo(longValue);
298 }
299 }
300
301 @Test
302 public void maxManifestFileSize() {
303 try(final DBOptions opt = new DBOptions()) {
304 final long longValue = rand.nextLong();
305 opt.setMaxManifestFileSize(longValue);
306 assertThat(opt.maxManifestFileSize()).isEqualTo(longValue);
307 }
308 }
309
310 @Test
311 public void tableCacheNumshardbits() {
312 try(final DBOptions opt = new DBOptions()) {
313 final int intValue = rand.nextInt();
314 opt.setTableCacheNumshardbits(intValue);
315 assertThat(opt.tableCacheNumshardbits()).isEqualTo(intValue);
316 }
317 }
318
319 @Test
320 public void walSizeLimitMB() {
321 try(final DBOptions opt = new DBOptions()) {
322 final long longValue = rand.nextLong();
323 opt.setWalSizeLimitMB(longValue);
324 assertThat(opt.walSizeLimitMB()).isEqualTo(longValue);
325 }
326 }
327
328 @Test
329 public void walTtlSeconds() {
330 try(final DBOptions opt = new DBOptions()) {
331 final long longValue = rand.nextLong();
332 opt.setWalTtlSeconds(longValue);
333 assertThat(opt.walTtlSeconds()).isEqualTo(longValue);
334 }
335 }
336
337 @Test
338 public void manifestPreallocationSize() throws RocksDBException {
339 try(final DBOptions opt = new DBOptions()) {
340 final long longValue = rand.nextLong();
341 opt.setManifestPreallocationSize(longValue);
342 assertThat(opt.manifestPreallocationSize()).isEqualTo(longValue);
343 }
344 }
345
346 @Test
347 public void useDirectReads() {
348 try(final DBOptions opt = new DBOptions()) {
349 final boolean boolValue = rand.nextBoolean();
350 opt.setUseDirectReads(boolValue);
351 assertThat(opt.useDirectReads()).isEqualTo(boolValue);
352 }
353 }
354
355 @Test
356 public void useDirectIoForFlushAndCompaction() {
357 try(final DBOptions opt = new DBOptions()) {
358 final boolean boolValue = rand.nextBoolean();
359 opt.setUseDirectIoForFlushAndCompaction(boolValue);
360 assertThat(opt.useDirectIoForFlushAndCompaction()).isEqualTo(boolValue);
361 }
362 }
363
364 @Test
365 public void allowFAllocate() {
366 try(final DBOptions opt = new DBOptions()) {
367 final boolean boolValue = rand.nextBoolean();
368 opt.setAllowFAllocate(boolValue);
369 assertThat(opt.allowFAllocate()).isEqualTo(boolValue);
370 }
371 }
372
373 @Test
374 public void allowMmapReads() {
375 try(final DBOptions opt = new DBOptions()) {
376 final boolean boolValue = rand.nextBoolean();
377 opt.setAllowMmapReads(boolValue);
378 assertThat(opt.allowMmapReads()).isEqualTo(boolValue);
379 }
380 }
381
382 @Test
383 public void allowMmapWrites() {
384 try(final DBOptions opt = new DBOptions()) {
385 final boolean boolValue = rand.nextBoolean();
386 opt.setAllowMmapWrites(boolValue);
387 assertThat(opt.allowMmapWrites()).isEqualTo(boolValue);
388 }
389 }
390
391 @Test
392 public void isFdCloseOnExec() {
393 try(final DBOptions opt = new DBOptions()) {
394 final boolean boolValue = rand.nextBoolean();
395 opt.setIsFdCloseOnExec(boolValue);
396 assertThat(opt.isFdCloseOnExec()).isEqualTo(boolValue);
397 }
398 }
399
400 @Test
401 public void statsDumpPeriodSec() {
402 try(final DBOptions opt = new DBOptions()) {
403 final int intValue = rand.nextInt();
404 opt.setStatsDumpPeriodSec(intValue);
405 assertThat(opt.statsDumpPeriodSec()).isEqualTo(intValue);
406 }
407 }
408
409 @Test
410 public void adviseRandomOnOpen() {
411 try(final DBOptions opt = new DBOptions()) {
412 final boolean boolValue = rand.nextBoolean();
413 opt.setAdviseRandomOnOpen(boolValue);
414 assertThat(opt.adviseRandomOnOpen()).isEqualTo(boolValue);
415 }
416 }
417
418 @Test
419 public void dbWriteBufferSize() {
420 try(final DBOptions opt = new DBOptions()) {
421 final long longValue = rand.nextLong();
422 opt.setDbWriteBufferSize(longValue);
423 assertThat(opt.dbWriteBufferSize()).isEqualTo(longValue);
424 }
425 }
426
427 @Test
428 public void accessHintOnCompactionStart() {
429 try(final DBOptions opt = new DBOptions()) {
430 final AccessHint accessHint = AccessHint.SEQUENTIAL;
431 opt.setAccessHintOnCompactionStart(accessHint);
432 assertThat(opt.accessHintOnCompactionStart()).isEqualTo(accessHint);
433 }
434 }
435
436 @Test
437 public void newTableReaderForCompactionInputs() {
438 try(final DBOptions opt = new DBOptions()) {
439 final boolean boolValue = rand.nextBoolean();
440 opt.setNewTableReaderForCompactionInputs(boolValue);
441 assertThat(opt.newTableReaderForCompactionInputs()).isEqualTo(boolValue);
442 }
443 }
444
445 @Test
446 public void compactionReadaheadSize() {
447 try(final DBOptions opt = new DBOptions()) {
448 final long longValue = rand.nextLong();
449 opt.setCompactionReadaheadSize(longValue);
450 assertThat(opt.compactionReadaheadSize()).isEqualTo(longValue);
451 }
452 }
453
454 @Test
455 public void randomAccessMaxBufferSize() {
456 try(final DBOptions opt = new DBOptions()) {
457 final long longValue = rand.nextLong();
458 opt.setRandomAccessMaxBufferSize(longValue);
459 assertThat(opt.randomAccessMaxBufferSize()).isEqualTo(longValue);
460 }
461 }
462
463 @Test
464 public void writableFileMaxBufferSize() {
465 try(final DBOptions opt = new DBOptions()) {
466 final long longValue = rand.nextLong();
467 opt.setWritableFileMaxBufferSize(longValue);
468 assertThat(opt.writableFileMaxBufferSize()).isEqualTo(longValue);
469 }
470 }
471
472 @Test
473 public void useAdaptiveMutex() {
474 try(final DBOptions opt = new DBOptions()) {
475 final boolean boolValue = rand.nextBoolean();
476 opt.setUseAdaptiveMutex(boolValue);
477 assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue);
478 }
479 }
480
481 @Test
482 public void bytesPerSync() {
483 try(final DBOptions opt = new DBOptions()) {
484 final long longValue = rand.nextLong();
485 opt.setBytesPerSync(longValue);
486 assertThat(opt.bytesPerSync()).isEqualTo(longValue);
487 }
488 }
489
490 @Test
491 public void walBytesPerSync() {
492 try(final DBOptions opt = new DBOptions()) {
493 final long longValue = rand.nextLong();
494 opt.setWalBytesPerSync(longValue);
495 assertThat(opt.walBytesPerSync()).isEqualTo(longValue);
496 }
497 }
498
499 @Test
500 public void enableThreadTracking() {
501 try (final DBOptions opt = new DBOptions()) {
502 final boolean boolValue = rand.nextBoolean();
503 opt.setEnableThreadTracking(boolValue);
504 assertThat(opt.enableThreadTracking()).isEqualTo(boolValue);
505 }
506 }
507
508 @Test
509 public void delayedWriteRate() {
510 try(final DBOptions opt = new DBOptions()) {
511 final long longValue = rand.nextLong();
512 opt.setDelayedWriteRate(longValue);
513 assertThat(opt.delayedWriteRate()).isEqualTo(longValue);
514 }
515 }
516
517 @Test
518 public void allowConcurrentMemtableWrite() {
519 try (final DBOptions opt = new DBOptions()) {
520 final boolean boolValue = rand.nextBoolean();
521 opt.setAllowConcurrentMemtableWrite(boolValue);
522 assertThat(opt.allowConcurrentMemtableWrite()).isEqualTo(boolValue);
523 }
524 }
525
526 @Test
527 public void enableWriteThreadAdaptiveYield() {
528 try (final DBOptions opt = new DBOptions()) {
529 final boolean boolValue = rand.nextBoolean();
530 opt.setEnableWriteThreadAdaptiveYield(boolValue);
531 assertThat(opt.enableWriteThreadAdaptiveYield()).isEqualTo(boolValue);
532 }
533 }
534
535 @Test
536 public void writeThreadMaxYieldUsec() {
537 try (final DBOptions opt = new DBOptions()) {
538 final long longValue = rand.nextLong();
539 opt.setWriteThreadMaxYieldUsec(longValue);
540 assertThat(opt.writeThreadMaxYieldUsec()).isEqualTo(longValue);
541 }
542 }
543
544 @Test
545 public void writeThreadSlowYieldUsec() {
546 try (final DBOptions opt = new DBOptions()) {
547 final long longValue = rand.nextLong();
548 opt.setWriteThreadSlowYieldUsec(longValue);
549 assertThat(opt.writeThreadSlowYieldUsec()).isEqualTo(longValue);
550 }
551 }
552
553 @Test
554 public void skipStatsUpdateOnDbOpen() {
555 try (final DBOptions opt = new DBOptions()) {
556 final boolean boolValue = rand.nextBoolean();
557 opt.setSkipStatsUpdateOnDbOpen(boolValue);
558 assertThat(opt.skipStatsUpdateOnDbOpen()).isEqualTo(boolValue);
559 }
560 }
561
562 @Test
563 public void walRecoveryMode() {
564 try (final DBOptions opt = new DBOptions()) {
565 for (final WALRecoveryMode walRecoveryMode : WALRecoveryMode.values()) {
566 opt.setWalRecoveryMode(walRecoveryMode);
567 assertThat(opt.walRecoveryMode()).isEqualTo(walRecoveryMode);
568 }
569 }
570 }
571
572 @Test
573 public void allow2pc() {
574 try (final DBOptions opt = new DBOptions()) {
575 final boolean boolValue = rand.nextBoolean();
576 opt.setAllow2pc(boolValue);
577 assertThat(opt.allow2pc()).isEqualTo(boolValue);
578 }
579 }
580
581 @Test
582 public void rowCache() {
583 try (final DBOptions opt = new DBOptions()) {
584 assertThat(opt.rowCache()).isNull();
585
586 try(final Cache lruCache = new LRUCache(1000)) {
587 opt.setRowCache(lruCache);
588 assertThat(opt.rowCache()).isEqualTo(lruCache);
589 }
590
591 try(final Cache clockCache = new ClockCache(1000)) {
592 opt.setRowCache(clockCache);
593 assertThat(opt.rowCache()).isEqualTo(clockCache);
594 }
595 }
596 }
597
598 @Test
599 public void failIfOptionsFileError() {
600 try (final DBOptions opt = new DBOptions()) {
601 final boolean boolValue = rand.nextBoolean();
602 opt.setFailIfOptionsFileError(boolValue);
603 assertThat(opt.failIfOptionsFileError()).isEqualTo(boolValue);
604 }
605 }
606
607 @Test
608 public void dumpMallocStats() {
609 try (final DBOptions opt = new DBOptions()) {
610 final boolean boolValue = rand.nextBoolean();
611 opt.setDumpMallocStats(boolValue);
612 assertThat(opt.dumpMallocStats()).isEqualTo(boolValue);
613 }
614 }
615
616 @Test
617 public void avoidFlushDuringRecovery() {
618 try (final DBOptions opt = new DBOptions()) {
619 final boolean boolValue = rand.nextBoolean();
620 opt.setAvoidFlushDuringRecovery(boolValue);
621 assertThat(opt.avoidFlushDuringRecovery()).isEqualTo(boolValue);
622 }
623 }
624
625 @Test
626 public void avoidFlushDuringShutdown() {
627 try (final DBOptions opt = new DBOptions()) {
628 final boolean boolValue = rand.nextBoolean();
629 opt.setAvoidFlushDuringShutdown(boolValue);
630 assertThat(opt.avoidFlushDuringShutdown()).isEqualTo(boolValue);
631 }
632 }
633
634 @Test
635 public void rateLimiter() {
636 try(final DBOptions options = new DBOptions();
637 final DBOptions anotherOptions = new DBOptions();
638 final RateLimiter rateLimiter = new RateLimiter(1000, 100 * 1000, 1)) {
639 options.setRateLimiter(rateLimiter);
640 // Test with parameter initialization
641 anotherOptions.setRateLimiter(
642 new RateLimiter(1000));
643 }
644 }
645
11fdf7f2
TL
646 @Test
647 public void sstFileManager() throws RocksDBException {
648 try (final DBOptions options = new DBOptions();
649 final SstFileManager sstFileManager =
650 new SstFileManager(Env.getDefault())) {
651 options.setSstFileManager(sstFileManager);
652 }
653 }
654
7c673cae
FG
655 @Test
656 public void statistics() {
657 try(final DBOptions options = new DBOptions()) {
11fdf7f2
TL
658 final Statistics statistics = options.statistics();
659 assertThat(statistics).isNull();
660 }
7c673cae 661
11fdf7f2
TL
662 try(final Statistics statistics = new Statistics();
663 final DBOptions options = new DBOptions().setStatistics(statistics);
664 final Statistics stats = options.statistics()) {
665 assertThat(stats).isNotNull();
7c673cae
FG
666 }
667 }
668}