HBASE-26416 Implement a new method for region replication instead of using replay...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / AcidGuaranteesTestBase.java
blob0f68e11f0f877be31e5bdf348ddbb4ee4b57e65e
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.apache.hadoop.hbase;
20 import static org.apache.hadoop.hbase.AcidGuaranteesTestTool.FAMILIES;
21 import static org.apache.hadoop.hbase.AcidGuaranteesTestTool.TABLE_NAME;
23 import java.util.List;
24 import java.util.stream.Stream;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
27 import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
28 import org.apache.hadoop.hbase.regionserver.CompactingMemStore;
29 import org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy;
30 import org.apache.hadoop.hbase.regionserver.MemStoreLAB;
31 import org.junit.After;
32 import org.junit.AfterClass;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
37 import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
39 /**
40 * Test case that uses multiple threads to read and write multifamily rows into a table, verifying
41 * that reads never see partially-complete writes. This can run as a junit test, or with a main()
42 * function which runs against a real cluster (eg for testing with failures, region movement, etc)
44 public abstract class AcidGuaranteesTestBase {
46 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
48 private AcidGuaranteesTestTool tool = new AcidGuaranteesTestTool();
50 protected abstract MemoryCompactionPolicy getMemoryCompactionPolicy();
52 @BeforeClass
53 public static void setUpBeforeClass() throws Exception {
54 // Set small flush size for minicluster so we exercise reseeking scanners
55 Configuration conf = UTIL.getConfiguration();
56 conf.set(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, String.valueOf(128 * 1024));
57 // prevent aggressive region split
58 conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
59 ConstantSizeRegionSplitPolicy.class.getName());
60 conf.setInt("hfile.format.version", 3); // for mob tests
61 UTIL.startMiniCluster(1);
64 @AfterClass
65 public static void tearDownAfterClass() throws Exception {
66 UTIL.shutdownMiniCluster();
69 @Before
70 public void setUp() throws Exception {
71 MemoryCompactionPolicy policy = getMemoryCompactionPolicy();
72 TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TABLE_NAME)
73 .setValue(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, policy.name());
74 if (policy == MemoryCompactionPolicy.EAGER) {
75 builder.setValue(MemStoreLAB.USEMSLAB_KEY, "false");
76 builder.setValue(CompactingMemStore.IN_MEMORY_FLUSH_THRESHOLD_FACTOR_KEY, "0.9");
78 Stream.of(FAMILIES).map(ColumnFamilyDescriptorBuilder::of)
79 .forEachOrdered(builder::setColumnFamily);
80 UTIL.getAdmin().createTable(builder.build());
81 tool.setConf(UTIL.getConfiguration());
84 @After
85 public void tearDown() throws Exception {
86 UTIL.deleteTable(TABLE_NAME);
89 private void runTestAtomicity(long millisToRun, int numWriters, int numGetters, int numScanners,
90 int numUniqueRows) throws Exception {
91 runTestAtomicity(millisToRun, numWriters, numGetters, numScanners, numUniqueRows, false);
94 private void runTestAtomicity(long millisToRun, int numWriters, int numGetters, int numScanners,
95 int numUniqueRows, boolean useMob) throws Exception {
96 List<String> args = Lists.newArrayList("-millis", String.valueOf(millisToRun), "-numWriters",
97 String.valueOf(numWriters), "-numGetters", String.valueOf(numGetters), "-numScanners",
98 String.valueOf(numScanners), "-numUniqueRows", String.valueOf(numUniqueRows), "-crazyFlush");
99 if (useMob) {
100 args.add("-useMob");
102 tool.run(args.toArray(new String[0]));
105 @Test
106 public void testGetAtomicity() throws Exception {
107 runTestAtomicity(20000, 5, 5, 0, 3);
110 @Test
111 public void testScanAtomicity() throws Exception {
112 runTestAtomicity(20000, 5, 0, 5, 3);
115 @Test
116 public void testMixedAtomicity() throws Exception {
117 runTestAtomicity(20000, 5, 2, 2, 3);
120 @Test
121 public void testMobGetAtomicity() throws Exception {
122 runTestAtomicity(20000, 5, 5, 0, 3, true);
125 @Test
126 public void testMobScanAtomicity() throws Exception {
127 runTestAtomicity(20000, 5, 0, 5, 3, true);
130 @Test
131 public void testMobMixedAtomicity() throws Exception {
132 runTestAtomicity(20000, 5, 2, 2, 3, true);