org.apache.hadoop.hbase.util.test
Class LoadTestKVGenerator

java.lang.Object
  extended by org.apache.hadoop.hbase.util.test.LoadTestKVGenerator

@InterfaceAudience.Private
public class LoadTestKVGenerator
extends Object

A generator of random keys and values for load testing. Keys are generated by converting numeric indexes to strings and prefixing them with an MD5 hash. Values are generated by selecting value size in the configured range and generating a pseudo-random sequence of bytes seeded by key, column qualifier, and value size.


Constructor Summary
LoadTestKVGenerator(int minValueSize, int maxValueSize)
           
 
Method Summary
 byte[] generateRandomSizeValue(byte[]... seedStrings)
          Generates a value for the given key index and column qualifier.
static String md5PrefixedKey(long key)
          Converts the given key to string, and prefixes it with the MD5 hash of the index's string representation.
static boolean verify(byte[] value, byte[]... seedStrings)
          Verifies that the given byte array is the same as what would be generated for the given seed strings (row/cf/column/...).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoadTestKVGenerator

public LoadTestKVGenerator(int minValueSize,
                           int maxValueSize)
Method Detail

verify

public static boolean verify(byte[] value,
                             byte[]... seedStrings)
Verifies that the given byte array is the same as what would be generated for the given seed strings (row/cf/column/...). We are assuming that the value size is correct, and only verify the actual bytes. However, if the min/max value sizes are set sufficiently high, an accidental match should be extremely improbable.


md5PrefixedKey

public static String md5PrefixedKey(long key)
Converts the given key to string, and prefixes it with the MD5 hash of the index's string representation.


generateRandomSizeValue

public byte[] generateRandomSizeValue(byte[]... seedStrings)
Generates a value for the given key index and column qualifier. Size is selected randomly in the configured range. The generated value depends only on the combination of the strings passed (key/cf/column/...) and the selected value size. This allows to verify the actual value bytes when reading, as done in {#verify(byte[], byte[]...)} This method is as thread-safe as Random class. It appears that the worst bug ever found with the latter is that multiple threads will get some duplicate values, which we don't care about.



Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.