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;
019
020import static org.apache.hadoop.hbase.AcidGuaranteesTestTool.FAMILY_A;
021import static org.apache.hadoop.hbase.AcidGuaranteesTestTool.FAMILY_B;
022import static org.apache.hadoop.hbase.AcidGuaranteesTestTool.FAMILY_C;
023import static org.apache.hadoop.hbase.AcidGuaranteesTestTool.TABLE_NAME;
024
025import java.util.Set;
026import org.apache.hadoop.conf.Configuration;
027import org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy;
028import org.apache.hadoop.hbase.testclassification.IntegrationTests;
029import org.apache.hadoop.hbase.util.Bytes;
030import org.apache.hadoop.util.ToolRunner;
031import org.junit.Test;
032import org.junit.experimental.categories.Category;
033
034import org.apache.hbase.thirdparty.com.google.common.collect.Sets;
035
036/**
037 * This Integration Test verifies acid guarantees across column families by frequently writing
038 * values to rows with multiple column families and concurrently reading entire rows that expect all
039 * column families.
040 * <p>
041 * Sample usage:
042 *
043 * <pre>
044 * hbase org.apache.hadoop.hbase.IntegrationTestAcidGuarantees -Dmillis=10000 -DnumWriters=50
045 * -DnumGetters=2 -DnumScanners=2 -DnumUniqueRows=5
046 * </pre>
047 */
048@Category(IntegrationTests.class)
049public class IntegrationTestAcidGuarantees extends IntegrationTestBase {
050  private static final int SERVER_COUNT = 1; // number of slaves for the smallest cluster
051
052  // The unit test version.
053  AcidGuaranteesTestTool tool;
054
055  @Override
056  public int runTestFromCommandLine() throws Exception {
057    return tool.run(new String[0]);
058  }
059
060  @Override
061  public void setUpCluster() throws Exception {
062    // Set small flush size for minicluster so we exercise reseeking scanners
063    util = getTestingUtil(getConf());
064    util.initializeCluster(SERVER_COUNT);
065    conf = getConf();
066    conf.set(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, String.valueOf(128 * 1024));
067    // prevent aggressive region split
068    conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
069      ConstantSizeRegionSplitPolicy.class.getName());
070
071    tool = new AcidGuaranteesTestTool();
072    tool.setConf(getConf());
073  }
074
075  @Override
076  public TableName getTablename() {
077    return TABLE_NAME;
078  }
079
080  @Override
081  protected Set<String> getColumnFamilies() {
082    return Sets.newHashSet(Bytes.toString(FAMILY_A), Bytes.toString(FAMILY_B),
083      Bytes.toString(FAMILY_C));
084  }
085
086  private void runTestAtomicity(long millisToRun, int numWriters, int numGetters, int numScanners,
087    int numUniqueRows) throws Exception {
088    tool.run(new String[] { "-millis", String.valueOf(millisToRun), "-numWriters",
089      String.valueOf(numWriters), "-numGetters", String.valueOf(numGetters), "-numScanners",
090      String.valueOf(numScanners), "-numUniqueRows", String.valueOf(numUniqueRows) });
091  }
092
093  // ***** Actual integration tests
094  @Test
095  public void testGetAtomicity() throws Exception {
096    runTestAtomicity(20000, 4, 4, 0, 3);
097  }
098
099  @Test
100  public void testScanAtomicity() throws Exception {
101    runTestAtomicity(20000, 3, 0, 2, 3);
102  }
103
104  @Test
105  public void testMixedAtomicity() throws Exception {
106    runTestAtomicity(20000, 4, 2, 2, 3);
107  }
108
109  // **** Command line hook
110  public static void main(String[] args) throws Exception {
111    Configuration conf = HBaseConfiguration.create();
112    IntegrationTestingUtility.setUseDistributedCluster(conf);
113    int ret = ToolRunner.run(conf, new IntegrationTestAcidGuarantees(), args);
114    System.exit(ret);
115  }
116}