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).
6 package org
.rocksdb
.util
;
8 import org
.rocksdb
.CompactionPriority
;
9 import org
.rocksdb
.Options
;
10 import org
.rocksdb
.WALRecoveryMode
;
12 import java
.util
.Random
;
14 import static java
.nio
.charset
.StandardCharsets
.UTF_8
;
17 * General test utilities.
19 public class TestUtil
{
22 * Get the options for log iteration tests.
26 public static Options
optionsForLogIterTest() {
27 return defaultOptions()
28 .setCreateIfMissing(true)
29 .setWalTtlSeconds(1000);
33 * Get the default options.
37 public static Options
defaultOptions() {
39 .setWriteBufferSize(4090 * 4096)
40 .setTargetFileSizeBase(2 * 1024 * 1024)
41 .setMaxBytesForLevelBase(10 * 1024 * 1024)
42 .setMaxOpenFiles(5000)
43 .setWalRecoveryMode(WALRecoveryMode
.TolerateCorruptedTailRecords
)
44 .setCompactionPriority(CompactionPriority
.ByCompensatedSize
);
47 private static final Random random
= new Random();
50 * Generate a random string of bytes.
52 * @param len the length of the string to generate.
54 * @return the random string of bytes
56 public static byte[] dummyString(final int len
) {
57 final byte[] str
= new byte[len
];
58 random
.nextBytes(str
);
63 * Convert a UTF-8 String to a byte array.
65 * @param str the string
67 * @return the byte array.
69 public static byte[] u(final String str
) {
70 return str
.getBytes(UTF_8
);