]>
Commit | Line | Data |
---|---|---|
494da23a TL |
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.util; | |
7 | ||
1e59de90 TL |
8 | import static java.nio.charset.StandardCharsets.UTF_8; |
9 | ||
10 | import java.nio.ByteBuffer; | |
11 | import java.util.Random; | |
494da23a TL |
12 | import org.rocksdb.CompactionPriority; |
13 | import org.rocksdb.Options; | |
14 | import org.rocksdb.WALRecoveryMode; | |
15 | ||
494da23a TL |
16 | /** |
17 | * General test utilities. | |
18 | */ | |
19 | public class TestUtil { | |
20 | ||
21 | /** | |
22 | * Get the options for log iteration tests. | |
23 | * | |
24 | * @return the options | |
25 | */ | |
26 | public static Options optionsForLogIterTest() { | |
27 | return defaultOptions() | |
28 | .setCreateIfMissing(true) | |
29 | .setWalTtlSeconds(1000); | |
30 | } | |
31 | ||
32 | /** | |
33 | * Get the default options. | |
34 | * | |
35 | * @return the options | |
36 | */ | |
37 | public static Options defaultOptions() { | |
38 | return new Options() | |
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); | |
45 | } | |
46 | ||
47 | private static final Random random = new Random(); | |
48 | ||
49 | /** | |
50 | * Generate a random string of bytes. | |
51 | * | |
52 | * @param len the length of the string to generate. | |
53 | * | |
54 | * @return the random string of bytes | |
55 | */ | |
56 | public static byte[] dummyString(final int len) { | |
57 | final byte[] str = new byte[len]; | |
58 | random.nextBytes(str); | |
59 | return str; | |
60 | } | |
1e59de90 TL |
61 | |
62 | /** | |
63 | * Copy a {@link ByteBuffer} into an array for shorthand ease of test coding | |
64 | * @param byteBuffer the buffer to copy | |
65 | * @return a {@link byte[]} containing the same bytes as the input | |
66 | */ | |
67 | public static byte[] bufferBytes(final ByteBuffer byteBuffer) { | |
68 | final byte[] result = new byte[byteBuffer.limit()]; | |
69 | byteBuffer.get(result); | |
70 | return result; | |
71 | } | |
494da23a | 72 | } |