HBASE-5887 Make TestAcidGuarantees usable for system testing

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1333785 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Hsieh 2012-05-04 07:15:23 +00:00
parent 07082e8f69
commit 8c47119bcd
1 changed files with 61 additions and 16 deletions

View File

@ -27,8 +27,8 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.MultithreadedTestUtil.TestContext;
import org.apache.hadoop.hbase.MultithreadedTestUtil.RepeatingTestThread;
import org.apache.hadoop.hbase.MultithreadedTestUtil.TestContext;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
@ -36,11 +36,12 @@ import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Ignore;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.google.common.collect.Lists;
import org.junit.experimental.categories.Category;
/**
* Test case that uses multiple threads to read and write multifamily rows
@ -50,7 +51,7 @@ import org.junit.experimental.categories.Category;
* a real cluster (eg for testing with failures, region movement, etc)
*/
@Category(MediumTests.class)
public class TestAcidGuarantees {
public class TestAcidGuarantees implements Tool {
protected static final Log LOG = LogFactory.getLog(TestAcidGuarantees.class);
public static final byte [] TABLE_NAME = Bytes.toBytes("TestAcidGuarantees");
public static final byte [] FAMILY_A = Bytes.toBytes("A");
@ -65,6 +66,9 @@ public class TestAcidGuarantees {
public static int NUM_COLS_TO_CHECK = 50;
// when run as main
private Configuration conf;
private void createTableIfMissing()
throws IOException {
try {
@ -237,6 +241,15 @@ public class TestAcidGuarantees {
int numGetters,
int numScanners,
int numUniqueRows) throws Exception {
runTestAtomicity(millisToRun, numWriters, numGetters, numScanners,
numUniqueRows, true);
}
public void runTestAtomicity(long millisToRun,
int numWriters,
int numGetters,
int numScanners,
int numUniqueRows, boolean useFlusher) throws Exception {
createTableIfMissing();
TestContext ctx = new TestContext(util.getConfiguration());
@ -253,11 +266,13 @@ public class TestAcidGuarantees {
ctx.addThread(writer);
}
// Add a flusher
if (useFlusher) {
ctx.addThread(new RepeatingTestThread(ctx) {
public void doAnAction() throws Exception {
util.flush();
}
});
}
List<AtomicGetReader> getters = Lists.newArrayList();
for (int i = 0; i < numGetters; i++) {
@ -323,17 +338,47 @@ public class TestAcidGuarantees {
}
}
public static void main(String args[]) throws Exception {
Configuration c = HBaseConfiguration.create();
TestAcidGuarantees test = new TestAcidGuarantees();
test.setConf(c);
test.runTestAtomicity(5000, 50, 2, 2, 3);
////////////////////////////////////////////////////////////////////////////
// Tool interface
////////////////////////////////////////////////////////////////////////////
@Override
public Configuration getConf() {
return conf;
}
private void setConf(Configuration c) {
util = new HBaseTestingUtility(c);
@Override
public void setConf(Configuration c) {
this.conf = c;
this.util = new HBaseTestingUtility(c);
}
@Override
public int run(String[] arg0) throws Exception {
Configuration c = getConf();
int millis = c.getInt("millis", 5000);
int numWriters = c.getInt("numWriters", 50);
int numGetters = c.getInt("numGetters", 2);
int numScanners = c.getInt("numScanners", 2);
int numUniqueRows = c.getInt("numUniqueRows", 3);
// cannot run flusher in real cluster case.
runTestAtomicity(millis, numWriters, numGetters, numScanners, numUniqueRows, false);
return 0;
}
public static void main(String args[]) throws Exception {
Configuration c = HBaseConfiguration.create();
int status;
try {
TestAcidGuarantees test = new TestAcidGuarantees();
status = ToolRunner.run(c, test, args);
} catch (Exception e) {
LOG.error("Exiting due to error", e);
status = -1;
}
System.exit(status);
}
@org.junit.Rule
public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();