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;
19  
20  import com.google.common.collect.Sets;
21  import org.apache.hadoop.conf.Configuration;
22  import org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy;
23  import org.apache.hadoop.hbase.testclassification.IntegrationTests;
24  import org.apache.hadoop.util.ToolRunner;
25  import org.junit.Test;
26  import org.junit.experimental.categories.Category;
27  
28  import java.util.Set;
29  
30  /**
31   * This Integration Test verifies acid guarantees across column families by frequently writing
32   * values to rows with multiple column families and concurrently reading entire rows that expect all
33   * column families.
34   *
35   * <p>
36   * Sample usage:
37   * <pre>
38   * hbase org.apache.hadoop.hbase.IntegrationTestAcidGuarantees -Dmillis=10000 -DnumWriters=50
39   * -DnumGetters=2 -DnumScanners=2 -DnumUniqueRows=5
40   * </pre>
41   */
42  @Category(IntegrationTests.class)
43  public class IntegrationTestAcidGuarantees extends IntegrationTestBase {
44    private static final int SERVER_COUNT = 1; // number of slaves for the smallest cluster
45  
46    // The unit test version.
47    TestAcidGuarantees tag;
48  
49    @Override
50    public int runTestFromCommandLine() throws Exception {
51      Configuration c = getConf();
52      int millis = c.getInt("millis", 5000);
53      int numWriters = c.getInt("numWriters", 50);
54      int numGetters = c.getInt("numGetters", 2);
55      int numScanners = c.getInt("numScanners", 2);
56      int numUniqueRows = c.getInt("numUniqueRows", 3);
57      tag.runTestAtomicity(millis, numWriters, numGetters, numScanners, numUniqueRows, true);
58      return 0;
59    }
60  
61    @Override
62    public void setUpCluster() throws Exception {
63      // Set small flush size for minicluster so we exercise reseeking scanners
64      util = getTestingUtil(getConf());
65      util.initializeCluster(SERVER_COUNT);
66      conf = getConf();
67      conf.set(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, String.valueOf(128*1024));
68      // prevent aggressive region split
69      conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
70              ConstantSizeRegionSplitPolicy.class.getName());
71      this.setConf(util.getConfiguration());
72  
73      // replace the HBaseTestingUtility in the unit test with the integration test's
74      // IntegrationTestingUtility
75      tag = new TestAcidGuarantees();
76      tag.setHBaseTestingUtil(util);
77    }
78  
79    @Override
80    public TableName getTablename() {
81      return TestAcidGuarantees.TABLE_NAME;
82    }
83  
84    @Override
85    protected Set<String> getColumnFamilies() {
86      return Sets.newHashSet(String.valueOf(TestAcidGuarantees.FAMILY_A),
87              String.valueOf(TestAcidGuarantees.FAMILY_B),
88              String.valueOf(TestAcidGuarantees.FAMILY_C));
89    }
90  
91    // ***** Actual integration tests
92  
93    @Test
94    public void testGetAtomicity() throws Exception {
95      tag.runTestAtomicity(20000, 5, 5, 0, 3);
96    }
97  
98    @Test
99    public void testScanAtomicity() throws Exception {
100     tag.runTestAtomicity(20000, 5, 0, 5, 3);
101   }
102 
103   @Test
104   public void testMixedAtomicity() throws Exception {
105     tag.runTestAtomicity(20000, 5, 2, 2, 3);
106   }
107 
108 
109   // **** Command line hook
110 
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 }
118 
119