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