HBASE-23623 Reduced the number of Checkstyle violations in hbase-rest

Signed-off-by: stack <stack@apache.org>
Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Jan Hentschel 2020-01-02 00:39:54 +01:00 committed by GitHub
parent d86778f4ff
commit e8d2931bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 192 additions and 251 deletions

View File

@ -40,6 +40,7 @@ import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.CompareOperator; import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
@ -48,7 +49,6 @@ import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.client.BufferedMutator; import org.apache.hadoop.hbase.client.BufferedMutator;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.ConnectionFactory;
@ -121,8 +121,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
private static final int ROWS_PER_GB = ONE_GB / ROW_LENGTH; private static final int ROWS_PER_GB = ONE_GB / ROW_LENGTH;
public static final TableName TABLE_NAME = TableName.valueOf("TestTable"); public static final TableName TABLE_NAME = TableName.valueOf("TestTable");
public static final byte [] FAMILY_NAME = Bytes.toBytes("info"); public static final byte[] FAMILY_NAME = Bytes.toBytes("info");
public static final byte [] QUALIFIER_NAME = Bytes.toBytes("data"); public static final byte[] QUALIFIER_NAME = Bytes.toBytes("data");
private TableName tableName = TABLE_NAME; private TableName tableName = TABLE_NAME;
protected HTableDescriptor TABLE_DESCRIPTOR; protected HTableDescriptor TABLE_DESCRIPTOR;
@ -144,6 +144,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
private Connection connection; private Connection connection;
private static final Path PERF_EVAL_DIR = new Path("performance_evaluation"); private static final Path PERF_EVAL_DIR = new Path("performance_evaluation");
/** /**
* Regex to parse lines in input file passed to mapreduce task. * Regex to parse lines in input file passed to mapreduce task.
*/ */
@ -162,11 +163,12 @@ public class PerformanceEvaluation extends Configured implements Tool {
* Enum for map metrics. Keep it out here rather than inside in the Map * Enum for map metrics. Keep it out here rather than inside in the Map
* inner-class so we can find associated properties. * inner-class so we can find associated properties.
*/ */
protected static enum Counter { protected enum Counter {
/** elapsed time */ /** elapsed time */
ELAPSED_TIME, ELAPSED_TIME,
/** number of rows */ /** number of rows */
ROWS} ROWS
}
/** /**
* Constructor * Constructor
@ -214,7 +216,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
/** /**
* Sets status * Sets status
* @param msg status message * @param msg status message
* @throws IOException * @throws IOException if setting the status fails
*/ */
void setStatus(final String msg) throws IOException; void setStatus(final String msg) throws IOException;
} }
@ -226,18 +228,15 @@ public class PerformanceEvaluation extends Configured implements Tool {
* the record value is the PeInputSplit itself. * the record value is the PeInputSplit itself.
*/ */
public static class PeInputSplit extends InputSplit implements Writable { public static class PeInputSplit extends InputSplit implements Writable {
private TableName tableName = TABLE_NAME; private TableName tableName;
private int startRow = 0; private int startRow;
private int rows = 0; private int rows;
private int totalRows = 0; private int totalRows;
private int clients = 0; private int clients;
private boolean flushCommits = false; private boolean flushCommits;
private boolean writeToWAL = true; private boolean writeToWAL;
private boolean useTags = false; private boolean useTags;
private int noOfTags = 0; private int noOfTags;
public PeInputSplit() {
}
public PeInputSplit(TableName tableName, int startRow, int rows, int totalRows, int clients, public PeInputSplit(TableName tableName, int startRow, int rows, int totalRows, int clients,
boolean flushCommits, boolean writeToWAL, boolean useTags, int noOfTags) { boolean flushCommits, boolean writeToWAL, boolean useTags, int noOfTags) {
@ -284,12 +283,12 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
@Override @Override
public long getLength() throws IOException, InterruptedException { public long getLength() {
return 0; return 0;
} }
@Override @Override
public String[] getLocations() throws IOException, InterruptedException { public String[] getLocations() {
return new String[0]; return new String[0];
} }
@ -309,10 +308,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
return totalRows; return totalRows;
} }
public int getClients() {
return clients;
}
public boolean isFlushCommits() { public boolean isFlushCommits() {
return flushCommits; return flushCommits;
} }
@ -335,7 +330,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
* It extends from FileInputFormat, want to use it's methods such as setInputPaths(). * It extends from FileInputFormat, want to use it's methods such as setInputPaths().
*/ */
public static class PeInputFormat extends FileInputFormat<NullWritable, PeInputSplit> { public static class PeInputFormat extends FileInputFormat<NullWritable, PeInputSplit> {
@Override @Override
public List<InputSplit> getSplits(JobContext job) throws IOException { public List<InputSplit> getSplits(JobContext job) throws IOException {
// generate splits // generate splits
@ -349,7 +343,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
FileSystem fs = path.getFileSystem(job.getConfiguration()); FileSystem fs = path.getFileSystem(job.getConfiguration());
FSDataInputStream fileIn = fs.open(path); FSDataInputStream fileIn = fs.open(path);
LineReader in = new LineReader(fileIn, job.getConfiguration()); LineReader in = new LineReader(fileIn, job.getConfiguration());
int lineLen = 0; int lineLen;
while(true) { while(true) {
Text lineText = new Text(); Text lineText = new Text();
lineLen = in.readLine(lineText); lineLen = in.readLine(lineText);
@ -357,7 +351,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
break; break;
} }
Matcher m = LINE_PATTERN.matcher(lineText.toString()); Matcher m = LINE_PATTERN.matcher(lineText.toString());
if((m != null) && m.matches()) { if ((m != null) && m.matches()) {
TableName tableName = TableName.valueOf(m.group(1)); TableName tableName = TableName.valueOf(m.group(1));
int startRow = Integer.parseInt(m.group(2)); int startRow = Integer.parseInt(m.group(2));
int rows = Integer.parseInt(m.group(3)); int rows = Integer.parseInt(m.group(3));
@ -405,14 +399,13 @@ public class PerformanceEvaluation extends Configured implements Tool {
private PeInputSplit value = null; private PeInputSplit value = null;
@Override @Override
public void initialize(InputSplit split, TaskAttemptContext context) public void initialize(InputSplit split, TaskAttemptContext context) {
throws IOException, InterruptedException {
this.readOver = false; this.readOver = false;
this.split = (PeInputSplit)split; this.split = (PeInputSplit)split;
} }
@Override @Override
public boolean nextKeyValue() throws IOException, InterruptedException { public boolean nextKeyValue() {
if(readOver) { if(readOver) {
return false; return false;
} }
@ -425,17 +418,17 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
@Override @Override
public NullWritable getCurrentKey() throws IOException, InterruptedException { public NullWritable getCurrentKey() {
return key; return key;
} }
@Override @Override
public PeInputSplit getCurrentValue() throws IOException, InterruptedException { public PeInputSplit getCurrentValue() {
return value; return value;
} }
@Override @Override
public float getProgress() throws IOException, InterruptedException { public float getProgress() {
if(readOver) { if(readOver) {
return 1.0f; return 1.0f;
} else { } else {
@ -444,7 +437,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
@Override @Override
public void close() throws IOException { public void close() {
// do nothing // do nothing
} }
} }
@ -465,7 +458,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
private PerformanceEvaluation pe; private PerformanceEvaluation pe;
@Override @Override
protected void setup(Context context) throws IOException, InterruptedException { protected void setup(Context context) {
this.cmd = forName(context.getConfiguration().get(CMD_KEY), Test.class); this.cmd = forName(context.getConfiguration().get(CMD_KEY), Test.class);
// this is required so that extensions of PE are instantiated within the // this is required so that extensions of PE are instantiated within the
@ -481,7 +474,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
private <Type> Class<? extends Type> forName(String className, Class<Type> type) { private <Type> Class<? extends Type> forName(String className, Class<Type> type) {
Class<? extends Type> clazz = null; Class<? extends Type> clazz;
try { try {
clazz = Class.forName(className).asSubclass(type); clazz = Class.forName(className).asSubclass(type);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
@ -493,13 +486,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
@Override @Override
protected void map(NullWritable key, PeInputSplit value, final Context context) protected void map(NullWritable key, PeInputSplit value, final Context context)
throws IOException, InterruptedException { throws IOException, InterruptedException {
Status status = context::setStatus;
Status status = new Status() {
@Override
public void setStatus(String msg) {
context.setStatus(msg);
}
};
// Evaluation task // Evaluation task
pe.tableName = value.getTableName(); pe.tableName = value.getTableName();
@ -517,11 +504,11 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
} }
/* /**
* If table does not already exist, create. * If table does not already exist, create.
* @param c Client to use checking. * @param admin Client to use checking.
* @return True if we created the table. * @return True if we created the table.
* @throws IOException * @throws IOException if an operation on the table fails
*/ */
private boolean checkTable(RemoteAdmin admin) throws IOException { private boolean checkTable(RemoteAdmin admin) throws IOException {
HTableDescriptor tableDescriptor = getDescriptor(); HTableDescriptor tableDescriptor = getDescriptor();
@ -536,7 +523,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
LOG.debug(" split " + i + ": " + Bytes.toStringBinary(splits[i])); LOG.debug(" split " + i + ": " + Bytes.toStringBinary(splits[i]));
} }
admin.createTable(tableDescriptor); admin.createTable(tableDescriptor);
LOG.info ("Table created with " + this.presplitRegions + " splits"); LOG.info("Table created with " + this.presplitRegions + " splits");
} else { } else {
boolean tableExists = admin.isTableAvailable(tableDescriptor.getTableName().getName()); boolean tableExists = admin.isTableAvailable(tableDescriptor.getTableName().getName());
if (!tableExists) { if (!tableExists) {
@ -544,8 +531,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
LOG.info("Table " + tableDescriptor + " created"); LOG.info("Table " + tableDescriptor + " created");
} }
} }
boolean tableExists = admin.isTableAvailable(tableDescriptor.getTableName().getName());
return tableExists; return admin.isTableAvailable(tableDescriptor.getTableName().getName());
} }
protected HTableDescriptor getDescriptor() { protected HTableDescriptor getDescriptor() {
@ -568,8 +555,9 @@ public class PerformanceEvaluation extends Configured implements Tool {
* @return splits : array of byte [] * @return splits : array of byte []
*/ */
protected byte[][] getSplits() { protected byte[][] getSplits() {
if (this.presplitRegions == 0) if (this.presplitRegions == 0) {
return new byte [0][]; return new byte[0][];
}
int numSplitPoints = presplitRegions - 1; int numSplitPoints = presplitRegions - 1;
byte[][] splits = new byte[numSplitPoints][]; byte[][] splits = new byte[numSplitPoints][];
@ -581,11 +569,10 @@ public class PerformanceEvaluation extends Configured implements Tool {
return splits; return splits;
} }
/* /**
* We're to run multiple clients concurrently. Setup a mapreduce job. Run * We're to run multiple clients concurrently. Setup a mapreduce job. Run
* one map per client. Then run a single reduce to sum the elapsed times. * one map per client. Then run a single reduce to sum the elapsed times.
* @param cmd Command to run. * @param cmd Command to run.
* @throws IOException
*/ */
private void runNIsMoreThanOne(final Class<? extends Test> cmd) private void runNIsMoreThanOne(final Class<? extends Test> cmd)
throws IOException, InterruptedException, ClassNotFoundException { throws IOException, InterruptedException, ClassNotFoundException {
@ -598,10 +585,10 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
} }
/* /**
* Run all clients in this vm each to its own thread. * Run all clients in this vm each to its own thread.
* @param cmd Command to run. * @param cmd Command to run
* @throws IOException * @throws IOException if creating a connection fails
*/ */
private void doMultipleClients(final Class<? extends Test> cmd) throws IOException { private void doMultipleClients(final Class<? extends Test> cmd) throws IOException {
final List<Thread> threads = new ArrayList<>(this.N); final List<Thread> threads = new ArrayList<>(this.N);
@ -618,7 +605,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
final Connection connection = ConnectionFactory.createConnection(getConf()); final Connection connection = ConnectionFactory.createConnection(getConf());
for (int i = 0; i < this.N; i++) { for (int i = 0; i < this.N; i++) {
final int index = i; final int index = i;
Thread t = new Thread ("TestClient-" + i) { Thread t = new Thread("TestClient-" + i) {
@Override @Override
public void run() { public void run() {
super.run(); super.run();
@ -636,12 +623,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
try { try {
long elapsedTime = pe.runOneClient(cmd, index * perClientRows, long elapsedTime = pe.runOneClient(cmd, index * perClientRows,
perClientRows, R, perClientRows, R,
flushCommits, writeToWAL, useTags, noOfTags, connection, new Status() { flushCommits, writeToWAL, useTags, noOfTags, connection,
@Override msg -> LOG.info("client-" + getName() + " " + msg));
public void setStatus(final String msg) throws IOException {
LOG.info("client-" + getName() + " " + msg);
}
});
timings[index] = elapsedTime; timings[index] = elapsedTime;
LOG.info("Finished " + getName() + " in " + elapsedTime + LOG.info("Finished " + getName() + " in " + elapsedTime +
"ms writing " + perClientRows + " rows"); "ms writing " + perClientRows + " rows");
@ -678,15 +661,14 @@ public class PerformanceEvaluation extends Configured implements Tool {
+ "\tAvg: " + (total / this.N) + "ms"); + "\tAvg: " + (total / this.N) + "ms");
} }
/* /**
* Run a mapreduce job. Run as many maps as asked-for clients. * Run a mapreduce job. Run as many maps as asked-for clients.
* Before we start up the job, write out an input file with instruction * Before we start up the job, write out an input file with instruction
* per client regards which row they are to start on. * per client regards which row they are to start on.
* @param cmd Command to run. * @param cmd Command to run.
* @throws IOException
*/ */
private void doMapReduce(final Class<? extends Test> cmd) throws IOException, private void doMapReduce(final Class<? extends Test> cmd)
InterruptedException, ClassNotFoundException { throws IOException, InterruptedException, ClassNotFoundException {
Configuration conf = getConf(); Configuration conf = getConf();
Path inputDir = writeInputFile(conf); Path inputDir = writeInputFile(conf);
conf.set(EvaluationMapTask.CMD_KEY, cmd.getName()); conf.set(EvaluationMapTask.CMD_KEY, cmd.getName());
@ -712,11 +694,11 @@ public class PerformanceEvaluation extends Configured implements Tool {
job.waitForCompletion(true); job.waitForCompletion(true);
} }
/* /**
* Write input file of offsets-per-client for the mapreduce job. * Write input file of offsets-per-client for the mapreduce job.
* @param c Configuration * @param c Configuration
* @return Directory that contains file written. * @return Directory that contains file written.
* @throws IOException * @throws IOException if creating the directory or the file fails
*/ */
private Path writeInputFile(final Configuration c) throws IOException { private Path writeInputFile(final Configuration c) throws IOException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
@ -785,31 +767,26 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
/** /**
* Wraps up options passed to {@link org.apache.hadoop.hbase.PerformanceEvaluation.Test * Wraps up options passed to {@link org.apache.hadoop.hbase.PerformanceEvaluation} tests
* tests}. This makes the reflection logic a little easier to understand... * This makes the reflection logic a little easier to understand...
*/ */
static class TestOptions { static class TestOptions {
private int startRow; private int startRow;
private int perClientRunRows; private int perClientRunRows;
private int totalRows; private int totalRows;
private int numClientThreads;
private TableName tableName; private TableName tableName;
private boolean flushCommits; private boolean flushCommits;
private boolean writeToWAL = true; private boolean writeToWAL;
private boolean useTags = false; private boolean useTags;
private int noOfTags = 0; private int noOfTags;
private Connection connection; private Connection connection;
TestOptions() { TestOptions(int startRow, int perClientRunRows, int totalRows, TableName tableName,
} boolean flushCommits, boolean writeToWAL, boolean useTags,
TestOptions(int startRow, int perClientRunRows, int totalRows, int numClientThreads,
TableName tableName, boolean flushCommits, boolean writeToWAL, boolean useTags,
int noOfTags, Connection connection) { int noOfTags, Connection connection) {
this.startRow = startRow; this.startRow = startRow;
this.perClientRunRows = perClientRunRows; this.perClientRunRows = perClientRunRows;
this.totalRows = totalRows; this.totalRows = totalRows;
this.numClientThreads = numClientThreads;
this.tableName = tableName; this.tableName = tableName;
this.flushCommits = flushCommits; this.flushCommits = flushCommits;
this.writeToWAL = writeToWAL; this.writeToWAL = writeToWAL;
@ -830,10 +807,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
return totalRows; return totalRows;
} }
public int getNumClientThreads() {
return numClientThreads;
}
public TableName getTableName() { public TableName getTableName() {
return tableName; return tableName;
} }
@ -912,10 +885,11 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
abstract void testTakedown() throws IOException; abstract void testTakedown() throws IOException;
/*
/**
* Run test * Run test
* @return Elapsed time. * @return Elapsed time.
* @throws IOException * @throws IOException if something in the test fails
*/ */
long test() throws IOException { long test() throws IOException {
testSetup(); testSetup();
@ -945,7 +919,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
} }
/* /**
* Test for individual row. * Test for individual row.
* @param i Row index. * @param i Row index.
*/ */
@ -1012,7 +986,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
int period = this.perClientRunRows / 100; int period = this.perClientRunRows / 100;
return period == 0? this.perClientRunRows: period; return period == 0? this.perClientRunRows: period;
} }
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -1041,7 +1014,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
s.close(); s.close();
} }
protected abstract Pair<byte[],byte[]> getStartAndStopRow(); protected abstract Pair<byte[], byte[]> getStartAndStopRow();
protected Pair<byte[], byte[]> generateStartAndStopRows(int maxRange) { protected Pair<byte[], byte[]> generateStartAndStopRows(int maxRange) {
int start = this.rand.nextInt(Integer.MAX_VALUE) % totalRows; int start = this.rand.nextInt(Integer.MAX_VALUE) % totalRows;
@ -1117,7 +1090,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
int period = this.perClientRunRows / 100; int period = this.perClientRunRows / 100;
return period == 0? this.perClientRunRows: period; return period == 0? this.perClientRunRows: period;
} }
} }
static class RandomWriteTest extends BufferedMutatorTest { static class RandomWriteTest extends BufferedMutatorTest {
@ -1163,7 +1135,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
super.testTakedown(); super.testTakedown();
} }
@Override @Override
void testRow(final int i) throws IOException { void testRow(final int i) throws IOException {
if (this.testScanner == null) { if (this.testScanner == null) {
@ -1173,7 +1144,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
testScanner.next(); testScanner.next();
} }
} }
static class SequentialReadTest extends TableTest { static class SequentialReadTest extends TableTest {
@ -1187,11 +1157,9 @@ public class PerformanceEvaluation extends Configured implements Tool {
get.addColumn(FAMILY_NAME, QUALIFIER_NAME); get.addColumn(FAMILY_NAME, QUALIFIER_NAME);
table.get(get); table.get(get);
} }
} }
static class SequentialWriteTest extends BufferedMutatorTest { static class SequentialWriteTest extends BufferedMutatorTest {
SequentialWriteTest(Configuration conf, TestOptions options, Status status) { SequentialWriteTest(Configuration conf, TestOptions options, Status status) {
super(conf, options, status); super(conf, options, status);
} }
@ -1236,11 +1204,13 @@ public class PerformanceEvaluation extends Configured implements Tool {
while (scanner.next() != null) { while (scanner.next() != null) {
} }
} finally { } finally {
if (scanner != null) scanner.close(); if (scanner != null) {
scanner.close();
}
} }
} }
protected Scan constructScan(byte[] valuePrefix) throws IOException { protected Scan constructScan(byte[] valuePrefix) {
Filter filter = new SingleColumnValueFilter( Filter filter = new SingleColumnValueFilter(
FAMILY_NAME, QUALIFIER_NAME, CompareOperator.EQUAL, FAMILY_NAME, QUALIFIER_NAME, CompareOperator.EQUAL,
new BinaryComparator(valuePrefix) new BinaryComparator(valuePrefix)
@ -1252,14 +1222,14 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
} }
/* /**
* Format passed integer. * Format passed integer.
* @param number * @param number the integer to format
* @return Returns zero-prefixed 10-byte wide decimal version of passed * @return Returns zero-prefixed 10-byte wide decimal version of passed number (Does absolute in
* number (Does absolute in case number is negative). * case number is negative).
*/ */
public static byte [] format(final int number) { public static byte [] format(final int number) {
byte [] b = new byte[DEFAULT_ROW_PREFIX_LENGTH + 10]; byte[] b = new byte[DEFAULT_ROW_PREFIX_LENGTH + 10];
int d = Math.abs(number); int d = Math.abs(number);
for (int i = b.length - 1; i >= 0; i--) { for (int i = b.length - 1; i >= 0; i--) {
b[i] = (byte)((d % 10) + '0'); b[i] = (byte)((d % 10) + '0');
@ -1269,10 +1239,10 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
public static byte[] generateData(final Random r, int length) { public static byte[] generateData(final Random r, int length) {
byte [] b = new byte [length]; byte[] b = new byte [length];
int i = 0; int i;
for(i = 0; i < (length-8); i += 8) { for (i = 0; i < (length-8); i += 8) {
b[i] = (byte) (65 + r.nextInt(26)); b[i] = (byte) (65 + r.nextInt(26));
b[i+1] = b[i]; b[i+1] = b[i];
b[i+2] = b[i]; b[i+2] = b[i];
@ -1284,7 +1254,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
byte a = (byte) (65 + r.nextInt(26)); byte a = (byte) (65 + r.nextInt(26));
for(; i < length; i++) { for (; i < length; i++) {
b[i] = a; b[i] = a;
} }
return b; return b;
@ -1296,21 +1266,20 @@ public class PerformanceEvaluation extends Configured implements Tool {
return b; return b;
} }
static byte [] getRandomRow(final Random random, final int totalRows) { static byte[] getRandomRow(final Random random, final int totalRows) {
return format(random.nextInt(Integer.MAX_VALUE) % totalRows); return format(random.nextInt(Integer.MAX_VALUE) % totalRows);
} }
long runOneClient(final Class<? extends Test> cmd, final int startRow, long runOneClient(final Class<? extends Test> cmd, final int startRow,
final int perClientRunRows, final int totalRows, final int perClientRunRows, final int totalRows,
boolean flushCommits, boolean writeToWAL, boolean useTags, int noOfTags, boolean flushCommits, boolean writeToWAL, boolean useTags, int noOfTags,
Connection connection, final Status status) Connection connection, final Status status) throws IOException {
throws IOException {
status.setStatus("Start " + cmd + " at offset " + startRow + " for " + status.setStatus("Start " + cmd + " at offset " + startRow + " for " +
perClientRunRows + " rows"); perClientRunRows + " rows");
long totalElapsedTime = 0; long totalElapsedTime;
TestOptions options = new TestOptions(startRow, perClientRunRows, TestOptions options = new TestOptions(startRow, perClientRunRows,
totalRows, N, tableName, flushCommits, writeToWAL, useTags, noOfTags, connection); totalRows, tableName, flushCommits, writeToWAL, useTags, noOfTags, connection);
final Test t; final Test t;
try { try {
Constructor<? extends Test> constructor = cmd.getDeclaredConstructor( Constructor<? extends Test> constructor = cmd.getDeclaredConstructor(
@ -1332,14 +1301,9 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
private void runNIsOne(final Class<? extends Test> cmd) { private void runNIsOne(final Class<? extends Test> cmd) {
Status status = new Status() { Status status = LOG::info;
@Override
public void setStatus(String msg) throws IOException {
LOG.info(msg);
}
};
RemoteAdmin admin = null; RemoteAdmin admin;
try { try {
Client client = new Client(cluster); Client client = new Client(cluster);
admin = new RemoteAdmin(client, getConf()); admin = new RemoteAdmin(client, getConf());
@ -1351,8 +1315,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
} }
private void runTest(final Class<? extends Test> cmd) throws IOException, private void runTest(final Class<? extends Test> cmd)
InterruptedException, ClassNotFoundException { throws IOException, InterruptedException, ClassNotFoundException {
if (N == 1) { if (N == 1) {
// If there is only one client and one HRegionServer, we assume nothing // If there is only one client and one HRegionServer, we assume nothing
// has been set up at all. // has been set up at all.
@ -1419,7 +1383,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
} }
private void getArgs(final int start, final String[] args) { private void getArgs(final int start, final String[] args) {
if(start + 1 > args.length) { if (start + 1 > args.length) {
throw new IllegalArgumentException("must supply the number of clients"); throw new IllegalArgumentException("must supply the number of clients");
} }
N = Integer.parseInt(args[start]); N = Integer.parseInt(args[start]);
@ -1554,9 +1518,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
return descriptor != null ? descriptor.getCmdClass() : null; return descriptor != null ? descriptor.getCmdClass() : null;
} }
/**
* @param args
*/
public static void main(final String[] args) throws Exception { public static void main(final String[] args) throws Exception {
int res = ToolRunner.run(new PerformanceEvaluation(HBaseConfiguration.create()), args); int res = ToolRunner.run(new PerformanceEvaluation(HBaseConfiguration.create()), args);
System.exit(res); System.exit(res);

View File

@ -46,7 +46,6 @@ import org.junit.experimental.categories.Category;
@Category({RestTests.class, MediumTests.class}) @Category({RestTests.class, MediumTests.class})
public class TestGetAndPutResource extends RowResourceBase { public class TestGetAndPutResource extends RowResourceBase {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestGetAndPutResource.class); HBaseClassTestRule.forClass(TestGetAndPutResource.class);
@ -134,7 +133,7 @@ public class TestGetAndPutResource extends RowResourceBase {
} }
@Test @Test
public void testMultipleCellCheckPutPB() throws IOException, JAXBException { public void testMultipleCellCheckPutPB() throws IOException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1); Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(404, response.getCode()); assertEquals(404, response.getCode());
@ -200,7 +199,7 @@ public class TestGetAndPutResource extends RowResourceBase {
} }
@Test @Test
public void testMultipleCellCheckDeletePB() throws IOException, JAXBException { public void testMultipleCellCheckDeletePB() throws IOException {
Response response = getValuePB(TABLE, ROW_1, COLUMN_1); Response response = getValuePB(TABLE, ROW_1, COLUMN_1);
assertEquals(404, response.getCode()); assertEquals(404, response.getCode());
@ -252,6 +251,7 @@ public class TestGetAndPutResource extends RowResourceBase {
response = deleteRow(TABLE, ROW_1); response = deleteRow(TABLE, ROW_1);
assertEquals(200, response.getCode()); assertEquals(200, response.getCode());
} }
@Test @Test
public void testSingleCellGetPutBinary() throws IOException { public void testSingleCellGetPutBinary() throws IOException {
final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1; final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1;
@ -278,7 +278,7 @@ public class TestGetAndPutResource extends RowResourceBase {
} }
@Test @Test
public void testSingleCellGetJSON() throws IOException, JAXBException { public void testSingleCellGetJSON() throws IOException {
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1; final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
Response response = client.put(path, Constants.MIMETYPE_BINARY, Response response = client.put(path, Constants.MIMETYPE_BINARY,
Bytes.toBytes(VALUE_4)); Bytes.toBytes(VALUE_4));
@ -292,7 +292,7 @@ public class TestGetAndPutResource extends RowResourceBase {
} }
@Test @Test
public void testLatestCellGetJSON() throws IOException, JAXBException { public void testLatestCellGetJSON() throws IOException {
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1; final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
CellSetModel cellSetModel = new CellSetModel(); CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_4); RowModel rowModel = new RowModel(ROW_4);
@ -339,7 +339,7 @@ public class TestGetAndPutResource extends RowResourceBase {
} }
@Test @Test
public void testNoSuchCF() throws IOException, JAXBException { public void testNoSuchCF() throws IOException {
final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + CFA+":"; final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + CFA+":";
final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD"; final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD";
Response response = client.post(goodPath, Constants.MIMETYPE_BINARY, Response response = client.post(goodPath, Constants.MIMETYPE_BINARY,
@ -529,7 +529,7 @@ public class TestGetAndPutResource extends RowResourceBase {
} }
@Test @Test
public void testMetrics() throws IOException, JAXBException { public void testMetrics() throws IOException {
final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1; final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1;
Response response = client.put(path, Constants.MIMETYPE_BINARY, Response response = client.put(path, Constants.MIMETYPE_BINARY,
Bytes.toBytes(VALUE_4)); Bytes.toBytes(VALUE_4));
@ -542,16 +542,16 @@ public class TestGetAndPutResource extends RowResourceBase {
assertEquals(200, response.getCode()); assertEquals(200, response.getCode());
UserProvider userProvider = UserProvider.instantiate(conf); UserProvider userProvider = UserProvider.instantiate(conf);
METRICS_ASSERT.assertCounterGt("requests", 2l, METRICS_ASSERT.assertCounterGt("requests", 2L,
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource()); RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
METRICS_ASSERT.assertCounterGt("successfulGet", 0l, METRICS_ASSERT.assertCounterGt("successfulGet", 0L,
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource()); RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
METRICS_ASSERT.assertCounterGt("successfulPut", 0l, METRICS_ASSERT.assertCounterGt("successfulPut", 0L,
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource()); RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
METRICS_ASSERT.assertCounterGt("successfulDelete", 0l, METRICS_ASSERT.assertCounterGt("successfulDelete", 0L,
RESTServlet.getInstance(conf, userProvider).getMetrics().getSource()); RESTServlet.getInstance(conf, userProvider).getMetrics().getSource());
} }
@ -806,4 +806,3 @@ public class TestGetAndPutResource extends RowResourceBase {
assertEquals(200, response.getCode()); assertEquals(200, response.getCode());
} }
} }

View File

@ -17,7 +17,10 @@
*/ */
package org.apache.hadoop.hbase.rest; package org.apache.hadoop.hbase.rest;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
@ -60,7 +63,6 @@ import org.junit.experimental.categories.Category;
@Category({RestTests.class, MediumTests.class}) @Category({RestTests.class, MediumTests.class})
public class TestNamespacesInstanceResource { public class TestNamespacesInstanceResource {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestNamespacesInstanceResource.class); HBaseClassTestRule.forClass(TestNamespacesInstanceResource.class);
@ -122,9 +124,9 @@ public class TestNamespacesInstanceResource {
private NamespaceDescriptor findNamespace(Admin admin, String namespaceName) throws IOException{ private NamespaceDescriptor findNamespace(Admin admin, String namespaceName) throws IOException{
NamespaceDescriptor[] nd = admin.listNamespaceDescriptors(); NamespaceDescriptor[] nd = admin.listNamespaceDescriptors();
for(int i = 0; i < nd.length; i++){ for (NamespaceDescriptor namespaceDescriptor : nd) {
if(nd[i].getName().equals(namespaceName)){ if (namespaceDescriptor.getName().equals(namespaceName)) {
return nd[i]; return namespaceDescriptor;
} }
} }
return null; return null;
@ -137,15 +139,15 @@ public class TestNamespacesInstanceResource {
private void checkNamespaceProperties(Map<String,String> namespaceProps, private void checkNamespaceProperties(Map<String,String> namespaceProps,
Map<String,String> testProps){ Map<String,String> testProps){
assertTrue(namespaceProps.size() == testProps.size()); assertTrue(namespaceProps.size() == testProps.size());
for(String key: testProps.keySet()){ for (String key: testProps.keySet()) {
assertEquals(testProps.get(key), namespaceProps.get(key)); assertEquals(testProps.get(key), namespaceProps.get(key));
} }
} }
private void checkNamespaceTables(List<TableModel> namespaceTables, List<String> testTables){ private void checkNamespaceTables(List<TableModel> namespaceTables, List<String> testTables){
assertEquals(namespaceTables.size(), testTables.size()); assertEquals(namespaceTables.size(), testTables.size());
for(int i = 0 ; i < namespaceTables.size() ; i++){ for (TableModel namespaceTable : namespaceTables) {
String tableName = ((TableModel) namespaceTables.get(i)).getName(); String tableName = namespaceTable.getName();
assertTrue(testTables.contains(tableName)); assertTrue(testTables.contains(tableName));
} }
} }
@ -369,7 +371,7 @@ public class TestNamespacesInstanceResource {
} }
@Test @Test
public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException, JAXBException { public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException {
String namespacePath3 = "/namespaces/" + NAMESPACE3; String namespacePath3 = "/namespaces/" + NAMESPACE3;
String namespacePath4 = "/namespaces/" + NAMESPACE4; String namespacePath4 = "/namespaces/" + NAMESPACE4;
NamespacesInstanceModel model3; NamespacesInstanceModel model3;

View File

@ -17,7 +17,8 @@
*/ */
package org.apache.hadoop.hbase.rest; package org.apache.hadoop.hbase.rest;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
@ -44,7 +45,6 @@ import org.junit.experimental.categories.Category;
@Category({RestTests.class, MediumTests.class}) @Category({RestTests.class, MediumTests.class})
public class TestNamespacesResource { public class TestNamespacesResource {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestNamespacesResource.class); HBaseClassTestRule.forClass(TestNamespacesResource.class);
@ -83,8 +83,8 @@ public class TestNamespacesResource {
private boolean doesNamespaceExist(Admin admin, String namespaceName) throws IOException { private boolean doesNamespaceExist(Admin admin, String namespaceName) throws IOException {
NamespaceDescriptor[] nd = admin.listNamespaceDescriptors(); NamespaceDescriptor[] nd = admin.listNamespaceDescriptors();
for(int i = 0; i < nd.length; i++) { for (NamespaceDescriptor namespaceDescriptor : nd) {
if(nd[i].getName().equals(namespaceName)) { if (namespaceDescriptor.getName().equals(namespaceName)) {
return true; return true;
} }
} }
@ -156,7 +156,7 @@ public class TestNamespacesResource {
} }
@Test @Test
public void testNamespaceListPBandDefault() throws IOException, JAXBException { public void testNamespaceListPBandDefault() throws IOException {
String schemaPath = "/namespaces/"; String schemaPath = "/namespaces/";
NamespacesModel model; NamespacesModel model;
Response response; Response response;

View File

@ -71,7 +71,6 @@ import org.junit.experimental.categories.Category;
@Category({RestTests.class, MediumTests.class}) @Category({RestTests.class, MediumTests.class})
public class TestScannersWithLabels { public class TestScannersWithLabels {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestScannersWithLabels.class); HBaseClassTestRule.forClass(TestScannersWithLabels.class);
@ -96,7 +95,8 @@ public class TestScannersWithLabels {
private static Unmarshaller unmarshaller; private static Unmarshaller unmarshaller;
private static Configuration conf; private static Configuration conf;
private static int insertData(TableName tableName, String column, double prob) throws IOException { private static int insertData(TableName tableName, String column, double prob)
throws IOException {
byte[] k = new byte[3]; byte[] k = new byte[3];
byte[][] famAndQf = CellUtil.parseColumn(Bytes.toBytes(column)); byte[][] famAndQf = CellUtil.parseColumn(Bytes.toBytes(column));
@ -168,9 +168,7 @@ public class TestScannersWithLabels {
} }
private static void createLabels() throws IOException, InterruptedException { private static void createLabels() throws IOException, InterruptedException {
PrivilegedExceptionAction<VisibilityLabelsResponse> action = new PrivilegedExceptionAction<VisibilityLabelsResponse>() { PrivilegedExceptionAction<VisibilityLabelsResponse> action = () -> {
@Override
public VisibilityLabelsResponse run() throws Exception {
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET }; String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
try (Connection conn = ConnectionFactory.createConnection(conf)) { try (Connection conn = ConnectionFactory.createConnection(conf)) {
VisibilityClient.addLabels(conn, labels); VisibilityClient.addLabels(conn, labels);
@ -178,10 +176,10 @@ public class TestScannersWithLabels {
throw new IOException(t); throw new IOException(t);
} }
return null; return null;
}
}; };
SUPERUSER.runAs(action); SUPERUSER.runAs(action);
} }
private static void setAuths() throws Exception { private static void setAuths() throws Exception {
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET }; String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, PUBLIC, TOPSECRET };
try (Connection conn = ConnectionFactory.createConnection(conf)) { try (Connection conn = ConnectionFactory.createConnection(conf)) {
@ -190,6 +188,7 @@ public class TestScannersWithLabels {
throw new IOException(t); throw new IOException(t);
} }
} }
@Test @Test
public void testSimpleScannerXMLWithLabelsThatReceivesNoData() throws IOException, JAXBException { public void testSimpleScannerXMLWithLabelsThatReceivesNoData() throws IOException, JAXBException {
final int BATCH_SIZE = 5; final int BATCH_SIZE = 5;
@ -242,5 +241,4 @@ public class TestScannersWithLabels {
.getBody())); .getBody()));
assertEquals(5, countCellSet(cellSet)); assertEquals(5, countCellSet(cellSet));
} }
} }

View File

@ -52,19 +52,14 @@ import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Category({RestTests.class, MediumTests.class}) @Category({RestTests.class, MediumTests.class})
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
public class TestSchemaResource { public class TestSchemaResource {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestSchemaResource.class); HBaseClassTestRule.forClass(TestSchemaResource.class);
private static final Logger LOG = LoggerFactory.getLogger(TestSchemaResource.class);
private static String TABLE1 = "TestSchemaResource1"; private static String TABLE1 = "TestSchemaResource1";
private static String TABLE2 = "TestSchemaResource2"; private static String TABLE2 = "TestSchemaResource2";
@ -146,7 +141,8 @@ public class TestSchemaResource {
Response response; Response response;
Admin admin = TEST_UTIL.getAdmin(); Admin admin = TEST_UTIL.getAdmin();
assertFalse("Table " + TABLE1 + " should not exist", admin.tableExists(TableName.valueOf(TABLE1))); assertFalse("Table " + TABLE1 + " should not exist",
admin.tableExists(TableName.valueOf(TABLE1)));
// create the table // create the table
model = testTableSchemaModel.buildTestModel(TABLE1); model = testTableSchemaModel.buildTestModel(TABLE1);
@ -200,7 +196,7 @@ public class TestSchemaResource {
} }
@Test @Test
public void testTableCreateAndDeletePB() throws IOException, JAXBException { public void testTableCreateAndDeletePB() throws IOException {
String schemaPath = "/" + TABLE2 + "/schema"; String schemaPath = "/" + TABLE2 + "/schema";
TableSchemaModel model; TableSchemaModel model;
Response response; Response response;
@ -263,6 +259,4 @@ public class TestSchemaResource {
assertEquals(200, response.getCode()); assertEquals(200, response.getCode());
assertFalse(admin.tableExists(TableName.valueOf(TABLE2))); assertFalse(admin.tableExists(TableName.valueOf(TABLE2)));
} }
} }

View File

@ -46,7 +46,6 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLStreamException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
@ -72,20 +71,15 @@ import org.junit.BeforeClass;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
@Category({RestTests.class, MediumTests.class}) @Category({RestTests.class, MediumTests.class})
public class TestTableScan { public class TestTableScan {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestTableScan.class); HBaseClassTestRule.forClass(TestTableScan.class);
private static final Logger LOG = LoggerFactory.getLogger(TestTableScan.class);
private static final TableName TABLE = TableName.valueOf("TestScanResource"); private static final TableName TABLE = TableName.valueOf("TestScanResource");
private static final String CFA = "a"; private static final String CFA = "a";
private static final String CFB = "b"; private static final String CFB = "b";
@ -131,7 +125,7 @@ public class TestTableScan {
} }
@Test @Test
public void testSimpleScannerXML() throws IOException, JAXBException, XMLStreamException { public void testSimpleScannerXML() throws IOException, JAXBException {
// Test scanning particular columns // Test scanning particular columns
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("/*"); builder.append("/*");
@ -207,7 +201,7 @@ public class TestTableScan {
} }
@Test @Test
public void testSimpleScannerJson() throws IOException, JAXBException { public void testSimpleScannerJson() throws IOException {
// Test scanning particular columns with limit. // Test scanning particular columns with limit.
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("/*"); builder.append("/*");
@ -434,7 +428,7 @@ public class TestTableScan {
} }
@Test @Test
public void testScanningUnknownColumnJson() throws IOException, JAXBException { public void testScanningUnknownColumnJson() throws IOException {
// Test scanning particular columns with limit. // Test scanning particular columns with limit.
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("/*"); builder.append("/*");
@ -603,7 +597,7 @@ public class TestTableScan {
} }
@Test @Test
public void testColumnWithEmptyQualifier() throws IOException, JAXBException { public void testColumnWithEmptyQualifier() throws IOException {
// Test scanning with empty qualifier // Test scanning with empty qualifier
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("/*"); builder.append("/*");
@ -669,7 +663,6 @@ public class TestTableScan {
@XmlRootElement(name = "CellSet") @XmlRootElement(name = "CellSet")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public static class ClientSideCellSetModel implements Serializable { public static class ClientSideCellSetModel implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
@ -701,11 +694,8 @@ public class TestTableScan {
/** /**
* This listener is invoked every time a new row model is unmarshalled. * This listener is invoked every time a new row model is unmarshalled.
*/ */
public static interface Listener { public interface Listener {
void handleRowModel(ClientSideCellSetModel helper, RowModel rowModel); void handleRowModel(ClientSideCellSetModel helper, RowModel rowModel);
} }
} }
} }

View File

@ -50,7 +50,6 @@ import org.junit.experimental.categories.Category;
*/ */
@Category({RestTests.class, SmallTests.class}) @Category({RestTests.class, SmallTests.class})
public class TestRemoteHTableRetries { public class TestRemoteHTableRetries {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRemoteHTableRetries.class); HBaseClassTestRule.forClass(TestRemoteHTableRetries.class);
@ -131,8 +130,7 @@ public class TestRemoteHTableRetries {
testTimedOutCall(new CallExecutor() { testTimedOutCall(new CallExecutor() {
@Override @Override
public void run() throws Exception { public void run() throws Exception {
Put[] puts = { new Put(Bytes.toBytes("Row1")), Put[] puts = { new Put(Bytes.toBytes("Row1")), new Put(Bytes.toBytes("Row2")) };
new Put(Bytes.toBytes("Row2")) };
remoteTable.put(Arrays.asList(puts)); remoteTable.put(Arrays.asList(puts));
} }
}); });
@ -172,7 +170,6 @@ public class TestRemoteHTableRetries {
Put put = new Put(ROW_1); Put put = new Put(ROW_1);
put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1);
Delete delete= new Delete(ROW_1); Delete delete= new Delete(ROW_1);
//remoteTable.checkAndDelete(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1, delete );
remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1) remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1)
.ifEquals(VALUE_1).thenDelete(delete); .ifEquals(VALUE_1).thenDelete(delete);
} }
@ -195,8 +192,7 @@ public class TestRemoteHTableRetries {
assertTrue((System.currentTimeMillis() - start) > MAX_TIME); assertTrue((System.currentTimeMillis() - start) > MAX_TIME);
} }
private static interface CallExecutor { private interface CallExecutor {
void run() throws Exception; void run() throws Exception;
} }
} }

View File

@ -61,7 +61,6 @@ import org.junit.experimental.categories.Category;
@Category({RestTests.class, MediumTests.class}) @Category({RestTests.class, MediumTests.class})
public class TestRemoteTable { public class TestRemoteTable {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRemoteTable.class); HBaseClassTestRule.forClass(TestRemoteTable.class);
@ -116,7 +115,10 @@ public class TestRemoteTable {
public void before() throws Exception { public void before() throws Exception {
Admin admin = TEST_UTIL.getAdmin(); Admin admin = TEST_UTIL.getAdmin();
if (admin.tableExists(TABLE)) { if (admin.tableExists(TABLE)) {
if (admin.isTableEnabled(TABLE)) admin.disableTable(TABLE); if (admin.isTableEnabled(TABLE)) {
admin.disableTable(TABLE);
}
admin.deleteTable(TABLE); admin.deleteTable(TABLE);
} }
HTableDescriptor htd = new HTableDescriptor(TABLE); HTableDescriptor htd = new HTableDescriptor(TABLE);
@ -217,7 +219,6 @@ public class TestRemoteTable {
assertTrue(Bytes.equals(VALUE_2, value2)); assertTrue(Bytes.equals(VALUE_2, value2));
// test timestamp // test timestamp
get = new Get(ROW_2); get = new Get(ROW_2);
get.addFamily(COLUMN_1); get.addFamily(COLUMN_1);
get.addFamily(COLUMN_2); get.addFamily(COLUMN_2);
@ -230,7 +231,6 @@ public class TestRemoteTable {
assertNull(value2); assertNull(value2);
// test timerange // test timerange
get = new Get(ROW_2); get = new Get(ROW_2);
get.addFamily(COLUMN_1); get.addFamily(COLUMN_1);
get.addFamily(COLUMN_2); get.addFamily(COLUMN_2);
@ -243,7 +243,6 @@ public class TestRemoteTable {
assertNull(value2); assertNull(value2);
// test maxVersions // test maxVersions
get = new Get(ROW_2); get = new Get(ROW_2);
get.addFamily(COLUMN_1); get.addFamily(COLUMN_1);
get.readVersions(2); get.readVersions(2);
@ -315,7 +314,6 @@ public class TestRemoteTable {
assertTrue(Bytes.equals(VALUE_1, value)); assertTrue(Bytes.equals(VALUE_1, value));
// multiput // multiput
List<Put> puts = new ArrayList<>(3); List<Put> puts = new ArrayList<>(3);
put = new Put(ROW_3); put = new Put(ROW_3);
put.addColumn(COLUMN_2, QUALIFIER_2, VALUE_2); put.addColumn(COLUMN_2, QUALIFIER_2, VALUE_2);
@ -343,7 +341,8 @@ public class TestRemoteTable {
assertNotNull(value); assertNotNull(value);
assertTrue(Bytes.equals(VALUE_2, value)); assertTrue(Bytes.equals(VALUE_2, value));
assertTrue(Bytes.equals(Bytes.toBytes("TestRemoteTable" + VALID_TABLE_NAME_CHARS), remoteTable.getTableName())); assertTrue(Bytes.equals(Bytes.toBytes("TestRemoteTable" + VALID_TABLE_NAME_CHARS),
remoteTable.getTableName()));
} }
@Test @Test
@ -489,7 +488,6 @@ public class TestRemoteTable {
assertTrue(Bytes.equals(ROW_4, results[3].getRow())); assertTrue(Bytes.equals(ROW_4, results[3].getRow()));
scanner.close(); scanner.close();
assertTrue(remoteTable.isAutoFlush()); assertTrue(remoteTable.isAutoFlush());
} }
@Test @Test
@ -576,8 +574,9 @@ public class TestRemoteTable {
/** /**
* Tests keeping a HBase scanner alive for long periods of time. Each call to next() should reset * Tests keeping a HBase scanner alive for long periods of time. Each call to next() should reset
* the ConnectionCache timeout for the scanner's connection * the ConnectionCache timeout for the scanner's connection.
* @throws Exception *
* @throws Exception if starting the servlet container or disabling or truncating the table fails
*/ */
@Test @Test
public void testLongLivedScan() throws Exception { public void testLongLivedScan() throws Exception {

View File

@ -20,6 +20,9 @@ package org.apache.hadoop.hbase.rest.model;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.rest.ScannerResultGenerator; import org.apache.hadoop.hbase.rest.ScannerResultGenerator;
import org.apache.hadoop.hbase.testclassification.RestTests; import org.apache.hadoop.hbase.testclassification.RestTests;
@ -29,12 +32,8 @@ import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
@Category({RestTests.class, SmallTests.class}) @Category({RestTests.class, SmallTests.class})
public class TestScannerModel extends TestModelBase<ScannerModel> { public class TestScannerModel extends TestModelBase<ScannerModel> {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestScannerModel.class); HBaseClassTestRule.forClass(TestScannerModel.class);

View File

@ -32,7 +32,6 @@ import org.junit.experimental.categories.Category;
@Category({RestTests.class, SmallTests.class}) @Category({RestTests.class, SmallTests.class})
public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterStatusModel> { public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterStatusModel> {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestStorageClusterStatusModel.class); HBaseClassTestRule.forClass(TestStorageClusterStatusModel.class);
@ -44,16 +43,20 @@ public class TestStorageClusterStatusModel extends TestModelBase<StorageClusterS
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
"<ClusterStatus averageLoad=\"1.0\" regions=\"2\" requests=\"0\">" + "<ClusterStatus averageLoad=\"1.0\" regions=\"2\" requests=\"0\">" +
"<DeadNodes/><LiveNodes>" + "<DeadNodes/><LiveNodes>" +
"<Node heapSizeMB=\"128\" maxHeapSizeMB=\"1024\" name=\"test1\" requests=\"0\" startCode=\"1245219839331\">" + "<Node heapSizeMB=\"128\" maxHeapSizeMB=\"1024\" name=\"test1\" requests=\"0\" " +
"<Region currentCompactedKVs=\"1\" memstoreSizeMB=\"0\" name=\"aGJhc2U6cm9vdCwsMA==\" readRequestsCount=\"1\" " + "startCode=\"1245219839331\"><Region currentCompactedKVs=\"1\" memstoreSizeMB=\"0\" " +
"rootIndexSizeKB=\"1\" storefileIndexSizeKB=\"0\" storefileSizeMB=\"0\" storefiles=\"1\" stores=\"1\" " + "name=\"aGJhc2U6cm9vdCwsMA==\" readRequestsCount=\"1\" rootIndexSizeKB=\"1\" " +
"totalCompactingKVs=\"1\" totalStaticBloomSizeKB=\"1\" totalStaticIndexSizeKB=\"1\" writeRequestsCount=\"2\"/>" + "storefileIndexSizeKB=\"0\" storefileSizeMB=\"0\" storefiles=\"1\" stores=\"1\" " +
"</Node>" + "totalCompactingKVs=\"1\" totalStaticBloomSizeKB=\"1\" totalStaticIndexSizeKB=\"1\" " +
"<Node heapSizeMB=\"512\" maxHeapSizeMB=\"1024\" name=\"test2\" requests=\"0\" startCode=\"1245239331198\">" + "writeRequestsCount=\"2\"/></Node>" +
"<Region currentCompactedKVs=\"1\" memstoreSizeMB=\"0\" name=\"aGJhc2U6bWV0YSwsMTI0NjAwMDA0MzcyNA==\" " + "<Node heapSizeMB=\"512\" maxHeapSizeMB=\"1024\" name=\"test2\" requests=\"0\" " +
"readRequestsCount=\"1\" rootIndexSizeKB=\"1\" storefileIndexSizeKB=\"0\" storefileSizeMB=\"0\" " + "startCode=\"1245239331198\">" +
"<Region currentCompactedKVs=\"1\" memstoreSizeMB=\"0\" " +
"name=\"aGJhc2U6bWV0YSwsMTI0NjAwMDA0MzcyNA==\" readRequestsCount=\"1\" " +
"rootIndexSizeKB=\"1\" storefileIndexSizeKB=\"0\" storefileSizeMB=\"0\" " +
"storefiles=\"1\" stores=\"1\" totalCompactingKVs=\"1\" totalStaticBloomSizeKB=\"1\" " + "storefiles=\"1\" stores=\"1\" totalCompactingKVs=\"1\" totalStaticBloomSizeKB=\"1\" " +
"totalStaticIndexSizeKB=\"1\" writeRequestsCount=\"2\"/></Node></LiveNodes></ClusterStatus>"; "totalStaticIndexSizeKB=\"1\" writeRequestsCount=\"2\"/></Node></LiveNodes>" +
"</ClusterStatus>";
AS_PB = AS_PB =
"Cj8KBXRlc3QxEOO6i+eeJBgAIIABKIAIMicKDWhiYXNlOnJvb3QsLDAQARgBIAAoADAAOAFAAkgB" + "Cj8KBXRlc3QxEOO6i+eeJBgAIIABKIAIMicKDWhiYXNlOnJvb3QsLDAQARgBIAAoADAAOAFAAkgB" +