1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with this 4 * work for additional information regarding copyright ownership. The ASF 5 * licenses this file to you under the Apache License, Version 2.0 (the 6 * "License"); you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 * License for the specific language governing permissions and limitations 15 * under the License. 16 */ 17 package org.apache.hadoop.hbase.util.test; 18 19 import java.util.Set; 20 21 /** 22 * A generator of random data (keys/cfs/columns/values) for load testing. 23 * Contains LoadTestKVGenerator as a matter of convenience... 24 */ 25 public abstract class LoadTestDataGenerator { 26 protected final LoadTestKVGenerator kvGenerator; 27 28 // The mutate info column stores information 29 // about update done to this column family this row. 30 public final static byte[] MUTATE_INFO = "mutate_info".getBytes(); 31 32 // The increment column always has a long value, 33 // which can be incremented later on during updates. 34 public final static byte[] INCREMENT = "increment".getBytes(); 35 36 /** 37 * Initializes the object. 38 * @param minValueSize minimum size of the value generated by 39 * {@link #generateValue(byte[], byte[], byte[])}. 40 * @param maxValueSize maximum size of the value generated by 41 * {@link #generateValue(byte[], byte[], byte[])}. 42 */ 43 public LoadTestDataGenerator(int minValueSize, int maxValueSize) { 44 this.kvGenerator = new LoadTestKVGenerator(minValueSize, maxValueSize); 45 } 46 47 /** 48 * Generates a deterministic, unique hashed row key from a number. That way, the user can 49 * keep track of numbers, without messing with byte array and ensuring key distribution. 50 * @param keyBase Base number for a key, such as a loop counter. 51 */ 52 public abstract byte[] getDeterministicUniqueKey(long keyBase); 53 54 /** 55 * Gets column families for the load test table. 56 * @return The array of byte[]s representing column family names. 57 */ 58 public abstract byte[][] getColumnFamilies(); 59 60 /** 61 * Generates an applicable set of columns to be used for a particular key and family. 62 * @param rowKey The row key to generate for. 63 * @param cf The column family name to generate for. 64 * @return The array of byte[]s representing column names. 65 */ 66 public abstract byte[][] generateColumnsForCf(byte[] rowKey, byte[] cf); 67 68 /** 69 * Generates a value to be used for a particular row/cf/column. 70 * @param rowKey The row key to generate for. 71 * @param cf The column family name to generate for. 72 * @param column The column name to generate for. 73 * @return The value to use. 74 */ 75 public abstract byte[] generateValue(byte[] rowKey, byte[] cf, byte[] column); 76 77 /** 78 * Checks that columns for a rowKey and cf are valid if generated via 79 * {@link #generateColumnsForCf(byte[], byte[])} 80 * @param rowKey The row key to verify for. 81 * @param cf The column family name to verify for. 82 * @param columnSet The column set (for example, encountered by read). 83 * @return True iff valid. 84 */ 85 public abstract boolean verify(byte[] rowKey, byte[] cf, Set<byte[]> columnSet); 86 87 /** 88 * Checks that value for a rowKey/cf/column is valid if generated via 89 * {@link #generateValue(byte[], byte[], byte[])} 90 * @param rowKey The row key to verify for. 91 * @param cf The column family name to verify for. 92 * @param column The column name to verify for. 93 * @param value The value (for example, encountered by read). 94 * @return True iff valid. 95 */ 96 public abstract boolean verify(byte[] rowKey, byte[] cf, byte[] column, byte[] value); 97 }