]>
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 | ||
20effc67 TL |
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; | |
7c673cae FG |
12 | |
13 | import java.nio.file.Paths; | |
14 | import java.util.*; | |
20effc67 TL |
15 | import java.util.concurrent.atomic.AtomicBoolean; |
16 | import org.junit.ClassRule; | |
17 | import org.junit.Test; | |
7c673cae FG |
18 | |
19 | public class DBOptionsTest { | |
20 | ||
21 | @ClassRule | |
f67539c2 TL |
22 | public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE = |
23 | new RocksNativeLibraryResource(); | |
7c673cae FG |
24 | |
25 | public static final Random rand = PlatformRandomHelper. | |
26 | getPlatformSpecificRandomFactory(); | |
27 | ||
11fdf7f2 TL |
28 | @Test |
29 | public void copyConstructor() { | |
30 | DBOptions origOpts = new DBOptions(); | |
31 | origOpts.setCreateIfMissing(rand.nextBoolean()); | |
32 | origOpts.setAllow2pc(rand.nextBoolean()); | |
f67539c2 | 33 | origOpts.setMaxBackgroundJobs(rand.nextInt(10)); |
11fdf7f2 TL |
34 | DBOptions copyOpts = new DBOptions(origOpts); |
35 | assertThat(origOpts.createIfMissing()).isEqualTo(copyOpts.createIfMissing()); | |
36 | assertThat(origOpts.allow2pc()).isEqualTo(copyOpts.allow2pc()); | |
11fdf7f2 TL |
37 | } |
38 | ||
7c673cae FG |
39 | @Test |
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")); | |
51 | } | |
52 | } | |
53 | ||
54 | @Test | |
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(); | |
62 | } | |
63 | } | |
64 | ||
65 | @Test(expected = IllegalArgumentException.class) | |
66 | public void failDBOptionsFromPropsWithNullValue() { | |
67 | try(final DBOptions opt = DBOptions.getDBOptionsFromProps(null)) { | |
68 | //no-op | |
69 | } | |
70 | } | |
71 | ||
72 | @Test(expected = IllegalArgumentException.class) | |
73 | public void failDBOptionsFromPropsWithEmptyProps() { | |
74 | try(final DBOptions opt = DBOptions.getDBOptionsFromProps( | |
75 | new Properties())) { | |
76 | //no-op | |
77 | } | |
78 | } | |
79 | ||
80 | @Test | |
81 | public void linkageOfPrepMethods() { | |
82 | try (final DBOptions opt = new DBOptions()) { | |
83 | opt.optimizeForSmallDb(); | |
84 | } | |
85 | } | |
86 | ||
87 | @Test | |
88 | public void env() { | |
89 | try (final DBOptions opt = new DBOptions(); | |
90 | final Env env = Env.getDefault()) { | |
91 | opt.setEnv(env); | |
92 | assertThat(opt.getEnv()).isSameAs(env); | |
93 | } | |
94 | } | |
95 | ||
96 | @Test | |
97 | public void setIncreaseParallelism() { | |
98 | try(final DBOptions opt = new DBOptions()) { | |
99 | final int threads = Runtime.getRuntime().availableProcessors() * 2; | |
100 | opt.setIncreaseParallelism(threads); | |
101 | } | |
102 | } | |
103 | ||
104 | @Test | |
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); | |
110 | } | |
111 | } | |
112 | ||
113 | @Test | |
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); | |
119 | } | |
120 | } | |
121 | ||
122 | @Test | |
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); | |
128 | } | |
129 | } | |
130 | ||
131 | @Test | |
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); | |
137 | } | |
138 | } | |
139 | ||
140 | @Test | |
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); | |
146 | } | |
147 | } | |
148 | ||
149 | @Test | |
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); | |
155 | } | |
156 | } | |
157 | ||
158 | @Test | |
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); | |
164 | } | |
165 | } | |
166 | ||
167 | @Test | |
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); | |
173 | } | |
174 | } | |
175 | ||
176 | @Test | |
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)); | |
182 | ||
183 | try(final DBOptions opt = new DBOptions()) { | |
184 | assertThat(opt.dbPaths()).isEqualTo(Collections.emptyList()); | |
185 | ||
186 | opt.setDbPaths(dbPaths); | |
187 | ||
188 | assertThat(opt.dbPaths()).isEqualTo(dbPaths); | |
189 | } | |
190 | } | |
191 | ||
192 | @Test | |
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); | |
198 | } | |
199 | } | |
200 | ||
201 | @Test | |
202 | public void walDir() { | |
203 | try(final DBOptions opt = new DBOptions()) { | |
204 | final String str = "path/to/WalDir"; | |
205 | opt.setWalDir(str); | |
206 | assertThat(opt.walDir()).isEqualTo(str); | |
207 | } | |
208 | } | |
209 | ||
210 | @Test | |
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); | |
216 | } | |
217 | } | |
218 | ||
f67539c2 | 219 | @SuppressWarnings("deprecated") |
7c673cae FG |
220 | @Test |
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); | |
226 | } | |
227 | } | |
228 | ||
229 | @Test | |
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()). | |
235 | isEqualTo(intValue); | |
236 | } | |
237 | } | |
238 | ||
f67539c2 | 239 | @SuppressWarnings("deprecated") |
7c673cae FG |
240 | @Test |
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); | |
246 | } | |
247 | } | |
248 | ||
11fdf7f2 TL |
249 | @Test |
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); | |
255 | } | |
256 | } | |
257 | ||
7c673cae FG |
258 | @Test |
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); | |
264 | } | |
265 | } | |
266 | ||
267 | @Test | |
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); | |
273 | } | |
274 | } | |
275 | ||
276 | @Test | |
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); | |
282 | } | |
283 | } | |
284 | ||
285 | @Test | |
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); | |
291 | } | |
292 | } | |
293 | ||
294 | @Test | |
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); | |
300 | } | |
301 | } | |
302 | ||
303 | @Test | |
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); | |
309 | } | |
310 | } | |
311 | ||
312 | @Test | |
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); | |
318 | } | |
319 | } | |
320 | ||
321 | @Test | |
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); | |
327 | } | |
328 | } | |
329 | ||
330 | @Test | |
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); | |
336 | } | |
337 | } | |
338 | ||
339 | @Test | |
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); | |
345 | } | |
346 | } | |
347 | ||
348 | @Test | |
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); | |
354 | } | |
355 | } | |
356 | ||
357 | @Test | |
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); | |
363 | } | |
364 | } | |
365 | ||
366 | @Test | |
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); | |
372 | } | |
373 | } | |
374 | ||
375 | @Test | |
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); | |
381 | } | |
382 | } | |
383 | ||
384 | @Test | |
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); | |
390 | } | |
391 | } | |
392 | ||
393 | @Test | |
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); | |
399 | } | |
400 | } | |
401 | ||
f67539c2 TL |
402 | @Test |
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); | |
408 | } | |
409 | } | |
410 | ||
411 | @Test | |
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); | |
417 | } | |
418 | } | |
419 | ||
7c673cae FG |
420 | @Test |
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); | |
426 | } | |
427 | } | |
428 | ||
429 | @Test | |
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); | |
435 | } | |
436 | } | |
437 | ||
494da23a TL |
438 | @Test |
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); | |
445 | } | |
446 | } | |
447 | ||
448 | @Test | |
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); | |
455 | } | |
456 | } | |
457 | ||
7c673cae FG |
458 | @Test |
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); | |
464 | } | |
465 | } | |
466 | ||
7c673cae FG |
467 | @Test |
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); | |
473 | } | |
474 | } | |
475 | ||
476 | @Test | |
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); | |
482 | } | |
483 | } | |
484 | ||
485 | @Test | |
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); | |
491 | } | |
492 | } | |
493 | ||
494 | @Test | |
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); | |
500 | } | |
501 | } | |
502 | ||
503 | @Test | |
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); | |
509 | } | |
510 | } | |
511 | ||
512 | @Test | |
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); | |
518 | } | |
519 | } | |
520 | ||
f67539c2 TL |
521 | @Test |
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(); | |
527 | } | |
528 | } | |
529 | ||
7c673cae FG |
530 | @Test |
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); | |
536 | } | |
537 | } | |
538 | ||
539 | @Test | |
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); | |
545 | } | |
546 | } | |
547 | ||
494da23a TL |
548 | @Test |
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(); | |
554 | } | |
555 | } | |
556 | ||
f67539c2 TL |
557 | @Test |
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(); | |
563 | } | |
564 | } | |
565 | ||
7c673cae FG |
566 | @Test |
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); | |
572 | } | |
573 | } | |
574 | ||
575 | @Test | |
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); | |
581 | } | |
582 | } | |
583 | ||
584 | @Test | |
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); | |
590 | } | |
591 | } | |
592 | ||
593 | @Test | |
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); | |
599 | } | |
600 | } | |
601 | ||
602 | @Test | |
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); | |
608 | } | |
609 | } | |
610 | ||
611 | @Test | |
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); | |
617 | } | |
618 | } | |
619 | } | |
620 | ||
621 | @Test | |
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); | |
627 | } | |
628 | } | |
629 | ||
630 | @Test | |
631 | public void rowCache() { | |
632 | try (final DBOptions opt = new DBOptions()) { | |
633 | assertThat(opt.rowCache()).isNull(); | |
634 | ||
635 | try(final Cache lruCache = new LRUCache(1000)) { | |
636 | opt.setRowCache(lruCache); | |
637 | assertThat(opt.rowCache()).isEqualTo(lruCache); | |
638 | } | |
639 | ||
640 | try(final Cache clockCache = new ClockCache(1000)) { | |
641 | opt.setRowCache(clockCache); | |
642 | assertThat(opt.rowCache()).isEqualTo(clockCache); | |
643 | } | |
644 | } | |
645 | } | |
646 | ||
494da23a TL |
647 | @Test |
648 | public void walFilter() { | |
649 | try (final DBOptions opt = new DBOptions()) { | |
650 | assertThat(opt.walFilter()).isNull(); | |
651 | ||
652 | try (final AbstractWalFilter walFilter = new AbstractWalFilter() { | |
653 | @Override | |
654 | public void columnFamilyLogNumberMap( | |
655 | final Map<Integer, Long> cfLognumber, | |
656 | final Map<String, Integer> cfNameId) { | |
657 | // no-op | |
658 | } | |
659 | ||
660 | @Override | |
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); | |
666 | } | |
667 | ||
668 | @Override | |
669 | public String name() { | |
670 | return "test-wal-filter"; | |
671 | } | |
672 | }) { | |
673 | opt.setWalFilter(walFilter); | |
674 | assertThat(opt.walFilter()).isEqualTo(walFilter); | |
675 | } | |
676 | } | |
677 | } | |
678 | ||
7c673cae FG |
679 | @Test |
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); | |
685 | } | |
686 | } | |
687 | ||
688 | @Test | |
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); | |
694 | } | |
695 | } | |
696 | ||
697 | @Test | |
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); | |
703 | } | |
704 | } | |
705 | ||
706 | @Test | |
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); | |
712 | } | |
713 | } | |
714 | ||
494da23a TL |
715 | @Test |
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(); | |
721 | } | |
722 | } | |
723 | ||
494da23a TL |
724 | @Test |
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(); | |
730 | } | |
731 | } | |
732 | ||
733 | @Test | |
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(); | |
739 | } | |
740 | } | |
741 | ||
742 | @Test | |
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(); | |
748 | } | |
749 | } | |
750 | ||
7c673cae FG |
751 | @Test |
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)); | |
760 | } | |
761 | } | |
762 | ||
11fdf7f2 TL |
763 | @Test |
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); | |
769 | } | |
770 | } | |
771 | ||
7c673cae FG |
772 | @Test |
773 | public void statistics() { | |
774 | try(final DBOptions options = new DBOptions()) { | |
11fdf7f2 TL |
775 | final Statistics statistics = options.statistics(); |
776 | assertThat(statistics).isNull(); | |
777 | } | |
7c673cae | 778 | |
11fdf7f2 TL |
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(); | |
7c673cae FG |
783 | } |
784 | } | |
20effc67 TL |
785 | |
786 | @Test | |
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); | |
792 | } | |
793 | } | |
794 | ||
795 | @Test | |
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); | |
801 | } | |
802 | } | |
803 | ||
804 | @Test | |
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); | |
810 | } | |
811 | } | |
812 | ||
813 | @Test | |
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); | |
820 | } | |
821 | } | |
822 | ||
823 | @Test | |
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); | |
829 | } | |
830 | } | |
831 | ||
832 | @Test | |
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); | |
839 | } | |
840 | } | |
841 | ||
842 | @Test | |
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); | |
849 | } | |
850 | } | |
851 | ||
852 | @Test | |
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); | |
859 | } | |
860 | } | |
861 | ||
862 | @Test | |
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); | |
868 | } | |
869 | } | |
870 | ||
871 | @Test | |
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() { | |
878 | @Override | |
879 | public void onTableFileDeleted(final TableFileDeletionInfo tableFileDeletionInfo) { | |
880 | wasCalled1.set(true); | |
881 | } | |
882 | }; | |
883 | final AbstractEventListener el2 = | |
884 | new AbstractEventListener() { | |
885 | @Override | |
886 | public void onMemTableSealed(final MemTableInfo memTableInfo) { | |
887 | wasCalled2.set(true); | |
888 | } | |
889 | }) { | |
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()); | |
902 | } | |
903 | } | |
7c673cae | 904 | } |