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