001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.util;
019
020import java.util.Arrays;
021
022/**
023 * A load test data generator for MOB
024 */
025public class LoadTestDataGeneratorWithMOB extends MultiThreadedAction.DefaultDataGenerator {
026
027  private byte[] mobColumnFamily;
028  private LoadTestKVGenerator mobKvGenerator;
029
030  public LoadTestDataGeneratorWithMOB(int minValueSize, int maxValueSize, int minColumnsPerKey,
031    int maxColumnsPerKey, byte[]... columnFamilies) {
032    super(minValueSize, maxValueSize, minColumnsPerKey, maxColumnsPerKey, columnFamilies);
033  }
034
035  public LoadTestDataGeneratorWithMOB(byte[]... columnFamilies) {
036    super(columnFamilies);
037  }
038
039  @Override
040  public void initialize(String[] args) {
041    super.initialize(args);
042    if (args.length != 3) {
043      throw new IllegalArgumentException("LoadTestDataGeneratorWithMOB can have 3 arguments."
044        + "1st argument is a column family, the 2nd argument "
045        + "is the minimum mob data size and the 3rd argument " + "is the maximum mob data size.");
046    }
047    String mobColumnFamily = args[0];
048    int minMobDataSize = Integer.parseInt(args[1]);
049    int maxMobDataSize = Integer.parseInt(args[2]);
050    configureMob(Bytes.toBytes(mobColumnFamily), minMobDataSize, maxMobDataSize);
051  }
052
053  private void configureMob(byte[] mobColumnFamily, int minMobDataSize, int maxMobDataSize) {
054    this.mobColumnFamily = mobColumnFamily;
055    mobKvGenerator = new LoadTestKVGenerator(minMobDataSize, maxMobDataSize);
056  }
057
058  @Override
059  public byte[] generateValue(byte[] rowKey, byte[] cf, byte[] column) {
060    if (Arrays.equals(cf, mobColumnFamily))
061      return mobKvGenerator.generateRandomSizeValue(rowKey, cf, column);
062
063    return super.generateValue(rowKey, cf, column);
064  }
065}