HBASE-23646 Resolved remaining Checkstyle violations in tests of hbase-rest

Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Jan Hentschel 2020-01-20 22:21:32 +01:00 committed by GitHub
parent 99a59cf9e7
commit 2e3273f6ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 474 additions and 494 deletions

View File

@ -36,4 +36,6 @@
<suppress checks="MagicNumberCheck" files=".*Test\.java"/>
<!-- Will not have a private constructor, because it is InterfaceAudience.Public -->
<suppress checks="HideUtilityClassConstructor" files="org.apache.hadoop.hbase.util.ByteRangeUtils"/>
<suppress checks="InnerAssignment" files="org.apache.hadoop.hbase.rest.PerformanceEvaluation"/>
<suppress checks="EmptyBlock" files="org.apache.hadoop.hbase.rest.PerformanceEvaluation"/>
</suppressions>

View File

@ -34,7 +34,6 @@ import org.mortbay.jetty.servlet.ServletHolder;
import com.sun.jersey.spi.container.servlet.ServletContainer;
public class HBaseRESTTestingUtility {
private static final Log LOG = LogFactory.getLog(HBaseRESTTestingUtility.class);
private int testServletPort;
@ -91,7 +90,8 @@ public class HBaseRESTTestingUtility {
}
public void shutdownServletContainer() {
if (server != null) try {
if (server != null) {
try {
server.stop();
server = null;
RESTServlet.stop();
@ -100,3 +100,4 @@ public class HBaseRESTTestingUtility {
}
}
}
}

View File

@ -18,6 +18,22 @@
*/
package org.apache.hadoop.hbase.rest;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
@ -59,6 +75,7 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Hash;
import org.apache.hadoop.hbase.util.MurmurHash;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
@ -76,22 +93,6 @@ import org.apache.hadoop.util.LineReader;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Script used evaluating Stargate performance and scalability. Runs a SG
* client that steps through one of a set of hardcoded tests or 'experiments'
@ -123,7 +124,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
private TableName tableName = TABLE_NAME;
protected HTableDescriptor TABLE_DESCRIPTOR;
protected Map<String, CmdDescriptor> commands = new TreeMap<String, CmdDescriptor>();
protected Map<String, CmdDescriptor> commands = new TreeMap<>();
protected static Cluster cluster = new Cluster();
volatile Configuration conf;
@ -141,6 +142,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.
*/
@ -159,11 +161,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
@ -199,8 +202,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
protected void addCommandDescriptor(Class<? extends Test> cmdClass,
String name, String description) {
CmdDescriptor cmdDescriptor =
new CmdDescriptor(cmdClass, name, description);
CmdDescriptor cmdDescriptor = new CmdDescriptor(cmdClass, name, description);
commands.put(name, cmdDescriptor);
}
@ -211,7 +213,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;
}
@ -223,18 +225,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) {
@ -281,12 +280,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];
}
@ -332,11 +331,10 @@ 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
List<InputSplit> splitList = new ArrayList<InputSplit>();
List<InputSplit> splitList = new ArrayList<>();
for (FileStatus file : listStatus(job)) {
if (file.isDirectory()) {
@ -346,7 +344,7 @@ 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);
@ -402,37 +400,36 @@ 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;
}
key = NullWritable.get();
value = (PeInputSplit)split;
value = split;
readOver = true;
return true;
}
@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 {
@ -441,7 +438,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
@Override
public void close() throws IOException {
public void close() {
// do nothing
}
}
@ -462,7 +459,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
@ -478,7 +475,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) {
@ -513,11 +510,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();
@ -540,8 +537,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() {
@ -564,8 +561,9 @@ public class PerformanceEvaluation extends Configured implements Tool {
* @return splits : array of byte []
*/
protected byte[][] getSplits() {
if (this.presplitRegions == 0)
if (this.presplitRegions == 0) {
return new byte[0][];
}
int numSplitPoints = presplitRegions - 1;
byte[][] splits = new byte[numSplitPoints][];
@ -577,11 +575,10 @@ 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 {
@ -594,13 +591,13 @@ 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<Thread>(this.N);
final List<Thread> threads = new ArrayList<>(this.N);
final long[] timings = new long[this.N];
final int perClientRows = R/N;
final TableName tableName = this.tableName;
@ -674,15 +671,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());
@ -708,11 +704,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");
@ -722,32 +718,30 @@ public class PerformanceEvaluation extends Configured implements Tool {
FileSystem fs = FileSystem.get(c);
fs.mkdirs(inputDir);
Path inputFile = new Path(inputDir, "input.txt");
PrintStream out = new PrintStream(fs.create(inputFile));
// Make input random.
Map<Integer, String> m = new TreeMap<Integer, String>();
Map<Integer, String> m = new TreeMap<>();
Hash h = MurmurHash.getInstance();
int perClientRows = (this.R / this.N);
try {
try (PrintStream out = new PrintStream(fs.create(inputFile))) {
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;
int hash = h.hash(Bytes.toBytes(s));
m.put(hash, s);
StringBuilder s = new StringBuilder();
s.append("tableName=").append(tableName);
s.append(", startRow=").append((j * perClientRows) + (i * (perClientRows / 10)));
s.append(", perClientRunRows=").append(perClientRows / 10);
s.append(", totalRows=").append(R);
s.append(", clients=").append(N);
s.append(", flushCommits=").append(flushCommits);
s.append(", writeToWAL=").append(writeToWAL);
s.append(", useTags=").append(useTags);
s.append(", noOfTags=").append(noOfTags);
int hash = h.hash(Bytes.toBytes(s.toString()));
m.put(hash, s.toString());
}
}
for (Map.Entry<Integer, String> e : m.entrySet()) {
out.println(e.getValue());
}
} finally {
out.close();
}
return inputDir;
}
@ -780,8 +774,8 @@ 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;
@ -790,14 +784,11 @@ public class PerformanceEvaluation extends Configured implements Tool {
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,
int noOfTags, Connection connection) {
@ -907,10 +898,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();
@ -940,7 +932,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
}
/*
/**
* Test for individual row.
* @param i Row index.
*/
@ -1007,7 +999,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
int period = this.perClientRunRows / 100;
return period == 0? this.perClientRunRows: period;
}
}
@SuppressWarnings("unused")
@ -1041,7 +1032,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
protected Pair<byte[], byte[]> generateStartAndStopRows(int maxRange) {
int start = this.rand.nextInt(Integer.MAX_VALUE) % totalRows;
int stop = start + maxRange;
return new Pair<byte[],byte[]>(format(start), format(stop));
return new Pair<>(format(start), format(stop));
}
@Override
@ -1112,7 +1103,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
int period = this.perClientRunRows / 100;
return period == 0? this.perClientRunRows: period;
}
}
static class RandomWriteTest extends BufferedMutatorTest {
@ -1158,7 +1148,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
super.testTakedown();
}
@Override
void testRow(final int i) throws IOException {
if (this.testScanner == null) {
@ -1168,7 +1157,6 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
testScanner.next();
}
}
static class SequentialReadTest extends TableTest {
@ -1182,11 +1170,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);
}
@ -1225,17 +1211,13 @@ public class PerformanceEvaluation extends Configured implements Tool {
void testRow(int i) throws IOException {
byte[] value = generateValue(this.rand);
Scan scan = constructScan(value);
ResultScanner scanner = null;
try {
scanner = this.table.getScanner(scan);
try (ResultScanner scanner = this.table.getScanner(scan)) {
while (scanner.next() != null) {
}
} finally {
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, CompareFilter.CompareOp.EQUAL,
new BinaryComparator(valuePrefix)
@ -1247,11 +1229,11 @@ 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];
@ -1265,7 +1247,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
public static byte[] generateData(final Random r, int length) {
byte[] b = new byte [length];
int i = 0;
int i;
for (i = 0; i < (length-8); i += 8) {
b[i] = (byte) (65 + r.nextInt(26));
@ -1298,11 +1280,10 @@ public class PerformanceEvaluation extends Configured implements Tool {
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);
@ -1334,7 +1315,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
}
};
RemoteAdmin admin = null;
RemoteAdmin admin;
try {
Client client = new Client(cluster);
admin = new RemoteAdmin(client, getConf());
@ -1346,8 +1327,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.
@ -1545,9 +1526,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

@ -25,7 +25,8 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBContext;
@ -53,7 +54,6 @@ import org.junit.Before;
import org.junit.BeforeClass;
public class RowResourceBase {
protected static final String TABLE = "TestRowResource";
protected static final String CFA = "a";
protected static final String CFB = "b";
@ -175,8 +175,8 @@ public class RowResourceBase {
assertEquals(Bytes.toString(cell.getValue()), value);
}
protected static void checkIncrementValueXML(String table, String row, String column,
long value) throws IOException, JAXBException {
protected static void checkIncrementValueXML(String table, String row, String column, long value)
throws IOException, JAXBException {
Response response = getValueXML(table, row, column);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
@ -258,8 +258,8 @@ public class RowResourceBase {
assertEquals(Bytes.toLong(cell.getValue()), value);
}
protected static Response checkAndPutValuePB(String url, String table,
String row, String column, String valueToCheck, String valueToPut, HashMap<String,String> otherCells)
protected static Response checkAndPutValuePB(String url, String table, String row, String column,
String valueToCheck, String valueToPut, HashMap<String,String> otherCells)
throws IOException {
RowModel rowModel = new RowModel(row);
rowModel.addCell(new CellModel(Bytes.toBytes(column),
@ -267,7 +267,8 @@ public class RowResourceBase {
if (otherCells != null) {
for (Map.Entry<String,String> entry : otherCells.entrySet()) {
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()),
Bytes.toBytes(entry.getValue())));
}
}
@ -287,8 +288,10 @@ public class RowResourceBase {
String column, String valueToCheck, String valueToPut) throws IOException {
return checkAndPutValuePB(table,row,column,valueToCheck,valueToPut,null);
}
protected static Response checkAndPutValuePB(String table, String row,
String column, String valueToCheck, String valueToPut, HashMap<String,String> otherCells) throws IOException {
protected static Response checkAndPutValuePB(String table, String row, String column,
String valueToCheck, String valueToPut, HashMap<String,String> otherCells)
throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@ -299,8 +302,8 @@ public class RowResourceBase {
valueToCheck, valueToPut, otherCells);
}
protected static Response checkAndPutValueXML(String url, String table,
String row, String column, String valueToCheck, String valueToPut, HashMap<String,String> otherCells)
protected static Response checkAndPutValueXML(String url, String table, String row, String column,
String valueToCheck, String valueToPut, HashMap<String,String> otherCells)
throws IOException, JAXBException {
RowModel rowModel = new RowModel(row);
rowModel.addCell(new CellModel(Bytes.toBytes(column),
@ -308,7 +311,8 @@ public class RowResourceBase {
if (otherCells != null) {
for (Map.Entry<String,String> entry : otherCells.entrySet()) {
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()),
Bytes.toBytes(entry.getValue())));
}
}
@ -325,9 +329,8 @@ public class RowResourceBase {
return response;
}
protected static Response checkAndPutValueXML(String table, String row,
String column, String valueToCheck, String valueToPut)
throws IOException, JAXBException {
protected static Response checkAndPutValueXML(String table, String row, String column,
String valueToCheck, String valueToPut) throws IOException, JAXBException {
return checkAndPutValueXML(table,row,column,valueToCheck,valueToPut, null);
}
@ -351,7 +354,8 @@ public class RowResourceBase {
if (cellsToDelete != null) {
for (Map.Entry<String,String> entry : cellsToDelete.entrySet()) {
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()),
Bytes.toBytes(entry.getValue())));
}
}
// Add this at the end
@ -371,8 +375,10 @@ public class RowResourceBase {
String column, String valueToCheck) throws IOException, JAXBException {
return checkAndDeleteXML(table, row, column, valueToCheck, null);
}
protected static Response checkAndDeleteXML(String table, String row,
String column, String valueToCheck, HashMap<String,String> cellsToDelete) throws IOException, JAXBException {
String column, String valueToCheck, HashMap<String,String> cellsToDelete)
throws IOException, JAXBException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@ -383,12 +389,13 @@ public class RowResourceBase {
}
protected static Response checkAndDeleteJson(String table, String row,
String column, String valueToCheck) throws IOException, JAXBException {
String column, String valueToCheck) throws IOException {
return checkAndDeleteJson(table, row, column, valueToCheck, null);
}
protected static Response checkAndDeleteJson(String table, String row,
String column, String valueToCheck, HashMap<String,String> cellsToDelete) throws IOException, JAXBException {
String column, String valueToCheck, HashMap<String,String> cellsToDelete)
throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@ -400,12 +407,13 @@ public class RowResourceBase {
protected static Response checkAndDeleteJson(String url, String table,
String row, String column, String valueToCheck, HashMap<String,String> cellsToDelete)
throws IOException, JAXBException {
throws IOException {
RowModel rowModel = new RowModel(row);
if (cellsToDelete != null) {
for (Map.Entry<String,String> entry : cellsToDelete.entrySet()) {
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()),
Bytes.toBytes(entry.getValue())));
}
}
// Add this at the end
@ -420,9 +428,8 @@ public class RowResourceBase {
return response;
}
protected static Response checkAndDeletePB(String table, String row,
String column, String value) throws IOException {
protected static Response checkAndDeletePB(String table, String row, String column, String value)
throws IOException {
return checkAndDeletePB(table, row, column, value, null);
}
@ -443,7 +450,8 @@ public class RowResourceBase {
if (cellsToDelete != null) {
for (Map.Entry<String,String> entry : cellsToDelete.entrySet()) {
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()),
Bytes.toBytes(entry.getValue())));
}
}
// Add this at the end
@ -532,12 +540,12 @@ public class RowResourceBase {
}
protected static void checkValueJSON(String table, String row, String column,
String value) throws IOException, JAXBException {
String value) throws IOException {
Response response = getValueJson(table, row, column);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
ObjectMapper mapper = new JacksonProvider()
.locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
ObjectMapper mapper = new JacksonProvider().locateMapper(CellSetModel.class,
MediaType.APPLICATION_JSON_TYPE);
CellSetModel cellSet = mapper.readValue(response.getBody(), CellSetModel.class);
RowModel rowModel = cellSet.getRows().get(0);
CellModel cell = rowModel.getCells().get(0);
@ -546,7 +554,7 @@ public class RowResourceBase {
}
protected static void checkIncrementValueJSON(String table, String row, String column,
long value) throws IOException, JAXBException {
long value) throws IOException {
Response response = getValueJson(table, row, column);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
@ -560,7 +568,7 @@ public class RowResourceBase {
}
protected static Response putValueJson(String table, String row, String column,
String value) throws IOException, JAXBException {
String value) throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@ -572,7 +580,7 @@ public class RowResourceBase {
}
protected static Response putValueJson(String url, String table, String row, String column,
String value) throws IOException, JAXBException {
String value) throws IOException {
RowModel rowModel = new RowModel(row);
rowModel.addCell(new CellModel(Bytes.toBytes(column),
Bytes.toBytes(value)));
@ -597,7 +605,7 @@ public class RowResourceBase {
}
protected static Response appendValuePB(String table, String row, String column,
String value) throws IOException, JAXBException {
String value) throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);
@ -630,7 +638,7 @@ public class RowResourceBase {
}
protected static Response incrementValuePB(String table, String row, String column,
String value) throws IOException, JAXBException {
String value) throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(table);

View File

@ -1,5 +1,4 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -16,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.rest;
import static org.junit.Assert.assertEquals;
@ -30,7 +28,6 @@ import java.util.Collection;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.apache.commons.httpclient.Header;
import org.apache.hadoop.conf.Configuration;
@ -48,6 +45,7 @@ import org.apache.hadoop.hbase.rest.model.RowModel;
import org.apache.hadoop.hbase.rest.provider.JacksonProvider;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -55,11 +53,9 @@ import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@Category(MediumTests.class)
@RunWith(Parameterized.class)
public class TestMultiRowResource {
private static final TableName TABLE = TableName.valueOf("TestRowResource");
private static final String CFA = "a";
private static final String CFB = "b";
@ -70,7 +66,6 @@ public class TestMultiRowResource {
private static final String ROW_2 = "testrow6";
private static final String VALUE_2 = "testvalue6";
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final HBaseRESTTestingUtility REST_TEST_UTIL = new HBaseRESTTestingUtility();
@ -94,7 +89,6 @@ public class TestMultiRowResource {
csrfEnabled = csrf;
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
conf = TEST_UTIL.getConfiguration();
@ -123,13 +117,11 @@ public class TestMultiRowResource {
TEST_UTIL.shutdownMiniCluster();
}
@Test
public void testMultiCellGetJSON() throws IOException, JAXBException {
public void testMultiCellGetJSON() throws IOException {
String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;
StringBuilder path = new StringBuilder();
path.append("/");
path.append(TABLE);
@ -146,22 +138,19 @@ public class TestMultiRowResource {
client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1), extraHdr);
client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2), extraHdr);
Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
client.delete(row_5_url, extraHdr);
client.delete(row_6_url, extraHdr);
}
@Test
public void testMultiCellGetXML() throws IOException, JAXBException {
public void testMultiCellGetXML() throws IOException {
String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;
StringBuilder path = new StringBuilder();
path.append("/");
path.append(TABLE);
@ -173,18 +162,16 @@ public class TestMultiRowResource {
client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1), extraHdr);
client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2), extraHdr);
Response response = client.get(path.toString(), Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
client.delete(row_5_url, extraHdr);
client.delete(row_6_url, extraHdr);
}
@Test
public void testMultiCellGetWithColsJSON() throws IOException, JAXBException {
public void testMultiCellGetWithColsJSON() throws IOException {
String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;
@ -214,11 +201,10 @@ public class TestMultiRowResource {
client.delete(row_5_url, extraHdr);
client.delete(row_6_url, extraHdr);
}
@Test
public void testMultiCellGetJSONNotFound() throws IOException, JAXBException {
public void testMultiCellGetJSONNotFound() throws IOException {
String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
StringBuilder path = new StringBuilder();
@ -242,7 +228,7 @@ public class TestMultiRowResource {
}
@Test
public void testMultiCellGetWithColsInQueryPathJSON() throws IOException, JAXBException {
public void testMultiCellGetWithColsInQueryPathJSON() throws IOException {
String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;
String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2;
@ -274,4 +260,3 @@ public class TestMultiRowResource {
client.delete(row_6_url, extraHdr);
}
}

View File

@ -1,5 +1,4 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -16,9 +15,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.rest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.util.ArrayList;
@ -32,7 +34,12 @@ import javax.xml.bind.Unmarshaller;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Put;
@ -64,8 +71,6 @@ import org.apache.hadoop.hbase.rest.model.ScannerModel;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -73,7 +78,6 @@ import org.junit.experimental.categories.Category;
@Category(MediumTests.class)
public class TestScannersWithFilters {
private static final Log LOG = LogFactory.getLog(TestScannersWithFilters.class);
private static final TableName TABLE = TableName.valueOf("TestScannersWithFilters");
@ -233,8 +237,8 @@ public class TestScannersWithFilters {
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
int rows = cells.getRows().size();
assertTrue("Scanned too many rows! Only expected " + expectedRows +
" total but scanned " + rows, expectedRows == rows);
assertEquals("Scanned too many rows! Only expected " + expectedRows +
" total but scanned " + rows, expectedRows, rows);
for (RowModel row : cells.getRows()) {
int count = row.getCells().size();
assertEquals("Expected " + expectedKeys + " keys per row but " +
@ -246,8 +250,7 @@ public class TestScannersWithFilters {
assertEquals(200, response.getCode());
}
private static void verifyScanFull(Scan s, KeyValue [] kvs)
throws Exception {
private static void verifyScanFull(Scan s, KeyValue [] kvs) throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
@ -276,10 +279,16 @@ public class TestScannersWithFilters {
Iterator<RowModel> i = cellSet.getRows().iterator();
for (boolean done = true; done; row++) {
done = i.hasNext();
if (!done) break;
if (!done) {
break;
}
RowModel rowModel = i.next();
List<CellModel> cells = rowModel.getCells();
if (cells.isEmpty()) break;
if (cells.isEmpty()) {
break;
}
assertTrue("Scanned too many keys! Only expected " + kvs.length +
" total but already scanned " + (cells.size() + idx),
kvs.length >= idx + cells.size());
@ -329,10 +338,16 @@ public class TestScannersWithFilters {
int j = 0;
for (boolean done = true; done; j++) {
done = i.hasNext();
if (!done) break;
if (!done) {
break;
}
RowModel rowModel = i.next();
List<CellModel> cells = rowModel.getCells();
if (cells.isEmpty()) break;
if (cells.isEmpty()) {
break;
}
assertTrue("Scanned too many rows! Only expected " + expectedRows +
" total but already scanned " + (j+1), expectedRows > j);
assertEquals("Expected " + expectedKeys + " keys per row but " +
@ -507,8 +522,7 @@ public class TestScannersWithFilters {
s.setFilter(f);
verifyScanNoEarlyOut(s, expectedRows, expectedKeys);
// Match keys less than or equal
// Expect four keys (two from each family) in half the rows
// Match keys less than or equal. Expect four keys (two from each family) in half the rows
expectedRows = numRows / 2;
expectedKeys = 4;
f = new QualifierFilter(CompareOp.LESS_OR_EQUAL,
@ -517,8 +531,7 @@ public class TestScannersWithFilters {
s.setFilter(f);
verifyScanNoEarlyOut(s, expectedRows, expectedKeys);
// Match keys not equal
// Expect four keys (two from each family)
// Match keys not equal. Expect four keys (two from each family)
// Only look in first group of rows
expectedRows = numRows / 2;
expectedKeys = 4;
@ -528,8 +541,7 @@ public class TestScannersWithFilters {
s.setFilter(f);
verifyScanNoEarlyOut(s, expectedRows, expectedKeys);
// Match keys greater or equal
// Expect four keys (two from each family)
// Match keys greater or equal. Expect four keys (two from each family)
// Only look in first group of rows
expectedRows = numRows / 2;
expectedKeys = 4;
@ -539,8 +551,7 @@ public class TestScannersWithFilters {
s.setFilter(f);
verifyScanNoEarlyOut(s, expectedRows, expectedKeys);
// Match keys greater
// Expect two keys (one from each family)
// Match keys greater. Expect two keys (one from each family)
// Only look in first group of rows
expectedRows = numRows / 2;
expectedKeys = 2;
@ -550,10 +561,8 @@ public class TestScannersWithFilters {
s.setFilter(f);
verifyScanNoEarlyOut(s, expectedRows, expectedKeys);
// Match keys not equal to
// Look across rows and fully validate the keys and ordering
// Expect varied numbers of keys, 4 per row in group one, 6 per row in
// group two
// Match keys not equal to. Look across rows and fully validate the keys and ordering
// Expect varied numbers of keys, 4 per row in group one, 6 per row in group two
f = new QualifierFilter(CompareOp.NOT_EQUAL,
new BinaryComparator(QUALIFIERS_ONE[2]));
s = new Scan();
@ -599,8 +608,7 @@ public class TestScannersWithFilters {
};
verifyScanFull(s, kvs);
// Test across rows and groups with a regex
// Filter out "test*-2"
// Test across rows and groups with a regex. Filter out "test*-2"
// Expect 4 keys per row across both groups
f = new QualifierFilter(CompareOp.NOT_EQUAL,
new RegexStringComparator("test.+-2"));
@ -995,6 +1003,4 @@ public class TestScannersWithFilters {
};
verifyScanFull(s, kvs);
}
}