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 8 import org.rocksdb.CompactionPriority; 9 import org.rocksdb.Options; 10 import org.rocksdb.WALRecoveryMode; 11 12 import java.util.Random; 13 14 import static java.nio.charset.StandardCharsets.UTF_8; 15 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 */ optionsForLogIterTest()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 */ defaultOptions()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 */ dummyString(final int len)56 public static byte[] dummyString(final int len) { 57 final byte[] str = new byte[len]; 58 random.nextBytes(str); 59 return str; 60 } 61 } 62