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 Jan Hentschel
parent a18a5c4baa
commit b81685cfcc
No known key found for this signature in database
GPG Key ID: 5CD818B19CC299A3
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.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.HBaseConfiguration;
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.TableName;
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.Connection;
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;
public static final TableName TABLE_NAME = TableName.valueOf("TestTable");
public static final byte [] FAMILY_NAME = Bytes.toBytes("info");
public static final byte [] QUALIFIER_NAME = Bytes.toBytes("data");
public static final byte[] FAMILY_NAME = Bytes.toBytes("info");
public static final byte[] QUALIFIER_NAME = Bytes.toBytes("data");
private TableName tableName = TABLE_NAME;
protected HTableDescriptor TABLE_DESCRIPTOR;
@ -144,6 +144,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
private Connection connection;
private static final Path PERF_EVAL_DIR = new Path("performance_evaluation");
/**
* 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
* inner-class so we can find associated properties.
*/
protected static enum Counter {
protected enum Counter {
/** elapsed time */
ELAPSED_TIME,
/** number of rows */
ROWS}
ROWS
}
/**
* Constructor
@ -214,7 +216,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
/**
* Sets status
* @param msg status message
* @throws IOException
* @throws IOException if setting the status fails
*/
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.
*/
public static class PeInputSplit extends InputSplit implements Writable {
private TableName tableName = TABLE_NAME;
private int startRow = 0;
private int rows = 0;
private int totalRows = 0;
private int clients = 0;
private boolean flushCommits = false;
private boolean writeToWAL = true;
private boolean useTags = false;
private int noOfTags = 0;
public PeInputSplit() {
}
private TableName tableName;
private int startRow;
private int rows;
private int totalRows;
private int clients;
private boolean flushCommits;
private boolean writeToWAL;
private boolean useTags;
private int noOfTags;
public PeInputSplit(TableName tableName, int startRow, int rows, int totalRows, int clients,
boolean flushCommits, boolean writeToWAL, boolean useTags, int noOfTags) {
@ -284,12 +283,12 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
@Override
public long getLength() throws IOException, InterruptedException {
public long getLength() {
return 0;
}
@Override
public String[] getLocations() throws IOException, InterruptedException {
public String[] getLocations() {
return new String[0];
}
@ -309,10 +308,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
return totalRows;
}
public int getClients() {
return clients;
}
public boolean isFlushCommits() {
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().
*/
public static class PeInputFormat extends FileInputFormat<NullWritable, PeInputSplit> {
@Override
public List<InputSplit> getSplits(JobContext job) throws IOException {
// generate splits
@ -349,15 +343,15 @@ public class PerformanceEvaluation extends Configured implements Tool {
FileSystem fs = path.getFileSystem(job.getConfiguration());
FSDataInputStream fileIn = fs.open(path);
LineReader in = new LineReader(fileIn, job.getConfiguration());
int lineLen = 0;
int lineLen;
while(true) {
Text lineText = new Text();
lineLen = in.readLine(lineText);
if(lineLen <= 0) {
break;
break;
}
Matcher m = LINE_PATTERN.matcher(lineText.toString());
if((m != null) && m.matches()) {
if ((m != null) && m.matches()) {
TableName tableName = TableName.valueOf(m.group(1));
int startRow = Integer.parseInt(m.group(2));
int rows = Integer.parseInt(m.group(3));
@ -394,7 +388,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
@Override
public RecordReader<NullWritable, PeInputSplit> createRecordReader(InputSplit split,
TaskAttemptContext context) {
TaskAttemptContext context) {
return new PeRecordReader();
}
@ -405,14 +399,13 @@ public class PerformanceEvaluation extends Configured implements Tool {
private PeInputSplit value = null;
@Override
public void initialize(InputSplit split, TaskAttemptContext context)
throws IOException, InterruptedException {
public void initialize(InputSplit split, TaskAttemptContext context) {
this.readOver = false;
this.split = (PeInputSplit)split;
}
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
public boolean nextKeyValue() {
if(readOver) {
return false;
}
@ -425,17 +418,17 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
@Override
public NullWritable getCurrentKey() throws IOException, InterruptedException {
public NullWritable getCurrentKey() {
return key;
}
@Override
public PeInputSplit getCurrentValue() throws IOException, InterruptedException {
public PeInputSplit getCurrentValue() {
return value;
}
@Override
public float getProgress() throws IOException, InterruptedException {
public float getProgress() {
if(readOver) {
return 1.0f;
} else {
@ -444,7 +437,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
@Override
public void close() throws IOException {
public void close() {
// do nothing
}
}
@ -465,7 +458,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
private PerformanceEvaluation pe;
@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 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) {
Class<? extends Type> clazz = null;
Class<? extends Type> clazz;
try {
clazz = Class.forName(className).asSubclass(type);
} catch (ClassNotFoundException e) {
@ -492,14 +485,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
@Override
protected void map(NullWritable key, PeInputSplit value, final Context context)
throws IOException, InterruptedException {
Status status = new Status() {
@Override
public void setStatus(String msg) {
context.setStatus(msg);
}
};
throws IOException, InterruptedException {
Status status = context::setStatus;
// Evaluation task
pe.tableName = value.getTableName();
@ -517,11 +504,11 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
}
/*
/**
* 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.
* @throws IOException
* @throws IOException if an operation on the table fails
*/
private boolean checkTable(RemoteAdmin admin) throws IOException {
HTableDescriptor tableDescriptor = getTableDescriptor();
@ -536,7 +523,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
LOG.debug(" split " + i + ": " + Bytes.toStringBinary(splits[i]));
}
admin.createTable(tableDescriptor);
LOG.info ("Table created with " + this.presplitRegions + " splits");
LOG.info("Table created with " + this.presplitRegions + " splits");
} else {
boolean tableExists = admin.isTableAvailable(tableDescriptor.getTableName().getName());
if (!tableExists) {
@ -544,8 +531,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
LOG.info("Table " + tableDescriptor + " created");
}
}
boolean tableExists = admin.isTableAvailable(tableDescriptor.getTableName().getName());
return tableExists;
return admin.isTableAvailable(tableDescriptor.getTableName().getName());
}
protected HTableDescriptor getTableDescriptor() {
@ -568,8 +555,9 @@ public class PerformanceEvaluation extends Configured implements Tool {
* @return splits : array of byte []
*/
protected byte[][] getSplits() {
if (this.presplitRegions == 0)
return new byte [0][];
if (this.presplitRegions == 0) {
return new byte[0][];
}
int numSplitPoints = presplitRegions - 1;
byte[][] splits = new byte[numSplitPoints][];
@ -581,14 +569,13 @@ public class PerformanceEvaluation extends Configured implements Tool {
return splits;
}
/*
/**
* 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.
* @param cmd Command to run.
* @throws IOException
*/
private void runNIsMoreThanOne(final Class<? extends Test> cmd)
throws IOException, InterruptedException, ClassNotFoundException {
throws IOException, InterruptedException, ClassNotFoundException {
RemoteAdmin remoteAdmin = new RemoteAdmin(new Client(cluster), getConf());
checkTable(remoteAdmin);
if (nomapred) {
@ -598,10 +585,10 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
}
/*
/**
* Run all clients in this vm each to its own thread.
* @param cmd Command to run.
* @throws IOException
* @param cmd Command to run
* @throws IOException if creating a connection fails
*/
private void doMultipleClients(final Class<? extends Test> cmd) throws IOException {
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());
for (int i = 0; i < this.N; i++) {
final int index = i;
Thread t = new Thread ("TestClient-" + i) {
Thread t = new Thread("TestClient-" + i) {
@Override
public void run() {
super.run();
@ -636,12 +623,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
try {
long elapsedTime = pe.runOneClient(cmd, index * perClientRows,
perClientRows, R,
flushCommits, writeToWAL, useTags, noOfTags, connection, new Status() {
@Override
public void setStatus(final String msg) throws IOException {
LOG.info("client-" + getName() + " " + msg);
}
});
flushCommits, writeToWAL, useTags, noOfTags, connection,
msg -> LOG.info("client-" + getName() + " " + msg));
timings[index] = elapsedTime;
LOG.info("Finished " + getName() + " in " + elapsedTime +
"ms writing " + perClientRows + " rows");
@ -678,15 +661,14 @@ public class PerformanceEvaluation extends Configured implements Tool {
+ "\tAvg: " + (total / this.N) + "ms");
}
/*
/**
* 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
* per client regards which row they are to start on.
* @param cmd Command to run.
* @throws IOException
*/
private void doMapReduce(final Class<? extends Test> cmd) throws IOException,
InterruptedException, ClassNotFoundException {
private void doMapReduce(final Class<? extends Test> cmd)
throws IOException, InterruptedException, ClassNotFoundException {
Configuration conf = getConf();
Path inputDir = writeInputFile(conf);
conf.set(EvaluationMapTask.CMD_KEY, cmd.getName());
@ -712,11 +694,11 @@ public class PerformanceEvaluation extends Configured implements Tool {
job.waitForCompletion(true);
}
/*
/**
* Write input file of offsets-per-client for the mapreduce job.
* @param c Configuration
* @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 {
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
@ -735,14 +717,14 @@ public class PerformanceEvaluation extends Configured implements Tool {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < N; j++) {
String s = "tableName=" + this.tableName +
", startRow=" + ((j * perClientRows) + (i * (perClientRows/10))) +
", perClientRunRows=" + (perClientRows / 10) +
", totalRows=" + this.R +
", clients=" + this.N +
", flushCommits=" + this.flushCommits +
", writeToWAL=" + this.writeToWAL +
", useTags=" + this.useTags +
", noOfTags=" + this.noOfTags;
", startRow=" + ((j * perClientRows) + (i * (perClientRows/10))) +
", perClientRunRows=" + (perClientRows / 10) +
", totalRows=" + this.R +
", clients=" + this.N +
", flushCommits=" + this.flushCommits +
", writeToWAL=" + this.writeToWAL +
", useTags=" + this.useTags +
", noOfTags=" + this.noOfTags;
byte[] b = Bytes.toBytes(s);
int hash = h.hash(new ByteArrayHashKey(b, 0, b.length), -1);
m.put(hash, s);
@ -785,31 +767,26 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
/**
* Wraps up options passed to {@link org.apache.hadoop.hbase.PerformanceEvaluation.Test
* tests}. This makes the reflection logic a little easier to understand...
* Wraps up options passed to {@link org.apache.hadoop.hbase.PerformanceEvaluation} tests
* This makes the reflection logic a little easier to understand...
*/
static class TestOptions {
private int startRow;
private int perClientRunRows;
private int totalRows;
private int numClientThreads;
private TableName tableName;
private boolean flushCommits;
private boolean writeToWAL = true;
private boolean useTags = false;
private int noOfTags = 0;
private boolean writeToWAL;
private boolean useTags;
private int noOfTags;
private Connection connection;
TestOptions() {
}
TestOptions(int startRow, int perClientRunRows, int totalRows, int numClientThreads,
TableName tableName, boolean flushCommits, boolean writeToWAL, boolean useTags,
TestOptions(int startRow, int perClientRunRows, int totalRows, TableName tableName,
boolean flushCommits, boolean writeToWAL, boolean useTags,
int noOfTags, Connection connection) {
this.startRow = startRow;
this.perClientRunRows = perClientRunRows;
this.totalRows = totalRows;
this.numClientThreads = numClientThreads;
this.tableName = tableName;
this.flushCommits = flushCommits;
this.writeToWAL = writeToWAL;
@ -830,10 +807,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
return totalRows;
}
public int getNumClientThreads() {
return numClientThreads;
}
public TableName getTableName() {
return tableName;
}
@ -912,10 +885,11 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
abstract void testTakedown() throws IOException;
/*
/**
* Run test
* @return Elapsed time.
* @throws IOException
* @throws IOException if something in the test fails
*/
long test() throws IOException {
testSetup();
@ -945,10 +919,10 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
}
/*
* Test for individual row.
* @param i Row index.
*/
/**
* Test for individual row.
* @param i Row index.
*/
abstract void testRow(final int i) throws IOException;
}
@ -1012,7 +986,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
int period = this.perClientRunRows / 100;
return period == 0? this.perClientRunRows: period;
}
}
@SuppressWarnings("unused")
@ -1041,7 +1014,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
s.close();
}
protected abstract Pair<byte[],byte[]> getStartAndStopRow();
protected abstract Pair<byte[], byte[]> getStartAndStopRow();
protected Pair<byte[], byte[]> generateStartAndStopRows(int maxRange) {
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;
return period == 0? this.perClientRunRows: period;
}
}
static class RandomWriteTest extends BufferedMutatorTest {
@ -1163,7 +1135,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
super.testTakedown();
}
@Override
void testRow(final int i) throws IOException {
if (this.testScanner == null) {
@ -1173,7 +1144,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
testScanner.next();
}
}
static class SequentialReadTest extends TableTest {
@ -1187,11 +1157,9 @@ public class PerformanceEvaluation extends Configured implements Tool {
get.addColumn(FAMILY_NAME, QUALIFIER_NAME);
table.get(get);
}
}
static class SequentialWriteTest extends BufferedMutatorTest {
SequentialWriteTest(Configuration conf, TestOptions options, Status status) {
super(conf, options, status);
}
@ -1236,11 +1204,13 @@ public class PerformanceEvaluation extends Configured implements Tool {
while (scanner.next() != null) {
}
} 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(
FAMILY_NAME, QUALIFIER_NAME, CompareOperator.EQUAL,
new BinaryComparator(valuePrefix)
@ -1252,14 +1222,14 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
}
/*
/**
* Format passed integer.
* @param number
* @return Returns zero-prefixed 10-byte wide decimal version of passed
* number (Does absolute in case number is negative).
* @param number the integer to format
* @return Returns zero-prefixed 10-byte wide decimal version of passed number (Does absolute in
* case number is negative).
*/
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);
for (int i = b.length - 1; i >= 0; i--) {
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) {
byte [] b = new byte [length];
int i = 0;
byte[] b = new byte [length];
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+1] = 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));
for(; i < length; i++) {
for (; i < length; i++) {
b[i] = a;
}
return b;
@ -1296,21 +1266,20 @@ public class PerformanceEvaluation extends Configured implements Tool {
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);
}
long runOneClient(final Class<? extends Test> cmd, final int startRow,
final int perClientRunRows, final int totalRows,
boolean flushCommits, boolean writeToWAL, boolean useTags, int noOfTags,
Connection connection, final Status status)
throws IOException {
Connection connection, final Status status) throws IOException {
status.setStatus("Start " + cmd + " at offset " + startRow + " for " +
perClientRunRows + " rows");
long totalElapsedTime = 0;
long totalElapsedTime;
TestOptions options = new TestOptions(startRow, perClientRunRows,
totalRows, N, tableName, flushCommits, writeToWAL, useTags, noOfTags, connection);
totalRows, tableName, flushCommits, writeToWAL, useTags, noOfTags, connection);
final Test t;
try {
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) {
Status status = new Status() {
@Override
public void setStatus(String msg) throws IOException {
LOG.info(msg);
}
};
Status status = LOG::info;
RemoteAdmin admin = null;
RemoteAdmin admin;
try {
Client client = new Client(cluster);
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,
InterruptedException, ClassNotFoundException {
private void runTest(final Class<? extends Test> cmd)
throws IOException, InterruptedException, ClassNotFoundException {
if (N == 1) {
// If there is only one client and one HRegionServer, we assume nothing
// 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) {
if(start + 1 > args.length) {
if (start + 1 > args.length) {
throw new IllegalArgumentException("must supply the number of clients");
}
N = Integer.parseInt(args[start]);
@ -1554,9 +1518,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
return descriptor != null ? descriptor.getCmdClass() : null;
}
/**
* @param args
*/
public static void main(final String[] args) throws Exception {
int res = ToolRunner.run(new PerformanceEvaluation(HBaseConfiguration.create()), args);
System.exit(res);

View File

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

View File

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

View File

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

View File

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

View File

@ -52,19 +52,14 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Category({RestTests.class, MediumTests.class})
@RunWith(Parameterized.class)
public class TestSchemaResource {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestSchemaResource.class);
private static final Logger LOG = LoggerFactory.getLogger(TestSchemaResource.class);
private static String TABLE1 = "TestSchemaResource1";
private static String TABLE2 = "TestSchemaResource2";
@ -146,7 +141,8 @@ public class TestSchemaResource {
Response response;
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
model = testTableSchemaModel.buildTestModel(TABLE1);
@ -200,7 +196,7 @@ public class TestSchemaResource {
}
@Test
public void testTableCreateAndDeletePB() throws IOException, JAXBException {
public void testTableCreateAndDeletePB() throws IOException {
String schemaPath = "/" + TABLE2 + "/schema";
TableSchemaModel model;
Response response;
@ -263,6 +259,4 @@ public class TestSchemaResource {
assertEquals(200, response.getCode());
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.XmlRootElement;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLStreamException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
@ -71,20 +70,15 @@ import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
@Category({RestTests.class, MediumTests.class})
public class TestTableScan {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestTableScan.class);
private static final Logger LOG = LoggerFactory.getLogger(TestTableScan.class);
private static final TableName TABLE = TableName.valueOf("TestScanResource");
private static final String CFA = "a";
private static final String CFB = "b";
@ -130,7 +124,7 @@ public class TestTableScan {
}
@Test
public void testSimpleScannerXML() throws IOException, JAXBException, XMLStreamException {
public void testSimpleScannerXML() throws IOException, JAXBException {
// Test scanning particular columns
StringBuilder builder = new StringBuilder();
builder.append("/*");
@ -206,7 +200,7 @@ public class TestTableScan {
}
@Test
public void testSimpleScannerJson() throws IOException, JAXBException {
public void testSimpleScannerJson() throws IOException {
// Test scanning particular columns with limit.
StringBuilder builder = new StringBuilder();
builder.append("/*");
@ -293,16 +287,16 @@ public class TestTableScan {
unmarshaller.setListener(new Unmarshaller.Listener() {
@Override
public void beforeUnmarshal(Object target, Object parent) {
if (target instanceof ClientSideCellSetModel) {
((ClientSideCellSetModel) target).setCellSetModelListener(listener);
}
if (target instanceof ClientSideCellSetModel) {
((ClientSideCellSetModel) target).setCellSetModelListener(listener);
}
}
@Override
public void afterUnmarshal(Object target, Object parent) {
if (target instanceof ClientSideCellSetModel) {
((ClientSideCellSetModel) target).setCellSetModelListener(null);
}
if (target instanceof ClientSideCellSetModel) {
((ClientSideCellSetModel) target).setCellSetModelListener(null);
}
}
});
@ -433,7 +427,7 @@ public class TestTableScan {
}
@Test
public void testScanningUnknownColumnJson() throws IOException, JAXBException {
public void testScanningUnknownColumnJson() throws IOException {
// Test scanning particular columns with limit.
StringBuilder builder = new StringBuilder();
builder.append("/*");
@ -602,7 +596,7 @@ public class TestTableScan {
}
@Test
public void testColumnWithEmptyQualifier() throws IOException, JAXBException {
public void testColumnWithEmptyQualifier() throws IOException {
// Test scanning with empty qualifier
StringBuilder builder = new StringBuilder();
builder.append("/*");
@ -667,7 +661,6 @@ public class TestTableScan {
@XmlRootElement(name = "CellSet")
@XmlAccessorType(XmlAccessType.FIELD)
public static class ClientSideCellSetModel implements Serializable {
private static final long serialVersionUID = 1L;
/**
@ -684,26 +677,23 @@ public class TestTableScan {
* is removed again.
*/
public void setCellSetModelListener(final Listener l) {
row = (l == null) ? null : new ArrayList<RowModel>() {
row = (l == null) ? null : new ArrayList<RowModel>() {
private static final long serialVersionUID = 1L;
@Override
public boolean add(RowModel o) {
l.handleRowModel(ClientSideCellSetModel.this, o);
listenerInvoked = true;
return false;
}
};
@Override
public boolean add(RowModel o) {
l.handleRowModel(ClientSideCellSetModel.this, o);
listenerInvoked = true;
return false;
}
};
}
/**
* This listener is invoked every time a new row model is unmarshalled.
*/
public static interface Listener {
void handleRowModel(ClientSideCellSetModel helper, RowModel rowModel);
public interface Listener {
void handleRowModel(ClientSideCellSetModel helper, RowModel rowModel);
}
}
}

View File

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

View File

@ -60,7 +60,6 @@ import org.junit.experimental.categories.Category;
@Category({RestTests.class, MediumTests.class})
public class TestRemoteTable {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRemoteTable.class);
@ -115,7 +114,10 @@ public class TestRemoteTable {
public void before() throws Exception {
Admin admin = TEST_UTIL.getAdmin();
if (admin.tableExists(TABLE)) {
if (admin.isTableEnabled(TABLE)) admin.disableTable(TABLE);
if (admin.isTableEnabled(TABLE)) {
admin.disableTable(TABLE);
}
admin.deleteTable(TABLE);
}
HTableDescriptor htd = new HTableDescriptor(TABLE);
@ -220,7 +222,6 @@ public class TestRemoteTable {
assertTrue(Bytes.equals(VALUE_2, value2));
// test timestamp
get = new Get(ROW_2);
get.addFamily(COLUMN_1);
get.addFamily(COLUMN_2);
@ -233,7 +234,6 @@ public class TestRemoteTable {
assertNull(value2);
// test timerange
get = new Get(ROW_2);
get.addFamily(COLUMN_1);
get.addFamily(COLUMN_2);
@ -246,7 +246,6 @@ public class TestRemoteTable {
assertNull(value2);
// test maxVersions
get = new Get(ROW_2);
get.addFamily(COLUMN_1);
get.setMaxVersions(2);
@ -318,7 +317,6 @@ public class TestRemoteTable {
assertTrue(Bytes.equals(VALUE_1, value));
// multiput
List<Put> puts = new ArrayList<>(3);
put = new Put(ROW_3);
put.addColumn(COLUMN_2, QUALIFIER_2, VALUE_2);
@ -346,7 +344,8 @@ public class TestRemoteTable {
assertNotNull(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
@ -492,7 +491,6 @@ public class TestRemoteTable {
assertTrue(Bytes.equals(ROW_4, results[3].getRow()));
scanner.close();
assertTrue(remoteTable.isAutoFlush());
}
@Test
@ -579,8 +577,9 @@ public class TestRemoteTable {
/**
* 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
* @throws Exception
* the ConnectionCache timeout for the scanner's connection.
*
* @throws Exception if starting the servlet container or disabling or truncating the table fails
*/
@Test
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.assertTrue;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.rest.ScannerResultGenerator;
import org.apache.hadoop.hbase.testclassification.RestTests;
@ -29,12 +32,8 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
@Category({RestTests.class, SmallTests.class})
public class TestScannerModel extends TestModelBase<ScannerModel> {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestScannerModel.class);

View File

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