Refactor existing test Signed-off-by: poorna <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/incubator-tephra/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tephra/commit/e56f6352 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tephra/tree/e56f6352 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tephra/diff/e56f6352 Branch: refs/heads/master Commit: e56f635231c8281ee656cb53576433491e362742 Parents: 99c7bec Author: poorna <[email protected]> Authored: Fri Oct 28 17:46:01 2016 -0700 Committer: poorna <[email protected]> Committed: Tue Nov 8 17:30:47 2016 -0800 ---------------------------------------------------------------------- tephra-hbase-compat-1.1-base/pom.xml | 5 + .../tephra/hbase/AbstractHBaseTableTest.java | 107 +++++++++++++++++++ .../hbase/TransactionAwareHTableTest.java | 75 ++----------- 3 files changed, 123 insertions(+), 64 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tephra/blob/e56f6352/tephra-hbase-compat-1.1-base/pom.xml ---------------------------------------------------------------------- diff --git a/tephra-hbase-compat-1.1-base/pom.xml b/tephra-hbase-compat-1.1-base/pom.xml index b0eee6d..b6a58e0 100644 --- a/tephra-hbase-compat-1.1-base/pom.xml +++ b/tephra-hbase-compat-1.1-base/pom.xml @@ -28,6 +28,11 @@ <artifactId>tephra-hbase-compat-1.1-base</artifactId> <name>Apache Tephra HBase 1.1 Compatibility Base</name> + <properties> + <hadoop.version>2.5.1</hadoop.version> + <hbase11.version>1.1.1</hbase11.version> + </properties> + <packaging>pom</packaging> <modules> <module>tephra-hbase-compat-1.2-cdh</module> http://git-wip-us.apache.org/repos/asf/incubator-tephra/blob/e56f6352/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/AbstractHBaseTableTest.java ---------------------------------------------------------------------- diff --git a/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/AbstractHBaseTableTest.java b/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/AbstractHBaseTableTest.java new file mode 100644 index 0000000..68c43ae --- /dev/null +++ b/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/AbstractHBaseTableTest.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tephra.hbase; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.Coprocessor; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.client.HTable; +import org.apache.tephra.TxConstants; +import org.apache.tephra.hbase.coprocessor.TransactionProcessor; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +import java.util.Collections; +import java.util.List; + +/** + * + */ +@SuppressWarnings("WeakerAccess") +public abstract class AbstractHBaseTableTest { + static HBaseTestingUtility testUtil; + static HBaseAdmin hBaseAdmin; + static Configuration conf; + + @BeforeClass + public static void startMiniCluster() throws Exception { + testUtil = new HBaseTestingUtility(); + conf = testUtil.getConfiguration(); + + // Tune down the connection thread pool size + conf.setInt("hbase.hconnection.threads.core", 5); + conf.setInt("hbase.hconnection.threads.max", 10); + // Tunn down handler threads in regionserver + conf.setInt("hbase.regionserver.handler.count", 10); + + // Set to random port + conf.setInt("hbase.master.port", 0); + conf.setInt("hbase.master.info.port", 0); + conf.setInt("hbase.regionserver.port", 0); + conf.setInt("hbase.regionserver.info.port", 0); + + testUtil.startMiniCluster(); + hBaseAdmin = testUtil.getHBaseAdmin(); + } + + @AfterClass + public static void shutdownMiniCluster() throws Exception { + try { + if (hBaseAdmin != null) { + hBaseAdmin.close(); + } + } finally { + testUtil.shutdownMiniCluster(); + } + } + + static HTable createTable(byte[] tableName, byte[][] columnFamilies) throws Exception { + return createTable(tableName, columnFamilies, false, + Collections.singletonList(TransactionProcessor.class.getName())); + } + + static HTable createTable(byte[] tableName, byte[][] columnFamilies, boolean existingData, + List<String> coprocessors) throws Exception { + HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); + for (byte[] family : columnFamilies) { + HColumnDescriptor columnDesc = new HColumnDescriptor(family); + columnDesc.setMaxVersions(Integer.MAX_VALUE); + columnDesc.setValue(TxConstants.PROPERTY_TTL, String.valueOf(100000)); // in millis + desc.addFamily(columnDesc); + } + if (existingData) { + desc.setValue(TxConstants.READ_NON_TX_DATA, "true"); + } + // Divide individually to prevent any overflow + int priority = Coprocessor.PRIORITY_USER; + // order in list is the same order that coprocessors will be invoked + for (String coprocessor : coprocessors) { + desc.addCoprocessor(coprocessor, null, ++priority, null); + } + hBaseAdmin.createTable(desc); + testUtil.waitTableAvailable(tableName, 5000); + return new HTable(testUtil.getConfiguration(), tableName); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tephra/blob/e56f6352/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java ---------------------------------------------------------------------- diff --git a/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java b/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java index de1fa6b..c336712 100644 --- a/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java +++ b/tephra-hbase-compat-1.1-base/src/test/java/org/apache/tephra/hbase/TransactionAwareHTableTest.java @@ -19,21 +19,14 @@ package org.apache.tephra.hbase; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.Coprocessor; import org.apache.hadoop.hbase.DoNotRetryIOException; -import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Durability; import org.apache.hadoop.hbase.client.Get; -import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.HTableInterface; import org.apache.hadoop.hbase.client.OperationWithAttributes; @@ -89,14 +82,11 @@ import static org.junit.Assert.fail; /** * Tests for TransactionAwareHTables. */ -public class TransactionAwareHTableTest { +public class TransactionAwareHTableTest extends AbstractHBaseTableTest { private static final Logger LOG = LoggerFactory.getLogger(TransactionAwareHTableTest.class); - private static HBaseTestingUtility testUtil; - private static HBaseAdmin hBaseAdmin; - private static TransactionStateStorage txStateStorage; - private static TransactionManager txManager; - private static Configuration conf; + static TransactionStateStorage txStateStorage; + static TransactionManager txManager; private TransactionContext transactionContext; private TransactionAwareHTable transactionAwareHTable; private HTable hTable; @@ -146,23 +136,6 @@ public class TransactionAwareHTableTest { @BeforeClass public static void setupBeforeClass() throws Exception { - testUtil = new HBaseTestingUtility(); - conf = testUtil.getConfiguration(); - - // Tune down the connection thread pool size - conf.setInt("hbase.hconnection.threads.core", 5); - conf.setInt("hbase.hconnection.threads.max", 10); - // Tunn down handler threads in regionserver - conf.setInt("hbase.regionserver.handler.count", 10); - - // Set to random port - conf.setInt("hbase.master.port", 0); - conf.setInt("hbase.master.info.port", 0); - conf.setInt("hbase.regionserver.port", 0); - conf.setInt("hbase.regionserver.info.port", 0); - - testUtil.startMiniCluster(); - hBaseAdmin = testUtil.getHBaseAdmin(); txStateStorage = new InMemoryTransactionStateStorage(); txManager = new TransactionManager(conf, txStateStorage, new TxMetricsCollector()); txManager.startAndWait(); @@ -170,8 +143,9 @@ public class TransactionAwareHTableTest { @AfterClass public static void shutdownAfterClass() throws Exception { - testUtil.shutdownMiniCluster(); - hBaseAdmin.close(); + if (txManager != null) { + txManager.stopAndWait(); + } } @Before @@ -187,34 +161,6 @@ public class TransactionAwareHTableTest { hBaseAdmin.deleteTable(TestBytes.table); } - private HTable createTable(byte[] tableName, byte[][] columnFamilies) throws Exception { - return createTable(tableName, columnFamilies, false, Collections.<String>emptyList()); - } - - private HTable createTable(byte[] tableName, byte[][] columnFamilies, boolean existingData, - List<String> coprocessors) throws Exception { - HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); - for (byte[] family : columnFamilies) { - HColumnDescriptor columnDesc = new HColumnDescriptor(family); - columnDesc.setMaxVersions(Integer.MAX_VALUE); - columnDesc.setValue(TxConstants.PROPERTY_TTL, String.valueOf(100000)); // in millis - desc.addFamily(columnDesc); - } - if (existingData) { - desc.setValue(TxConstants.READ_NON_TX_DATA, "true"); - } - // Divide individually to prevent any overflow - int priority = Coprocessor.PRIORITY_USER; - desc.addCoprocessor(TransactionProcessor.class.getName(), null, priority, null); - // order in list is the same order that coprocessors will be invoked - for (String coprocessor : coprocessors) { - desc.addCoprocessor(coprocessor, null, ++priority, null); - } - hBaseAdmin.createTable(desc); - testUtil.waitTableAvailable(tableName, 5000); - return new HTable(testUtil.getConfiguration(), tableName); - } - /** * Test transactional put and get requests. * @@ -406,7 +352,7 @@ public class TransactionAwareHTableTest { public void testAttributesPreserved() throws Exception { HTable hTable = createTable(Bytes.toBytes("TestAttributesPreserved"), new byte[][]{TestBytes.family, TestBytes.family2}, false, - Lists.newArrayList(TestRegionObserver.class.getName())); + Lists.newArrayList(TransactionProcessor.class.getName(), TestRegionObserver.class.getName())); try { TransactionAwareHTable txTable = new TransactionAwareHTable(hTable); TransactionContext txContext = new TransactionContext(new InMemoryTxSystemClient(txManager), txTable); @@ -1117,7 +1063,7 @@ public class TransactionAwareHTableTest { TransactionAwareHTable txTable = new TransactionAwareHTable(createTable(Bytes.toBytes("testExistingData"), new byte[][]{TestBytes.family}, true, - Collections.<String>emptyList())); + Collections.singletonList(TransactionProcessor.class.getName()))); TransactionContext txContext = new TransactionContext(new InMemoryTxSystemClient(txManager), txTable); // Add some pre-existing, non-transactional data @@ -1266,8 +1212,9 @@ public class TransactionAwareHTableTest { @Test public void testVisibilityAll() throws Exception { - HTable nonTxTable = createTable(Bytes.toBytes("testVisibilityAll"), - new byte[][]{TestBytes.family, TestBytes.family2}, true, Collections.<String>emptyList()); + HTable nonTxTable = + createTable(Bytes.toBytes("testVisibilityAll"), new byte[][]{TestBytes.family, TestBytes.family2}, + true, Collections.singletonList(TransactionProcessor.class.getName())); TransactionAwareHTable txTable = new TransactionAwareHTable(nonTxTable, TxConstants.ConflictDetection.ROW); // ROW conflict detection to verify family deletes
