View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.util;
19  
20  import java.util.Arrays;
21  
22  import org.apache.hadoop.hbase.util.test.LoadTestKVGenerator;
23  
24  /**
25   * A load test data generator for MOB
26   */
27  public class LoadTestDataGeneratorWithMOB
28      extends MultiThreadedAction.DefaultDataGenerator {
29  
30    private byte[] mobColumnFamily;
31    private LoadTestKVGenerator mobKvGenerator;
32  
33    public LoadTestDataGeneratorWithMOB(int minValueSize, int maxValueSize,
34        int minColumnsPerKey, int maxColumnsPerKey, byte[]... columnFamilies) {
35      super(minValueSize, maxValueSize, minColumnsPerKey, maxColumnsPerKey,
36          columnFamilies);
37    }
38  
39    public LoadTestDataGeneratorWithMOB(byte[]... columnFamilies) {
40      super(columnFamilies);
41    }
42  
43    @Override
44    public void initialize(String[] args) {
45      super.initialize(args);
46      if (args.length != 3) {
47        throw new IllegalArgumentException(
48            "LoadTestDataGeneratorWithMOB can have 3 arguments."
49                + "1st argument is a column family, the 2nd argument "
50                + "is the minimum mob data size and the 3rd argument "
51                + "is the maximum mob data size.");
52      }
53      String mobColumnFamily = args[0];
54      int minMobDataSize = Integer.parseInt(args[1]);
55      int maxMobDataSize = Integer.parseInt(args[2]);
56      configureMob(Bytes.toBytes(mobColumnFamily), minMobDataSize, maxMobDataSize);
57    }
58  
59    private void configureMob(byte[] mobColumnFamily, int minMobDataSize,
60        int maxMobDataSize) {
61      this.mobColumnFamily = mobColumnFamily;
62      mobKvGenerator = new LoadTestKVGenerator(minMobDataSize, maxMobDataSize);
63    }
64  
65    @Override
66    public byte[] generateValue(byte[] rowKey, byte[] cf,
67        byte[] column) {
68      if(Arrays.equals(cf, mobColumnFamily))
69        return mobKvGenerator.generateRandomSizeValue(rowKey, cf, column);
70  
71      return super.generateValue(rowKey, cf, column);
72    }
73  }