]>
Commit | Line | Data |
---|---|---|
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 | |
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 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 | ||
494da23a TL |
427 | @Test |
428 | public void setWriteBufferManager() throws RocksDBException { | |
429 | try (final DBOptions opt = new DBOptions(); | |
430 | final Cache cache = new LRUCache(1 * 1024 * 1024); | |
431 | final WriteBufferManager writeBufferManager = new WriteBufferManager(2000l, cache)) { | |
432 | opt.setWriteBufferManager(writeBufferManager); | |
433 | assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); | |
434 | } | |
435 | } | |
436 | ||
437 | @Test | |
438 | public void setWriteBufferManagerWithZeroBufferSize() throws RocksDBException { | |
439 | try (final DBOptions opt = new DBOptions(); | |
440 | final Cache cache = new LRUCache(1 * 1024 * 1024); | |
441 | final WriteBufferManager writeBufferManager = new WriteBufferManager(0l, cache)) { | |
442 | opt.setWriteBufferManager(writeBufferManager); | |
443 | assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); | |
444 | } | |
445 | } | |
446 | ||
7c673cae FG |
447 | @Test |
448 | public void accessHintOnCompactionStart() { | |
449 | try(final DBOptions opt = new DBOptions()) { | |
450 | final AccessHint accessHint = AccessHint.SEQUENTIAL; | |
451 | opt.setAccessHintOnCompactionStart(accessHint); | |
452 | assertThat(opt.accessHintOnCompactionStart()).isEqualTo(accessHint); | |
453 | } | |
454 | } | |
455 | ||
456 | @Test | |
457 | public void newTableReaderForCompactionInputs() { | |
458 | try(final DBOptions opt = new DBOptions()) { | |
459 | final boolean boolValue = rand.nextBoolean(); | |
460 | opt.setNewTableReaderForCompactionInputs(boolValue); | |
461 | assertThat(opt.newTableReaderForCompactionInputs()).isEqualTo(boolValue); | |
462 | } | |
463 | } | |
464 | ||
465 | @Test | |
466 | public void compactionReadaheadSize() { | |
467 | try(final DBOptions opt = new DBOptions()) { | |
468 | final long longValue = rand.nextLong(); | |
469 | opt.setCompactionReadaheadSize(longValue); | |
470 | assertThat(opt.compactionReadaheadSize()).isEqualTo(longValue); | |
471 | } | |
472 | } | |
473 | ||
474 | @Test | |
475 | public void randomAccessMaxBufferSize() { | |
476 | try(final DBOptions opt = new DBOptions()) { | |
477 | final long longValue = rand.nextLong(); | |
478 | opt.setRandomAccessMaxBufferSize(longValue); | |
479 | assertThat(opt.randomAccessMaxBufferSize()).isEqualTo(longValue); | |
480 | } | |
481 | } | |
482 | ||
483 | @Test | |
484 | public void writableFileMaxBufferSize() { | |
485 | try(final DBOptions opt = new DBOptions()) { | |
486 | final long longValue = rand.nextLong(); | |
487 | opt.setWritableFileMaxBufferSize(longValue); | |
488 | assertThat(opt.writableFileMaxBufferSize()).isEqualTo(longValue); | |
489 | } | |
490 | } | |
491 | ||
492 | @Test | |
493 | public void useAdaptiveMutex() { | |
494 | try(final DBOptions opt = new DBOptions()) { | |
495 | final boolean boolValue = rand.nextBoolean(); | |
496 | opt.setUseAdaptiveMutex(boolValue); | |
497 | assertThat(opt.useAdaptiveMutex()).isEqualTo(boolValue); | |
498 | } | |
499 | } | |
500 | ||
501 | @Test | |
502 | public void bytesPerSync() { | |
503 | try(final DBOptions opt = new DBOptions()) { | |
504 | final long longValue = rand.nextLong(); | |
505 | opt.setBytesPerSync(longValue); | |
506 | assertThat(opt.bytesPerSync()).isEqualTo(longValue); | |
507 | } | |
508 | } | |
509 | ||
510 | @Test | |
511 | public void walBytesPerSync() { | |
512 | try(final DBOptions opt = new DBOptions()) { | |
513 | final long longValue = rand.nextLong(); | |
514 | opt.setWalBytesPerSync(longValue); | |
515 | assertThat(opt.walBytesPerSync()).isEqualTo(longValue); | |
516 | } | |
517 | } | |
518 | ||
519 | @Test | |
520 | public void enableThreadTracking() { | |
521 | try (final DBOptions opt = new DBOptions()) { | |
522 | final boolean boolValue = rand.nextBoolean(); | |
523 | opt.setEnableThreadTracking(boolValue); | |
524 | assertThat(opt.enableThreadTracking()).isEqualTo(boolValue); | |
525 | } | |
526 | } | |
527 | ||
528 | @Test | |
529 | public void delayedWriteRate() { | |
530 | try(final DBOptions opt = new DBOptions()) { | |
531 | final long longValue = rand.nextLong(); | |
532 | opt.setDelayedWriteRate(longValue); | |
533 | assertThat(opt.delayedWriteRate()).isEqualTo(longValue); | |
534 | } | |
535 | } | |
536 | ||
494da23a TL |
537 | @Test |
538 | public void enablePipelinedWrite() { | |
539 | try(final DBOptions opt = new DBOptions()) { | |
540 | assertThat(opt.enablePipelinedWrite()).isFalse(); | |
541 | opt.setEnablePipelinedWrite(true); | |
542 | assertThat(opt.enablePipelinedWrite()).isTrue(); | |
543 | } | |
544 | } | |
545 | ||
7c673cae FG |
546 | @Test |
547 | public void allowConcurrentMemtableWrite() { | |
548 | try (final DBOptions opt = new DBOptions()) { | |
549 | final boolean boolValue = rand.nextBoolean(); | |
550 | opt.setAllowConcurrentMemtableWrite(boolValue); | |
551 | assertThat(opt.allowConcurrentMemtableWrite()).isEqualTo(boolValue); | |
552 | } | |
553 | } | |
554 | ||
555 | @Test | |
556 | public void enableWriteThreadAdaptiveYield() { | |
557 | try (final DBOptions opt = new DBOptions()) { | |
558 | final boolean boolValue = rand.nextBoolean(); | |
559 | opt.setEnableWriteThreadAdaptiveYield(boolValue); | |
560 | assertThat(opt.enableWriteThreadAdaptiveYield()).isEqualTo(boolValue); | |
561 | } | |
562 | } | |
563 | ||
564 | @Test | |
565 | public void writeThreadMaxYieldUsec() { | |
566 | try (final DBOptions opt = new DBOptions()) { | |
567 | final long longValue = rand.nextLong(); | |
568 | opt.setWriteThreadMaxYieldUsec(longValue); | |
569 | assertThat(opt.writeThreadMaxYieldUsec()).isEqualTo(longValue); | |
570 | } | |
571 | } | |
572 | ||
573 | @Test | |
574 | public void writeThreadSlowYieldUsec() { | |
575 | try (final DBOptions opt = new DBOptions()) { | |
576 | final long longValue = rand.nextLong(); | |
577 | opt.setWriteThreadSlowYieldUsec(longValue); | |
578 | assertThat(opt.writeThreadSlowYieldUsec()).isEqualTo(longValue); | |
579 | } | |
580 | } | |
581 | ||
582 | @Test | |
583 | public void skipStatsUpdateOnDbOpen() { | |
584 | try (final DBOptions opt = new DBOptions()) { | |
585 | final boolean boolValue = rand.nextBoolean(); | |
586 | opt.setSkipStatsUpdateOnDbOpen(boolValue); | |
587 | assertThat(opt.skipStatsUpdateOnDbOpen()).isEqualTo(boolValue); | |
588 | } | |
589 | } | |
590 | ||
591 | @Test | |
592 | public void walRecoveryMode() { | |
593 | try (final DBOptions opt = new DBOptions()) { | |
594 | for (final WALRecoveryMode walRecoveryMode : WALRecoveryMode.values()) { | |
595 | opt.setWalRecoveryMode(walRecoveryMode); | |
596 | assertThat(opt.walRecoveryMode()).isEqualTo(walRecoveryMode); | |
597 | } | |
598 | } | |
599 | } | |
600 | ||
601 | @Test | |
602 | public void allow2pc() { | |
603 | try (final DBOptions opt = new DBOptions()) { | |
604 | final boolean boolValue = rand.nextBoolean(); | |
605 | opt.setAllow2pc(boolValue); | |
606 | assertThat(opt.allow2pc()).isEqualTo(boolValue); | |
607 | } | |
608 | } | |
609 | ||
610 | @Test | |
611 | public void rowCache() { | |
612 | try (final DBOptions opt = new DBOptions()) { | |
613 | assertThat(opt.rowCache()).isNull(); | |
614 | ||
615 | try(final Cache lruCache = new LRUCache(1000)) { | |
616 | opt.setRowCache(lruCache); | |
617 | assertThat(opt.rowCache()).isEqualTo(lruCache); | |
618 | } | |
619 | ||
620 | try(final Cache clockCache = new ClockCache(1000)) { | |
621 | opt.setRowCache(clockCache); | |
622 | assertThat(opt.rowCache()).isEqualTo(clockCache); | |
623 | } | |
624 | } | |
625 | } | |
626 | ||
494da23a TL |
627 | @Test |
628 | public void walFilter() { | |
629 | try (final DBOptions opt = new DBOptions()) { | |
630 | assertThat(opt.walFilter()).isNull(); | |
631 | ||
632 | try (final AbstractWalFilter walFilter = new AbstractWalFilter() { | |
633 | @Override | |
634 | public void columnFamilyLogNumberMap( | |
635 | final Map<Integer, Long> cfLognumber, | |
636 | final Map<String, Integer> cfNameId) { | |
637 | // no-op | |
638 | } | |
639 | ||
640 | @Override | |
641 | public LogRecordFoundResult logRecordFound(final long logNumber, | |
642 | final String logFileName, final WriteBatch batch, | |
643 | final WriteBatch newBatch) { | |
644 | return new LogRecordFoundResult( | |
645 | WalProcessingOption.CONTINUE_PROCESSING, false); | |
646 | } | |
647 | ||
648 | @Override | |
649 | public String name() { | |
650 | return "test-wal-filter"; | |
651 | } | |
652 | }) { | |
653 | opt.setWalFilter(walFilter); | |
654 | assertThat(opt.walFilter()).isEqualTo(walFilter); | |
655 | } | |
656 | } | |
657 | } | |
658 | ||
7c673cae FG |
659 | @Test |
660 | public void failIfOptionsFileError() { | |
661 | try (final DBOptions opt = new DBOptions()) { | |
662 | final boolean boolValue = rand.nextBoolean(); | |
663 | opt.setFailIfOptionsFileError(boolValue); | |
664 | assertThat(opt.failIfOptionsFileError()).isEqualTo(boolValue); | |
665 | } | |
666 | } | |
667 | ||
668 | @Test | |
669 | public void dumpMallocStats() { | |
670 | try (final DBOptions opt = new DBOptions()) { | |
671 | final boolean boolValue = rand.nextBoolean(); | |
672 | opt.setDumpMallocStats(boolValue); | |
673 | assertThat(opt.dumpMallocStats()).isEqualTo(boolValue); | |
674 | } | |
675 | } | |
676 | ||
677 | @Test | |
678 | public void avoidFlushDuringRecovery() { | |
679 | try (final DBOptions opt = new DBOptions()) { | |
680 | final boolean boolValue = rand.nextBoolean(); | |
681 | opt.setAvoidFlushDuringRecovery(boolValue); | |
682 | assertThat(opt.avoidFlushDuringRecovery()).isEqualTo(boolValue); | |
683 | } | |
684 | } | |
685 | ||
686 | @Test | |
687 | public void avoidFlushDuringShutdown() { | |
688 | try (final DBOptions opt = new DBOptions()) { | |
689 | final boolean boolValue = rand.nextBoolean(); | |
690 | opt.setAvoidFlushDuringShutdown(boolValue); | |
691 | assertThat(opt.avoidFlushDuringShutdown()).isEqualTo(boolValue); | |
692 | } | |
693 | } | |
694 | ||
494da23a TL |
695 | @Test |
696 | public void allowIngestBehind() { | |
697 | try (final DBOptions opt = new DBOptions()) { | |
698 | assertThat(opt.allowIngestBehind()).isFalse(); | |
699 | opt.setAllowIngestBehind(true); | |
700 | assertThat(opt.allowIngestBehind()).isTrue(); | |
701 | } | |
702 | } | |
703 | ||
704 | @Test | |
705 | public void preserveDeletes() { | |
706 | try (final DBOptions opt = new DBOptions()) { | |
707 | assertThat(opt.preserveDeletes()).isFalse(); | |
708 | opt.setPreserveDeletes(true); | |
709 | assertThat(opt.preserveDeletes()).isTrue(); | |
710 | } | |
711 | } | |
712 | ||
713 | @Test | |
714 | public void twoWriteQueues() { | |
715 | try (final DBOptions opt = new DBOptions()) { | |
716 | assertThat(opt.twoWriteQueues()).isFalse(); | |
717 | opt.setTwoWriteQueues(true); | |
718 | assertThat(opt.twoWriteQueues()).isTrue(); | |
719 | } | |
720 | } | |
721 | ||
722 | @Test | |
723 | public void manualWalFlush() { | |
724 | try (final DBOptions opt = new DBOptions()) { | |
725 | assertThat(opt.manualWalFlush()).isFalse(); | |
726 | opt.setManualWalFlush(true); | |
727 | assertThat(opt.manualWalFlush()).isTrue(); | |
728 | } | |
729 | } | |
730 | ||
731 | @Test | |
732 | public void atomicFlush() { | |
733 | try (final DBOptions opt = new DBOptions()) { | |
734 | assertThat(opt.atomicFlush()).isFalse(); | |
735 | opt.setAtomicFlush(true); | |
736 | assertThat(opt.atomicFlush()).isTrue(); | |
737 | } | |
738 | } | |
739 | ||
7c673cae FG |
740 | @Test |
741 | public void rateLimiter() { | |
742 | try(final DBOptions options = new DBOptions(); | |
743 | final DBOptions anotherOptions = new DBOptions(); | |
744 | final RateLimiter rateLimiter = new RateLimiter(1000, 100 * 1000, 1)) { | |
745 | options.setRateLimiter(rateLimiter); | |
746 | // Test with parameter initialization | |
747 | anotherOptions.setRateLimiter( | |
748 | new RateLimiter(1000)); | |
749 | } | |
750 | } | |
751 | ||
11fdf7f2 TL |
752 | @Test |
753 | public void sstFileManager() throws RocksDBException { | |
754 | try (final DBOptions options = new DBOptions(); | |
755 | final SstFileManager sstFileManager = | |
756 | new SstFileManager(Env.getDefault())) { | |
757 | options.setSstFileManager(sstFileManager); | |
758 | } | |
759 | } | |
760 | ||
7c673cae FG |
761 | @Test |
762 | public void statistics() { | |
763 | try(final DBOptions options = new DBOptions()) { | |
11fdf7f2 TL |
764 | final Statistics statistics = options.statistics(); |
765 | assertThat(statistics).isNull(); | |
766 | } | |
7c673cae | 767 | |
11fdf7f2 TL |
768 | try(final Statistics statistics = new Statistics(); |
769 | final DBOptions options = new DBOptions().setStatistics(statistics); | |
770 | final Statistics stats = options.statistics()) { | |
771 | assertThat(stats).isNotNull(); | |
7c673cae FG |
772 | } |
773 | } | |
774 | } |