View Javadoc

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    /**
29     * Initializes the object.
30     * @param minValueSize minimum size of the value generated by
31     * {@link #generateValue(byte[], byte[], byte[])}.
32     * @param maxValueSize maximum size of the value generated by
33     * {@link #generateValue(byte[], byte[], byte[])}.
34     */
35    public LoadTestDataGenerator(int minValueSize, int maxValueSize) {
36      this.kvGenerator = new LoadTestKVGenerator(minValueSize, maxValueSize);
37    }
38  
39    /**
40     * Generates a deterministic, unique hashed row key from a number. That way, the user can
41     * keep track of numbers, without messing with byte array and ensuring key distribution.
42     * @param keyBase Base number for a key, such as a loop counter.
43     */
44    public abstract byte[] getDeterministicUniqueKey(long keyBase);
45  
46    /**
47     * Gets column families for the load test table.
48     * @return The array of byte[]s representing column family names.
49     */
50    public abstract byte[][] getColumnFamilies();
51  
52    /**
53     * Generates an applicable set of columns to be used for a particular key and family.
54     * @param rowKey The row key to generate for.
55     * @param cf The column family name to generate for.
56     * @return The array of byte[]s representing column names.
57     */
58    public abstract byte[][] generateColumnsForCf(byte[] rowKey, byte[] cf);
59  
60    /**
61     * Generates a value to be used for a particular row/cf/column.
62     * @param rowKey The row key to generate for.
63     * @param cf The column family name to generate for.
64     * @param column The column name to generate for.
65     * @return The value to use.
66     */
67    public abstract byte[] generateValue(byte[] rowKey, byte[] cf, byte[] column);
68  
69    /**
70     * Checks that columns for a rowKey and cf are valid if generated via
71     * {@link #generateColumnsForCf(byte[], byte[])}
72     * @param rowKey The row key to verify for.
73     * @param cf The column family name to verify for.
74     * @param columnSet The column set (for example, encountered by read).
75     * @return True iff valid.
76     */
77    public abstract boolean verify(byte[] rowKey, byte[] cf, Set<byte[]> columnSet);
78  
79    /**
80     * Checks that value for a rowKey/cf/column is valid if generated via
81     * {@link #generateValue(byte[], byte[], byte[])}
82     * @param rowKey The row key to verify for.
83     * @param cf The column family name to verify for.
84     * @param column The column name to verify for.
85     * @param value The value (for example, encountered by read).
86     * @return True iff valid.
87     */
88    public abstract boolean verify(byte[] rowKey, byte[] cf, byte[] column, byte[] value);
89  }