Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 371A1119BF for ; Wed, 14 May 2014 02:15:12 +0000 (UTC) Received: (qmail 46928 invoked by uid 500); 14 May 2014 00:28:32 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 46884 invoked by uid 500); 14 May 2014 00:28:32 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 46877 invoked by uid 99); 14 May 2014 00:28:32 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 May 2014 00:28:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 May 2014 00:28:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C51672388C42; Wed, 14 May 2014 00:27:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1594423 [15/17] - in /hbase/branches/0.89-fb: ./ bin/ src/main/java/org/apache/hadoop/hbase/rest/ src/main/java/org/apache/hadoop/hbase/rest/client/ src/main/java/org/apache/hadoop/hbase/rest/metrics/ src/main/java/org/apache/hadoop/hbase/... Date: Wed, 14 May 2014 00:27:04 -0000 To: commits@hbase.apache.org From: liyin@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140514002721.C51672388C42@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java?rev=1594423&r1=1594422&r2=1594423&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java Wed May 14 00:26:57 2014 @@ -1,399 +0,0 @@ -/* - * Copyright 2010 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hbase.rest; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.StringWriter; -import java.net.URLEncoder; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; - -import org.apache.commons.httpclient.Header; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.client.HBaseAdmin; -import org.apache.hadoop.hbase.rest.client.Client; -import org.apache.hadoop.hbase.rest.client.Cluster; -import org.apache.hadoop.hbase.rest.client.Response; -import org.apache.hadoop.hbase.rest.model.CellModel; -import org.apache.hadoop.hbase.rest.model.CellSetModel; -import org.apache.hadoop.hbase.rest.model.RowModel; -import org.apache.hadoop.hbase.util.Bytes; - -public class TestRowResource extends HBaseRESTClusterTestBase { - static final String TABLE = "TestRowResource"; - static final String CFA = "a"; - static final String CFB = "b"; - static final String COLUMN_1 = CFA + ":1"; - static final String COLUMN_2 = CFB + ":2"; - static final String ROW_1 = "testrow1"; - static final String VALUE_1 = "testvalue1"; - static final String ROW_2 = "testrow2"; - static final String VALUE_2 = "testvalue2"; - static final String ROW_3 = "testrow3"; - static final String VALUE_3 = "testvalue3"; - static final String ROW_4 = "testrow4"; - static final String VALUE_4 = "testvalue4"; - - Client client; - JAXBContext context; - Marshaller marshaller; - Unmarshaller unmarshaller; - HBaseAdmin admin; - - @Override - protected void setUp() throws Exception { - super.setUp(); - context = JAXBContext.newInstance( - CellModel.class, - CellSetModel.class, - RowModel.class); - marshaller = context.createMarshaller(); - unmarshaller = context.createUnmarshaller(); - client = new Client(new Cluster().add("localhost", testServletPort)); - admin = new HBaseAdmin(conf); - if (admin.tableExists(TABLE)) { - return; - } - HTableDescriptor htd = new HTableDescriptor(TABLE); - htd.addFamily(new HColumnDescriptor(CFA)); - htd.addFamily(new HColumnDescriptor(CFB)); - admin.createTable(htd); - } - - @Override - protected void tearDown() throws Exception { - client.shutdown(); - super.tearDown(); - } - - Response deleteRow(String table, String row) throws IOException { - StringBuilder path = new StringBuilder(); - path.append('/'); - path.append(table); - path.append('/'); - path.append(row); - Response response = client.delete(path.toString()); - Thread.yield(); - return response; - } - - Response deleteValue(String table, String row, String column) - throws IOException { - StringBuilder path = new StringBuilder(); - path.append('/'); - path.append(table); - path.append('/'); - path.append(row); - path.append('/'); - path.append(column); - Response response = client.delete(path.toString()); - Thread.yield(); - return response; - } - - Response getValueXML(String table, String row, String column) - throws IOException { - StringBuilder path = new StringBuilder(); - path.append('/'); - path.append(table); - path.append('/'); - path.append(row); - path.append('/'); - path.append(column); - Response response = client.get(path.toString(), MIMETYPE_XML); - return response; - } - - Response getValuePB(String table, String row, String column) - throws IOException { - StringBuilder path = new StringBuilder(); - path.append('/'); - path.append(table); - path.append('/'); - path.append(row); - path.append('/'); - path.append(column); - Response response = client.get(path.toString(), MIMETYPE_PROTOBUF); - return response; - } - - Response putValueXML(String table, String row, String column, String value) - throws IOException, JAXBException { - StringBuilder path = new StringBuilder(); - path.append('/'); - path.append(table); - path.append('/'); - path.append(row); - path.append('/'); - path.append(column); - RowModel rowModel = new RowModel(row); - rowModel.addCell(new CellModel(Bytes.toBytes(column), - Bytes.toBytes(value))); - CellSetModel cellSetModel = new CellSetModel(); - cellSetModel.addRow(rowModel); - StringWriter writer = new StringWriter(); - marshaller.marshal(cellSetModel, writer); - Response response = client.put(path.toString(), MIMETYPE_XML, - Bytes.toBytes(writer.toString())); - Thread.yield(); - return response; - } - - void checkValueXML(String table, String row, String column, String value) - throws IOException, JAXBException { - Response response = getValueXML(table, row, column); - assertEquals(response.getCode(), 200); - CellSetModel cellSet = (CellSetModel) - unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); - RowModel rowModel = cellSet.getRows().get(0); - CellModel cell = rowModel.getCells().get(0); - assertEquals(Bytes.toString(cell.getColumn()), column); - assertEquals(Bytes.toString(cell.getValue()), value); - } - - Response putValuePB(String table, String row, String column, String value) - throws IOException { - StringBuilder path = new StringBuilder(); - path.append('/'); - path.append(table); - path.append('/'); - path.append(row); - path.append('/'); - path.append(column); - RowModel rowModel = new RowModel(row); - rowModel.addCell(new CellModel(Bytes.toBytes(column), - Bytes.toBytes(value))); - CellSetModel cellSetModel = new CellSetModel(); - cellSetModel.addRow(rowModel); - Response response = client.put(path.toString(), MIMETYPE_PROTOBUF, - cellSetModel.createProtobufOutput()); - Thread.yield(); - return response; - } - - void checkValuePB(String table, String row, String column, String value) - throws IOException { - Response response = getValuePB(table, row, column); - assertEquals(response.getCode(), 200); - CellSetModel cellSet = new CellSetModel(); - cellSet.getObjectFromMessage(response.getBody()); - RowModel rowModel = cellSet.getRows().get(0); - CellModel cell = rowModel.getCells().get(0); - assertEquals(Bytes.toString(cell.getColumn()), column); - assertEquals(Bytes.toString(cell.getValue()), value); - } - - void doTestDelete() throws IOException, JAXBException { - Response response; - - response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1); - assertEquals(response.getCode(), 200); - response = putValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2); - assertEquals(response.getCode(), 200); - checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1); - checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2); - - response = deleteValue(TABLE, ROW_1, COLUMN_1); - assertEquals(response.getCode(), 200); - response = getValueXML(TABLE, ROW_1, COLUMN_1); - assertEquals(response.getCode(), 404); - checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2); - - response = deleteRow(TABLE, ROW_1); - assertEquals(response.getCode(), 200); - response = getValueXML(TABLE, ROW_1, COLUMN_1); - assertEquals(response.getCode(), 404); - response = getValueXML(TABLE, ROW_1, COLUMN_2); - assertEquals(response.getCode(), 404); - } - - void doTestSingleCellGetPutXML() throws IOException, JAXBException { - Response response = getValueXML(TABLE, ROW_1, COLUMN_1); - assertEquals(response.getCode(), 404); - - response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1); - assertEquals(response.getCode(), 200); - checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1); - response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2); - assertEquals(response.getCode(), 200); - checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2); - - response = deleteRow(TABLE, ROW_1); - assertEquals(response.getCode(), 200); - } - - void doTestSingleCellGetPutPB() throws IOException, JAXBException { - Response response = getValuePB(TABLE, ROW_1, COLUMN_1); - assertEquals(response.getCode(), 404); - - response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1); - assertEquals(response.getCode(), 200); - checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1); - - response = putValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1); - assertEquals(response.getCode(), 200); - checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1); - response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_2); - assertEquals(response.getCode(), 200); - checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_2); - - response = deleteRow(TABLE, ROW_1); - assertEquals(response.getCode(), 200); - } - - void doTestSingleCellGetPutBinary() throws IOException { - final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1; - final byte[] body = Bytes.toBytes(VALUE_3); - Response response = client.put(path, MIMETYPE_BINARY, body); - assertEquals(response.getCode(), 200); - Thread.yield(); - - response = client.get(path, MIMETYPE_BINARY); - assertEquals(response.getCode(), 200); - assertTrue(Bytes.equals(response.getBody(), body)); - boolean foundTimestampHeader = false; - for (Header header: response.getHeaders()) { - if (header.getName().equals("X-Timestamp")) { - foundTimestampHeader = true; - break; - } - } - assertTrue(foundTimestampHeader); - - response = deleteRow(TABLE, ROW_3); - assertEquals(response.getCode(), 200); - } - - void doTestSingleCellGetJSON() throws IOException, JAXBException { - final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1; - Response response = client.put(path, MIMETYPE_BINARY, - Bytes.toBytes(VALUE_4)); - assertEquals(response.getCode(), 200); - Thread.yield(); - response = client.get(path, MIMETYPE_JSON); - assertEquals(response.getCode(), 200); - response = deleteRow(TABLE, ROW_4); - assertEquals(response.getCode(), 200); - } - - void doTestURLEncodedKey() throws IOException, JAXBException { - String encodedKey = URLEncoder.encode("http://www.google.com/", - HConstants.UTF8_ENCODING); - Response response; - response = putValueXML(TABLE, encodedKey, COLUMN_1, VALUE_1); - assertEquals(response.getCode(), 200); - response = putValuePB(TABLE, encodedKey, COLUMN_2, VALUE_2); - assertEquals(response.getCode(), 200); - checkValuePB(TABLE, encodedKey, COLUMN_1, VALUE_1); - checkValueXML(TABLE, encodedKey, COLUMN_2, VALUE_2); - } - - void doTestMultiCellGetPutXML() throws IOException, JAXBException { - String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row - - CellSetModel cellSetModel = new CellSetModel(); - RowModel rowModel = new RowModel(ROW_1); - rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), - Bytes.toBytes(VALUE_1))); - rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), - Bytes.toBytes(VALUE_2))); - cellSetModel.addRow(rowModel); - rowModel = new RowModel(ROW_2); - rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), - Bytes.toBytes(VALUE_3))); - rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), - Bytes.toBytes(VALUE_4))); - cellSetModel.addRow(rowModel); - StringWriter writer = new StringWriter(); - marshaller.marshal(cellSetModel, writer); - Response response = client.put(path, MIMETYPE_XML, - Bytes.toBytes(writer.toString())); - Thread.yield(); - - // make sure the fake row was not actually created - response = client.get(path, MIMETYPE_XML); - assertEquals(response.getCode(), 404); - - // check that all of the values were created - checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1); - checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2); - checkValueXML(TABLE, ROW_2, COLUMN_1, VALUE_3); - checkValueXML(TABLE, ROW_2, COLUMN_2, VALUE_4); - - response = deleteRow(TABLE, ROW_1); - assertEquals(response.getCode(), 200); - response = deleteRow(TABLE, ROW_2); - assertEquals(response.getCode(), 200); - } - - void doTestMultiCellGetPutPB() throws IOException { - String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row - - CellSetModel cellSetModel = new CellSetModel(); - RowModel rowModel = new RowModel(ROW_1); - rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), - Bytes.toBytes(VALUE_1))); - rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), - Bytes.toBytes(VALUE_2))); - cellSetModel.addRow(rowModel); - rowModel = new RowModel(ROW_2); - rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), - Bytes.toBytes(VALUE_3))); - rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), - Bytes.toBytes(VALUE_4))); - cellSetModel.addRow(rowModel); - Response response = client.put(path, MIMETYPE_PROTOBUF, - cellSetModel.createProtobufOutput()); - Thread.yield(); - - // make sure the fake row was not actually created - response = client.get(path, MIMETYPE_PROTOBUF); - assertEquals(response.getCode(), 404); - - // check that all of the values were created - checkValuePB(TABLE, ROW_1, COLUMN_1, VALUE_1); - checkValuePB(TABLE, ROW_1, COLUMN_2, VALUE_2); - checkValuePB(TABLE, ROW_2, COLUMN_1, VALUE_3); - checkValuePB(TABLE, ROW_2, COLUMN_2, VALUE_4); - - response = deleteRow(TABLE, ROW_1); - assertEquals(response.getCode(), 200); - response = deleteRow(TABLE, ROW_2); - assertEquals(response.getCode(), 200); - } - - public void testRowResource() throws Exception { - doTestDelete(); - doTestSingleCellGetPutXML(); - doTestSingleCellGetPutPB(); - doTestSingleCellGetPutBinary(); - doTestSingleCellGetJSON(); - doTestURLEncodedKey(); - doTestMultiCellGetPutXML(); - doTestMultiCellGetPutPB(); - } -} Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java?rev=1594423&r1=1594422&r2=1594423&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java Wed May 14 00:26:57 2014 @@ -1,274 +0,0 @@ -/* - * Copyright 2010 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hbase.rest; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.StringWriter; -import java.util.Iterator; -import java.util.Random; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; - -import org.apache.commons.httpclient.Header; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.client.HBaseAdmin; -import org.apache.hadoop.hbase.client.HTable; -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.rest.client.Client; -import org.apache.hadoop.hbase.rest.client.Cluster; -import org.apache.hadoop.hbase.rest.client.Response; -import org.apache.hadoop.hbase.rest.model.CellModel; -import org.apache.hadoop.hbase.rest.model.CellSetModel; -import org.apache.hadoop.hbase.rest.model.RowModel; -import org.apache.hadoop.hbase.rest.model.ScannerModel; -import org.apache.hadoop.hbase.util.Bytes; - -public class TestScannerResource extends HBaseRESTClusterTestBase { - static final String TABLE = "TestScannerResource"; - static final String CFA = "a"; - static final String CFB = "b"; - static final String COLUMN_1 = CFA + ":1"; - static final String COLUMN_2 = CFB + ":2"; - - static int expectedRows1; - static int expectedRows2; - - Client client; - JAXBContext context; - Marshaller marshaller; - Unmarshaller unmarshaller; - HBaseAdmin admin; - - int insertData(String tableName, String column, double prob) - throws IOException { - Random rng = new Random(); - int count = 0; - HTable table = new HTable(conf, tableName); - byte[] k = new byte[3]; - byte [][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(column)); - for (byte b1 = 'a'; b1 < 'z'; b1++) { - for (byte b2 = 'a'; b2 < 'z'; b2++) { - for (byte b3 = 'a'; b3 < 'z'; b3++) { - if (rng.nextDouble() < prob) { - k[0] = b1; - k[1] = b2; - k[2] = b3; - Put put = new Put(k); - put.add(famAndQf[0], famAndQf[1], k); - table.put(put); - count++; - } - } - } - } - table.flushCommits(); - return count; - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - context = JAXBContext.newInstance( - CellModel.class, - CellSetModel.class, - RowModel.class, - ScannerModel.class); - marshaller = context.createMarshaller(); - unmarshaller = context.createUnmarshaller(); - client = new Client(new Cluster().add("localhost", testServletPort)); - admin = new HBaseAdmin(conf); - if (admin.tableExists(TABLE)) { - return; - } - HTableDescriptor htd = new HTableDescriptor(TABLE); - htd.addFamily(new HColumnDescriptor(CFA)); - htd.addFamily(new HColumnDescriptor(CFB)); - admin.createTable(htd); - expectedRows1 = insertData(TABLE, COLUMN_1, 1.0); - expectedRows2 = insertData(TABLE, COLUMN_2, 0.5); - } - - @Override - protected void tearDown() throws Exception { - client.shutdown(); - super.tearDown(); - } - - int countCellSet(CellSetModel model) { - int count = 0; - Iterator rows = model.getRows().iterator(); - while (rows.hasNext()) { - RowModel row = rows.next(); - Iterator cells = row.getCells().iterator(); - while (cells.hasNext()) { - cells.next(); - count++; - } - } - return count; - } - - void doTestSimpleScannerXML() throws IOException, JAXBException { - final int BATCH_SIZE = 5; - // new scanner - ScannerModel model = new ScannerModel(); - model.setBatch(BATCH_SIZE); - model.addColumn(Bytes.toBytes(COLUMN_1)); - StringWriter writer = new StringWriter(); - marshaller.marshal(model, writer); - byte[] body = Bytes.toBytes(writer.toString()); - Response response = client.put("/" + TABLE + "/scanner", MIMETYPE_XML, - body); - assertEquals(response.getCode(), 201); - String scannerURI = response.getLocation(); - assertNotNull(scannerURI); - - // get a cell set - response = client.get(scannerURI, MIMETYPE_XML); - assertEquals(response.getCode(), 200); - CellSetModel cellSet = (CellSetModel) - unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); - // confirm batch size conformance - assertEquals(countCellSet(cellSet), BATCH_SIZE); - - // delete the scanner - response = client.delete(scannerURI); - assertEquals(response.getCode(), 200); - } - - void doTestSimpleScannerPB() throws IOException { - final int BATCH_SIZE = 10; - // new scanner - ScannerModel model = new ScannerModel(); - model.setBatch(BATCH_SIZE); - model.addColumn(Bytes.toBytes(COLUMN_1)); - Response response = client.put("/" + TABLE + "/scanner", - MIMETYPE_PROTOBUF, model.createProtobufOutput()); - assertEquals(response.getCode(), 201); - String scannerURI = response.getLocation(); - assertNotNull(scannerURI); - - // get a cell set - response = client.get(scannerURI, MIMETYPE_PROTOBUF); - assertEquals(response.getCode(), 200); - CellSetModel cellSet = new CellSetModel(); - cellSet.getObjectFromMessage(response.getBody()); - // confirm batch size conformance - assertEquals(countCellSet(cellSet), BATCH_SIZE); - - // delete the scanner - response = client.delete(scannerURI); - assertEquals(response.getCode(), 200); - } - - void doTestSimpleScannerBinary() throws IOException { - // new scanner - ScannerModel model = new ScannerModel(); - model.setBatch(1); - model.addColumn(Bytes.toBytes(COLUMN_1)); - Response response = client.put("/" + TABLE + "/scanner", - MIMETYPE_PROTOBUF, model.createProtobufOutput()); - assertEquals(response.getCode(), 201); - String scannerURI = response.getLocation(); - assertNotNull(scannerURI); - - // get a cell - response = client.get(scannerURI, MIMETYPE_BINARY); - assertEquals(response.getCode(), 200); - // verify that data was returned - assertTrue(response.getBody().length > 0); - // verify that the expected X-headers are present - boolean foundRowHeader = false, foundColumnHeader = false, - foundTimestampHeader = false; - for (Header header: response.getHeaders()) { - if (header.getName().equals("X-Row")) { - foundRowHeader = true; - } else if (header.getName().equals("X-Column")) { - foundColumnHeader = true; - } else if (header.getName().equals("X-Timestamp")) { - foundTimestampHeader = true; - } - } - assertTrue(foundRowHeader); - assertTrue(foundColumnHeader); - assertTrue(foundTimestampHeader); - - // delete the scanner - response = client.delete(scannerURI); - assertEquals(response.getCode(), 200); - } - - int fullTableScan(ScannerModel model) throws IOException { - model.setBatch(100); - Response response = client.put("/" + TABLE + "/scanner", - MIMETYPE_PROTOBUF, model.createProtobufOutput()); - assertEquals(response.getCode(), 201); - String scannerURI = response.getLocation(); - assertNotNull(scannerURI); - int count = 0; - while (true) { - response = client.get(scannerURI, MIMETYPE_PROTOBUF); - assertTrue(response.getCode() == 200 || response.getCode() == 204); - if (response.getCode() == 200) { - CellSetModel cellSet = new CellSetModel(); - cellSet.getObjectFromMessage(response.getBody()); - Iterator rows = cellSet.getRows().iterator(); - while (rows.hasNext()) { - RowModel row = rows.next(); - Iterator cells = row.getCells().iterator(); - while (cells.hasNext()) { - cells.next(); - count++; - } - } - } else { - break; - } - } - // delete the scanner - response = client.delete(scannerURI); - assertEquals(response.getCode(), 200); - return count; - } - - void doTestFullTableScan() throws IOException { - ScannerModel model = new ScannerModel(); - model.addColumn(Bytes.toBytes(COLUMN_1)); - assertEquals(fullTableScan(model), expectedRows1); - - model = new ScannerModel(); - model.addColumn(Bytes.toBytes(COLUMN_2)); - assertEquals(fullTableScan(model), expectedRows2); - } - - public void testScannerResource() throws Exception { - doTestSimpleScannerXML(); - doTestSimpleScannerPB(); - doTestSimpleScannerBinary(); - doTestFullTableScan(); - } -} Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java?rev=1594423&r1=1594422&r2=1594423&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java Wed May 14 00:26:57 2014 @@ -1,980 +0,0 @@ -/* - * Copyright 2010 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hbase.rest; - -import java.io.ByteArrayInputStream; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -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.client.Delete; -import org.apache.hadoop.hbase.client.HBaseAdmin; -import org.apache.hadoop.hbase.client.HTable; -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.client.Scan; -import org.apache.hadoop.hbase.filter.BinaryComparator; -import org.apache.hadoop.hbase.filter.Filter; -import org.apache.hadoop.hbase.filter.FilterList; -import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter; -import org.apache.hadoop.hbase.filter.InclusiveStopFilter; -import org.apache.hadoop.hbase.filter.PageFilter; -import org.apache.hadoop.hbase.filter.PrefixFilter; -import org.apache.hadoop.hbase.filter.QualifierFilter; -import org.apache.hadoop.hbase.filter.RegexStringComparator; -import org.apache.hadoop.hbase.filter.RowFilter; -import org.apache.hadoop.hbase.filter.SkipFilter; -import org.apache.hadoop.hbase.filter.SubstringComparator; -import org.apache.hadoop.hbase.filter.ValueFilter; -import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp; -import org.apache.hadoop.hbase.filter.FilterList.Operator; -import org.apache.hadoop.hbase.rest.client.Client; -import org.apache.hadoop.hbase.rest.client.Cluster; -import org.apache.hadoop.hbase.rest.client.Response; -import org.apache.hadoop.hbase.rest.model.CellModel; -import org.apache.hadoop.hbase.rest.model.CellSetModel; -import org.apache.hadoop.hbase.rest.model.RowModel; -import org.apache.hadoop.hbase.rest.model.ScannerModel; -import org.apache.hadoop.hbase.util.Bytes; - -public class TestScannersWithFilters extends HBaseRESTClusterTestBase { - - static final Log LOG = LogFactory.getLog(TestScannersWithFilters.class); - - static final byte [][] ROWS_ONE = { - Bytes.toBytes("testRowOne-0"), Bytes.toBytes("testRowOne-1"), - Bytes.toBytes("testRowOne-2"), Bytes.toBytes("testRowOne-3") - }; - - static final byte [][] ROWS_TWO = { - Bytes.toBytes("testRowTwo-0"), Bytes.toBytes("testRowTwo-1"), - Bytes.toBytes("testRowTwo-2"), Bytes.toBytes("testRowTwo-3") - }; - - static final byte [][] FAMILIES = { - Bytes.toBytes("testFamilyOne"), Bytes.toBytes("testFamilyTwo") - }; - - static final byte [][] QUALIFIERS_ONE = { - Bytes.toBytes("testQualifierOne-0"), Bytes.toBytes("testQualifierOne-1"), - Bytes.toBytes("testQualifierOne-2"), Bytes.toBytes("testQualifierOne-3") - }; - - static final byte [][] QUALIFIERS_TWO = { - Bytes.toBytes("testQualifierTwo-0"), Bytes.toBytes("testQualifierTwo-1"), - Bytes.toBytes("testQualifierTwo-2"), Bytes.toBytes("testQualifierTwo-3") - }; - - static final byte [][] VALUES = { - Bytes.toBytes("testValueOne"), Bytes.toBytes("testValueTwo") - }; - - Client client; - JAXBContext context; - Marshaller marshaller; - Unmarshaller unmarshaller; - long numRows = ROWS_ONE.length + ROWS_TWO.length; - long colsPerRow = FAMILIES.length * QUALIFIERS_ONE.length; - - @Override - protected void setUp() throws Exception { - super.setUp(); - context = JAXBContext.newInstance( - CellModel.class, - CellSetModel.class, - RowModel.class, - ScannerModel.class); - marshaller = context.createMarshaller(); - unmarshaller = context.createUnmarshaller(); - client = new Client(new Cluster().add("localhost", testServletPort)); - HBaseAdmin admin = new HBaseAdmin(conf); - if (!admin.tableExists(getName())) { - HTableDescriptor htd = new HTableDescriptor(getName()); - htd.addFamily(new HColumnDescriptor(FAMILIES[0])); - htd.addFamily(new HColumnDescriptor(FAMILIES[1])); - admin.createTable(htd); - HTable table = new HTable(conf, getName()); - // Insert first half - for(byte [] ROW : ROWS_ONE) { - Put p = new Put(ROW); - for(byte [] QUALIFIER : QUALIFIERS_ONE) { - p.add(FAMILIES[0], QUALIFIER, VALUES[0]); - } - table.put(p); - } - for(byte [] ROW : ROWS_TWO) { - Put p = new Put(ROW); - for(byte [] QUALIFIER : QUALIFIERS_TWO) { - p.add(FAMILIES[1], QUALIFIER, VALUES[1]); - } - table.put(p); - } - - // Insert second half (reverse families) - for(byte [] ROW : ROWS_ONE) { - Put p = new Put(ROW); - for(byte [] QUALIFIER : QUALIFIERS_ONE) { - p.add(FAMILIES[1], QUALIFIER, VALUES[0]); - } - table.put(p); - } - for(byte [] ROW : ROWS_TWO) { - Put p = new Put(ROW); - for(byte [] QUALIFIER : QUALIFIERS_TWO) { - p.add(FAMILIES[0], QUALIFIER, VALUES[1]); - } - table.put(p); - } - - // Delete the second qualifier from all rows and families - for(byte [] ROW : ROWS_ONE) { - Delete d = new Delete(ROW); - d.deleteColumns(FAMILIES[0], QUALIFIERS_ONE[1]); - d.deleteColumns(FAMILIES[1], QUALIFIERS_ONE[1]); - table.delete(d); - } - for(byte [] ROW : ROWS_TWO) { - Delete d = new Delete(ROW); - d.deleteColumns(FAMILIES[0], QUALIFIERS_TWO[1]); - d.deleteColumns(FAMILIES[1], QUALIFIERS_TWO[1]); - table.delete(d); - } - colsPerRow -= 2; - - // Delete the second rows from both groups, one column at a time - for(byte [] QUALIFIER : QUALIFIERS_ONE) { - Delete d = new Delete(ROWS_ONE[1]); - d.deleteColumns(FAMILIES[0], QUALIFIER); - d.deleteColumns(FAMILIES[1], QUALIFIER); - table.delete(d); - } - for(byte [] QUALIFIER : QUALIFIERS_TWO) { - Delete d = new Delete(ROWS_TWO[1]); - d.deleteColumns(FAMILIES[0], QUALIFIER); - d.deleteColumns(FAMILIES[1], QUALIFIER); - table.delete(d); - } - numRows -= 2; - } - } - - @Override - protected void tearDown() throws Exception { - client.shutdown(); - super.tearDown(); - } - - void verifyScan(Scan s, long expectedRows, long expectedKeys) - throws Exception { - ScannerModel model = ScannerModel.fromScan(s); - model.setBatch(Integer.MAX_VALUE); // fetch it all at once - StringWriter writer = new StringWriter(); - marshaller.marshal(model, writer); - LOG.debug(writer.toString()); - byte[] body = Bytes.toBytes(writer.toString()); - Response response = client.put("/" + getName() + "/scanner", MIMETYPE_XML, - body); - assertEquals(response.getCode(), 201); - String scannerURI = response.getLocation(); - assertNotNull(scannerURI); - - // get a cell set - response = client.get(scannerURI, MIMETYPE_XML); - assertEquals(response.getCode(), 200); - CellSetModel cells = (CellSetModel) - 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); - for (RowModel row: cells.getRows()) { - int count = row.getCells().size(); - assertEquals("Expected " + expectedKeys + " keys per row but " + - "returned " + count, expectedKeys, count); - } - - // delete the scanner - response = client.delete(scannerURI); - assertEquals(response.getCode(), 200); - } - - 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(); - marshaller.marshal(model, writer); - LOG.debug(writer.toString()); - byte[] body = Bytes.toBytes(writer.toString()); - Response response = client.put("/" + getName() + "/scanner", MIMETYPE_XML, - body); - assertEquals(response.getCode(), 201); - String scannerURI = response.getLocation(); - assertNotNull(scannerURI); - - // get a cell set - response = client.get(scannerURI, MIMETYPE_XML); - assertEquals(response.getCode(), 200); - CellSetModel cellSet = (CellSetModel) - unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); - - // delete the scanner - response = client.delete(scannerURI); - assertEquals(response.getCode(), 200); - - int row = 0; - int idx = 0; - Iterator i = cellSet.getRows().iterator(); - for (boolean done = true; done; row++) { - done = i.hasNext(); - if (!done) break; - RowModel rowModel = i.next(); - List cells = rowModel.getCells(); - 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()); - for (CellModel cell: cells) { - assertTrue("Row mismatch", - Bytes.equals(rowModel.getKey(), kvs[idx].getRow())); - byte[][] split = KeyValue.parseColumn(cell.getColumn()); - assertTrue("Family mismatch", - Bytes.equals(split[0], kvs[idx].getFamily())); - assertTrue("Qualifier mismatch", - Bytes.equals(split[1], kvs[idx].getQualifier())); - assertTrue("Value mismatch", - Bytes.equals(cell.getValue(), kvs[idx].getValue())); - idx++; - } - } - assertEquals("Expected " + kvs.length + " total keys but scanned " + idx, - kvs.length, idx); - } - - void verifyScanNoEarlyOut(Scan s, long expectedRows, long expectedKeys) - throws Exception { - ScannerModel model = ScannerModel.fromScan(s); - model.setBatch(Integer.MAX_VALUE); // fetch it all at once - StringWriter writer = new StringWriter(); - marshaller.marshal(model, writer); - LOG.debug(writer.toString()); - byte[] body = Bytes.toBytes(writer.toString()); - Response response = client.put("/" + getName() + "/scanner", MIMETYPE_XML, - body); - assertEquals(response.getCode(), 201); - String scannerURI = response.getLocation(); - assertNotNull(scannerURI); - - // get a cell set - response = client.get(scannerURI, MIMETYPE_XML); - assertEquals(response.getCode(), 200); - CellSetModel cellSet = (CellSetModel) - unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); - - // delete the scanner - response = client.delete(scannerURI); - assertEquals(response.getCode(), 200); - - Iterator i = cellSet.getRows().iterator(); - int j = 0; - for (boolean done = true; done; j++) { - done = i.hasNext(); - if (!done) break; - RowModel rowModel = i.next(); - List cells = rowModel.getCells(); - 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 " + - "returned " + cells.size(), expectedKeys, cells.size()); - } - assertEquals("Expected " + expectedRows + " rows but scanned " + j + - " rows", expectedRows, j); - } - - void doTestNoFilter() throws Exception { - // No filter - long expectedRows = this.numRows; - long expectedKeys = this.colsPerRow; - - // Both families - Scan s = new Scan(); - verifyScan(s, expectedRows, expectedKeys); - - // One family - s = new Scan(); - s.addFamily(FAMILIES[0]); - verifyScan(s, expectedRows, expectedKeys/2); - } - - void doTestPrefixFilter() throws Exception { - // Grab rows from group one (half of total) - long expectedRows = this.numRows / 2; - long expectedKeys = this.colsPerRow; - Scan s = new Scan(); - s.setFilter(new PrefixFilter(Bytes.toBytes("testRowOne"))); - verifyScan(s, expectedRows, expectedKeys); - } - - void doTestPageFilter() throws Exception { - // KVs in first 6 rows - KeyValue [] expectedKVs = { - // testRowOne-0 - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[1], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowOne-2 - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[1], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowOne-3 - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[1], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowTwo-0 - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-2 - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-3 - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]) - }; - - // Grab all 6 rows - long expectedRows = 6; - long expectedKeys = this.colsPerRow; - Scan s = new Scan(); - s.setFilter(new PageFilter(expectedRows)); - verifyScan(s, expectedRows, expectedKeys); - s.setFilter(new PageFilter(expectedRows)); - verifyScanFull(s, expectedKVs); - - // Grab first 4 rows (6 cols per row) - expectedRows = 4; - expectedKeys = this.colsPerRow; - s = new Scan(); - s.setFilter(new PageFilter(expectedRows)); - verifyScan(s, expectedRows, expectedKeys); - s.setFilter(new PageFilter(expectedRows)); - verifyScanFull(s, Arrays.copyOf(expectedKVs, 24)); - - // Grab first 2 rows - expectedRows = 2; - expectedKeys = this.colsPerRow; - s = new Scan(); - s.setFilter(new PageFilter(expectedRows)); - verifyScan(s, expectedRows, expectedKeys); - s.setFilter(new PageFilter(expectedRows)); - verifyScanFull(s, Arrays.copyOf(expectedKVs, 12)); - - // Grab first row - expectedRows = 1; - expectedKeys = this.colsPerRow; - s = new Scan(); - s.setFilter(new PageFilter(expectedRows)); - verifyScan(s, expectedRows, expectedKeys); - s.setFilter(new PageFilter(expectedRows)); - verifyScanFull(s, Arrays.copyOf(expectedKVs, 6)); - } - - void doTestInclusiveStopFilter() throws Exception { - // Grab rows from group one - - // If we just use start/stop row, we get total/2 - 1 rows - long expectedRows = (this.numRows / 2) - 1; - long expectedKeys = this.colsPerRow; - Scan s = new Scan(Bytes.toBytes("testRowOne-0"), - Bytes.toBytes("testRowOne-3")); - verifyScan(s, expectedRows, expectedKeys); - - // Now use start row with inclusive stop filter - expectedRows = this.numRows / 2; - s = new Scan(Bytes.toBytes("testRowOne-0")); - s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowOne-3"))); - verifyScan(s, expectedRows, expectedKeys); - - // Grab rows from group two - - // If we just use start/stop row, we get total/2 - 1 rows - expectedRows = (this.numRows / 2) - 1; - expectedKeys = this.colsPerRow; - s = new Scan(Bytes.toBytes("testRowTwo-0"), - Bytes.toBytes("testRowTwo-3")); - verifyScan(s, expectedRows, expectedKeys); - - // Now use start row with inclusive stop filter - expectedRows = this.numRows / 2; - s = new Scan(Bytes.toBytes("testRowTwo-0")); - s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowTwo-3"))); - verifyScan(s, expectedRows, expectedKeys); - - } - - void doTestQualifierFilter() throws Exception { - // Match two keys (one from each family) in half the rows - long expectedRows = this.numRows / 2; - long expectedKeys = 2; - Filter f = new QualifierFilter(CompareOp.EQUAL, - new BinaryComparator(Bytes.toBytes("testQualifierOne-2"))); - Scan s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match keys less than same qualifier - // Expect only two keys (one from each family) in half the rows - expectedRows = this.numRows / 2; - expectedKeys = 2; - f = new QualifierFilter(CompareOp.LESS, - new BinaryComparator(Bytes.toBytes("testQualifierOne-2"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match keys less than or equal - // Expect four keys (two from each family) in half the rows - expectedRows = this.numRows / 2; - expectedKeys = 4; - f = new QualifierFilter(CompareOp.LESS_OR_EQUAL, - new BinaryComparator(Bytes.toBytes("testQualifierOne-2"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match keys not equal - // Expect four keys (two from each family) - // Only look in first group of rows - expectedRows = this.numRows / 2; - expectedKeys = 4; - f = new QualifierFilter(CompareOp.NOT_EQUAL, - new BinaryComparator(Bytes.toBytes("testQualifierOne-2"))); - s = new Scan(HConstants.EMPTY_START_ROW, Bytes.toBytes("testRowTwo")); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match keys greater or equal - // Expect four keys (two from each family) - // Only look in first group of rows - expectedRows = this.numRows / 2; - expectedKeys = 4; - f = new QualifierFilter(CompareOp.GREATER_OR_EQUAL, - new BinaryComparator(Bytes.toBytes("testQualifierOne-2"))); - s = new Scan(HConstants.EMPTY_START_ROW, Bytes.toBytes("testRowTwo")); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match keys greater - // Expect two keys (one from each family) - // Only look in first group of rows - expectedRows = this.numRows / 2; - expectedKeys = 2; - f = new QualifierFilter(CompareOp.GREATER, - new BinaryComparator(Bytes.toBytes("testQualifierOne-2"))); - s = new Scan(HConstants.EMPTY_START_ROW, Bytes.toBytes("testRowTwo")); - 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 - f = new QualifierFilter(CompareOp.NOT_EQUAL, - new BinaryComparator(QUALIFIERS_ONE[2])); - s = new Scan(); - s.setFilter(f); - - KeyValue [] kvs = { - // testRowOne-0 - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowOne-2 - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowOne-3 - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowTwo-0 - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-2 - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-3 - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - }; - verifyScanFull(s, kvs); - - // 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")); - s = new Scan(); - s.setFilter(f); - - kvs = new KeyValue [] { - // testRowOne-0 - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowOne-2 - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowOne-3 - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowTwo-0 - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-2 - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-3 - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - }; - verifyScanFull(s, kvs); - } - - void doTestRowFilter() throws Exception { - // Match a single row, all keys - long expectedRows = 1; - long expectedKeys = this.colsPerRow; - Filter f = new RowFilter(CompareOp.EQUAL, - new BinaryComparator(Bytes.toBytes("testRowOne-2"))); - Scan s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match a two rows, one from each group, using regex - expectedRows = 2; - expectedKeys = this.colsPerRow; - f = new RowFilter(CompareOp.EQUAL, - new RegexStringComparator("testRow.+-2")); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match rows less than - // Expect all keys in one row - expectedRows = 1; - expectedKeys = this.colsPerRow; - f = new RowFilter(CompareOp.LESS, - new BinaryComparator(Bytes.toBytes("testRowOne-2"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match rows less than or equal - // Expect all keys in two rows - expectedRows = 2; - expectedKeys = this.colsPerRow; - f = new RowFilter(CompareOp.LESS_OR_EQUAL, - new BinaryComparator(Bytes.toBytes("testRowOne-2"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match rows not equal - // Expect all keys in all but one row - expectedRows = this.numRows - 1; - expectedKeys = this.colsPerRow; - f = new RowFilter(CompareOp.NOT_EQUAL, - new BinaryComparator(Bytes.toBytes("testRowOne-2"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match keys greater or equal - // Expect all keys in all but one row - expectedRows = this.numRows - 1; - expectedKeys = this.colsPerRow; - f = new RowFilter(CompareOp.GREATER_OR_EQUAL, - new BinaryComparator(Bytes.toBytes("testRowOne-2"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match keys greater - // Expect all keys in all but two rows - expectedRows = this.numRows - 2; - expectedKeys = this.colsPerRow; - f = new RowFilter(CompareOp.GREATER, - new BinaryComparator(Bytes.toBytes("testRowOne-2"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match rows not equal to testRowTwo-2 - // Look across rows and fully validate the keys and ordering - // Should see all keys in all rows but testRowTwo-2 - f = new RowFilter(CompareOp.NOT_EQUAL, - new BinaryComparator(Bytes.toBytes("testRowOne-2"))); - s = new Scan(); - s.setFilter(f); - - KeyValue [] kvs = { - // testRowOne-0 - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[1], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[0], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowOne-3 - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[1], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowTwo-0 - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-2 - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-3 - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - }; - verifyScanFull(s, kvs); - - // Test across rows and groups with a regex - // Filter out everything that doesn't match "*-2" - // Expect all keys in two rows - f = new RowFilter(CompareOp.EQUAL, - new RegexStringComparator(".+-2")); - s = new Scan(); - s.setFilter(f); - - kvs = new KeyValue [] { - // testRowOne-2 - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[1], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[1], QUALIFIERS_ONE[2], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[1], QUALIFIERS_ONE[3], VALUES[0]), - // testRowTwo-2 - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]) - }; - verifyScanFull(s, kvs); - } - - void doTestValueFilter() throws Exception { - // Match group one rows - long expectedRows = this.numRows / 2; - long expectedKeys = this.colsPerRow; - Filter f = new ValueFilter(CompareOp.EQUAL, - new BinaryComparator(Bytes.toBytes("testValueOne"))); - Scan s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match group two rows - expectedRows = this.numRows / 2; - expectedKeys = this.colsPerRow; - f = new ValueFilter(CompareOp.EQUAL, - new BinaryComparator(Bytes.toBytes("testValueTwo"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match all values using regex - expectedRows = this.numRows; - expectedKeys = this.colsPerRow; - f = new ValueFilter(CompareOp.EQUAL, - new RegexStringComparator("testValue((One)|(Two))")); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match values less than - // Expect group one rows - expectedRows = this.numRows / 2; - expectedKeys = this.colsPerRow; - f = new ValueFilter(CompareOp.LESS, - new BinaryComparator(Bytes.toBytes("testValueTwo"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match values less than or equal - // Expect all rows - expectedRows = this.numRows; - expectedKeys = this.colsPerRow; - f = new ValueFilter(CompareOp.LESS_OR_EQUAL, - new BinaryComparator(Bytes.toBytes("testValueTwo"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match values less than or equal - // Expect group one rows - expectedRows = this.numRows / 2; - expectedKeys = this.colsPerRow; - f = new ValueFilter(CompareOp.LESS_OR_EQUAL, - new BinaryComparator(Bytes.toBytes("testValueOne"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match values not equal - // Expect half the rows - expectedRows = this.numRows / 2; - expectedKeys = this.colsPerRow; - f = new ValueFilter(CompareOp.NOT_EQUAL, - new BinaryComparator(Bytes.toBytes("testValueOne"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match values greater or equal - // Expect all rows - expectedRows = this.numRows; - expectedKeys = this.colsPerRow; - f = new ValueFilter(CompareOp.GREATER_OR_EQUAL, - new BinaryComparator(Bytes.toBytes("testValueOne"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match values greater - // Expect half rows - expectedRows = this.numRows / 2; - expectedKeys = this.colsPerRow; - f = new ValueFilter(CompareOp.GREATER, - new BinaryComparator(Bytes.toBytes("testValueOne"))); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, expectedRows, expectedKeys); - - // Match values not equal to testValueOne - // Look across rows and fully validate the keys and ordering - // Should see all keys in all group two rows - f = new ValueFilter(CompareOp.NOT_EQUAL, - new BinaryComparator(Bytes.toBytes("testValueOne"))); - s = new Scan(); - s.setFilter(f); - - KeyValue [] kvs = { - // testRowTwo-0 - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-2 - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-3 - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - }; - verifyScanFull(s, kvs); - } - - void doTestSkipFilter() throws Exception { - // Test for qualifier regex: "testQualifierOne-2" - // Should only get rows from second group, and all keys - Filter f = new SkipFilter(new QualifierFilter(CompareOp.NOT_EQUAL, - new BinaryComparator(Bytes.toBytes("testQualifierOne-2")))); - Scan s = new Scan(); - s.setFilter(f); - - KeyValue [] kvs = { - // testRowTwo-0 - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-2 - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - // testRowTwo-3 - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), - }; - verifyScanFull(s, kvs); - } - - void doTestFilterList() throws Exception { - // Test getting a single row, single key using Row, Qualifier, and Value - // regular expression and substring filters - // Use must pass all - List filters = new ArrayList(); - filters.add(new RowFilter(CompareOp.EQUAL, - new RegexStringComparator(".+-2"))); - filters.add(new QualifierFilter(CompareOp.EQUAL, - new RegexStringComparator(".+-2"))); - filters.add(new ValueFilter(CompareOp.EQUAL, - new SubstringComparator("One"))); - Filter f = new FilterList(Operator.MUST_PASS_ALL, filters); - Scan s = new Scan(); - s.addFamily(FAMILIES[0]); - s.setFilter(f); - KeyValue [] kvs = { - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]) - }; - verifyScanFull(s, kvs); - - // Test getting everything with a MUST_PASS_ONE filter including row, qf, - // val, regular expression and substring filters - filters.clear(); - filters.add(new RowFilter(CompareOp.EQUAL, - new RegexStringComparator(".+Two.+"))); - filters.add(new QualifierFilter(CompareOp.EQUAL, - new RegexStringComparator(".+-2"))); - filters.add(new ValueFilter(CompareOp.EQUAL, - new SubstringComparator("One"))); - f = new FilterList(Operator.MUST_PASS_ONE, filters); - s = new Scan(); - s.setFilter(f); - verifyScanNoEarlyOut(s, this.numRows, this.colsPerRow); - } - - void doTestFirstKeyOnlyFilter() throws Exception { - Scan s = new Scan(); - s.setFilter(new FirstKeyOnlyFilter()); - // Expected KVs, the first KV from each of the remaining 6 rows - KeyValue [] kvs = { - new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]), - new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), - new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]) - }; - verifyScanFull(s, kvs); - } - - public void testScannersWithFilters() throws Exception { - doTestNoFilter(); - doTestPrefixFilter(); - doTestPageFilter(); - doTestInclusiveStopFilter(); - doTestQualifierFilter(); - doTestRowFilter(); - doTestValueFilter(); - doTestSkipFilter(); - doTestFilterList(); - doTestFirstKeyOnlyFilter(); - } -} Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestSchemaResource.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestSchemaResource.java?rev=1594423&r1=1594422&r2=1594423&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestSchemaResource.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestSchemaResource.java Wed May 14 00:26:57 2014 @@ -1,138 +0,0 @@ -/* - * Copyright 2010 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hbase.rest; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.StringWriter; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; - -import org.apache.hadoop.hbase.client.HBaseAdmin; -import org.apache.hadoop.hbase.rest.client.Client; -import org.apache.hadoop.hbase.rest.client.Cluster; -import org.apache.hadoop.hbase.rest.client.Response; -import org.apache.hadoop.hbase.rest.model.ColumnSchemaModel; -import org.apache.hadoop.hbase.rest.model.TableSchemaModel; -import org.apache.hadoop.hbase.rest.model.TestTableSchemaModel; -import org.apache.hadoop.hbase.util.Bytes; - -public class TestSchemaResource extends HBaseRESTClusterTestBase { - static String TABLE1 = "TestSchemaResource1"; - static String TABLE2 = "TestSchemaResource2"; - - Client client; - JAXBContext context; - HBaseAdmin admin; - - @Override - protected void setUp() throws Exception { - super.setUp(); - context = JAXBContext.newInstance( - ColumnSchemaModel.class, - TableSchemaModel.class); - admin = new HBaseAdmin(conf); - client = new Client(new Cluster().add("localhost", testServletPort)); - } - - @Override - protected void tearDown() throws Exception { - client.shutdown(); - super.tearDown(); - } - - byte[] toXML(TableSchemaModel model) throws JAXBException { - StringWriter writer = new StringWriter(); - context.createMarshaller().marshal(model, writer); - return Bytes.toBytes(writer.toString()); - } - - TableSchemaModel fromXML(byte[] content) throws JAXBException { - return (TableSchemaModel) context.createUnmarshaller() - .unmarshal(new ByteArrayInputStream(content)); - } - - void doTestTableCreateAndDeleteXML() throws IOException, JAXBException { - String schemaPath = "/" + TABLE1 + "/schema"; - TableSchemaModel model; - Response response; - - assertFalse(admin.tableExists(TABLE1)); - - // create the table - model = TestTableSchemaModel.buildTestModel(TABLE1); - TestTableSchemaModel.checkModel(model, TABLE1); - response = client.put(schemaPath, MIMETYPE_XML, toXML(model)); - assertEquals(response.getCode(), 201); - - // make sure HBase concurs, and wait for the table to come online - admin.enableTable(TABLE1); - - // retrieve the schema and validate it - response = client.get(schemaPath, MIMETYPE_XML); - assertEquals(response.getCode(), 200); - model = fromXML(response.getBody()); - TestTableSchemaModel.checkModel(model, TABLE1); - - // delete the table - client.delete(schemaPath); - - // make sure HBase concurs - assertFalse(admin.tableExists(TABLE1)); - } - - void doTestTableCreateAndDeletePB() throws IOException, JAXBException { - String schemaPath = "/" + TABLE2 + "/schema"; - TableSchemaModel model; - Response response; - - assertFalse(admin.tableExists(TABLE2)); - - // create the table - model = TestTableSchemaModel.buildTestModel(TABLE2); - TestTableSchemaModel.checkModel(model, TABLE2); - response = client.put(schemaPath, Constants.MIMETYPE_PROTOBUF, - model.createProtobufOutput()); - assertEquals(response.getCode(), 201); - - // make sure HBase concurs, and wait for the table to come online - admin.enableTable(TABLE2); - - // retrieve the schema and validate it - response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF); - assertEquals(response.getCode(), 200); - model = new TableSchemaModel(); - model.getObjectFromMessage(response.getBody()); - TestTableSchemaModel.checkModel(model, TABLE2); - - // delete the table - client.delete(schemaPath); - - // make sure HBase concurs - assertFalse(admin.tableExists(TABLE2)); - } - - public void testSchemaResource() throws Exception { - doTestTableCreateAndDeleteXML(); - doTestTableCreateAndDeletePB(); - } -} Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java?rev=1594423&r1=1594422&r2=1594423&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java Wed May 14 00:26:57 2014 @@ -1,104 +0,0 @@ -/* - * Copyright 2010 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hbase.rest; - -import java.io.ByteArrayInputStream; -import java.io.IOException; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; - -import org.apache.hadoop.hbase.rest.client.Client; -import org.apache.hadoop.hbase.rest.client.Cluster; -import org.apache.hadoop.hbase.rest.client.Response; -import org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel; -import org.apache.hadoop.hbase.util.Bytes; - -public class TestStatusResource extends HBaseRESTClusterTestBase { - static final byte[] ROOT_REGION_NAME = Bytes.toBytes("-ROOT-,,0"); - static final byte[] META_REGION_NAME = Bytes.toBytes(".META.,,1"); - - Client client; - JAXBContext context; - - @Override - protected void setUp() throws Exception { - super.setUp(); - context = JAXBContext.newInstance( - StorageClusterStatusModel.class); - client = new Client(new Cluster().add("localhost", testServletPort)); - } - - @Override - protected void tearDown() throws Exception { - client.shutdown(); - super.tearDown(); - } - - void validate(StorageClusterStatusModel model) { - assertNotNull(model); - assertTrue(model.getRegions() >= 2); - assertTrue(model.getRequests() >= 0); - // assumes minicluster with two regionservers - assertTrue(model.getAverageLoad() >= 1.0); - assertNotNull(model.getLiveNodes()); - assertNotNull(model.getDeadNodes()); - assertFalse(model.getLiveNodes().isEmpty()); - boolean foundRoot = false, foundMeta = false; - for (StorageClusterStatusModel.Node node: model.getLiveNodes()) { - assertNotNull(node.getName()); - assertTrue(node.getStartCode() > 0L); - assertTrue(node.getRequests() >= 0); - assertFalse(node.getRegions().isEmpty()); - for (StorageClusterStatusModel.Node.Region region: node.getRegions()) { - if (Bytes.equals(region.getName(), ROOT_REGION_NAME)) { - foundRoot = true; - } else if (Bytes.equals(region.getName(), META_REGION_NAME)) { - foundMeta = true; - } - } - } - assertTrue(foundRoot); - assertTrue(foundMeta); - } - - void doTestGetClusterStatusXML() throws IOException, JAXBException { - Response response = client.get("/status/cluster", MIMETYPE_XML); - assertEquals(response.getCode(), 200); - StorageClusterStatusModel model = (StorageClusterStatusModel) - context.createUnmarshaller().unmarshal( - new ByteArrayInputStream(response.getBody())); - validate(model); - } - - void doTestGetClusterStatusPB() throws IOException { - Response response = client.get("/status/cluster", MIMETYPE_PROTOBUF); - assertEquals(response.getCode(), 200); - StorageClusterStatusModel model = new StorageClusterStatusModel(); - model.getObjectFromMessage(response.getBody()); - validate(model); - } - - public void testStatusResource() throws Exception { - doTestGetClusterStatusXML(); - doTestGetClusterStatusPB(); - } -} Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java?rev=1594423&r1=1594422&r2=1594423&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java Wed May 14 00:26:57 2014 @@ -1,229 +0,0 @@ -/* - * Copyright 2010 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hbase.rest; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Iterator; -import java.util.Map; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HRegionInfo; -import org.apache.hadoop.hbase.HServerAddress; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.client.HBaseAdmin; -import org.apache.hadoop.hbase.client.HTable; -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.rest.client.Client; -import org.apache.hadoop.hbase.rest.client.Cluster; -import org.apache.hadoop.hbase.rest.client.Response; -import org.apache.hadoop.hbase.rest.model.TableModel; -import org.apache.hadoop.hbase.rest.model.TableInfoModel; -import org.apache.hadoop.hbase.rest.model.TableListModel; -import org.apache.hadoop.hbase.rest.model.TableRegionModel; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.util.StringUtils; - -public class TestTableResource extends HBaseRESTClusterTestBase { - static final Log LOG = LogFactory.getLog(TestTableResource.class); - - static String TABLE = "TestTableResource"; - static String COLUMN_FAMILY = "test"; - static String COLUMN = COLUMN_FAMILY + ":qualifier"; - static Map regionMap; - - Client client; - JAXBContext context; - HBaseAdmin admin; - - @Override - protected void setUp() throws Exception { - super.setUp(); - context = JAXBContext.newInstance( - TableModel.class, - TableInfoModel.class, - TableListModel.class, - TableRegionModel.class); - client = new Client(new Cluster().add("localhost", testServletPort)); - admin = new HBaseAdmin(conf); - if (admin.tableExists(TABLE)) { - return; - } - HTableDescriptor htd = new HTableDescriptor(TABLE); - htd.addFamily(new HColumnDescriptor(COLUMN_FAMILY)); - admin.createTable(htd); - HTable table = new HTable(conf, TABLE); - byte[] k = new byte[3]; - byte [][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(COLUMN)); - for (byte b1 = 'a'; b1 < 'z'; b1++) { - for (byte b2 = 'a'; b2 < 'z'; b2++) { - for (byte b3 = 'a'; b3 < 'z'; b3++) { - k[0] = b1; - k[1] = b2; - k[2] = b3; - Put put = new Put(k); - put.add(famAndQf[0], famAndQf[1], k); - table.put(put); - } - } - } - table.flushCommits(); - // get the initial layout (should just be one region) - Map m = table.getRegionsInfo(); - assertEquals(m.size(), 1); - // tell the master to split the table - admin.split(TABLE); - // give some time for the split to happen - try { - Thread.sleep(15 * 1000); - } catch (InterruptedException e) { - LOG.warn(StringUtils.stringifyException(e)); - } - // check again - m = table.getRegionsInfo(); - // should have two regions now - assertEquals(m.size(), 2); - regionMap = m; - LOG.info("regions: " + regionMap); - } - - @Override - protected void tearDown() throws Exception { - client.shutdown(); - super.tearDown(); - } - - void checkTableList(TableListModel model) { - boolean found = false; - Iterator tables = model.getTables().iterator(); - assertTrue(tables.hasNext()); - while (tables.hasNext()) { - TableModel table = tables.next(); - if (table.getName().equals(TABLE)) { - found = true; - break; - } - } - assertTrue(found); - } - - void doTestTableListText() throws IOException { - Response response = client.get("/", MIMETYPE_TEXT); - assertEquals(response.getCode(), 200); - } - - void doTestTableListXML() throws IOException, JAXBException { - Response response = client.get("/", MIMETYPE_XML); - assertEquals(response.getCode(), 200); - TableListModel model = (TableListModel) - context.createUnmarshaller() - .unmarshal(new ByteArrayInputStream(response.getBody())); - checkTableList(model); - } - - void doTestTableListJSON() throws IOException { - Response response = client.get("/", MIMETYPE_JSON); - assertEquals(response.getCode(), 200); - } - - void doTestTableListPB() throws IOException, JAXBException { - Response response = client.get("/", MIMETYPE_PROTOBUF); - assertEquals(response.getCode(), 200); - TableListModel model = new TableListModel(); - model.getObjectFromMessage(response.getBody()); - checkTableList(model); - } - - public void checkTableInfo(TableInfoModel model) { - assertEquals(model.getName(), TABLE); - Iterator regions = model.getRegions().iterator(); - assertTrue(regions.hasNext()); - while (regions.hasNext()) { - TableRegionModel region = regions.next(); - boolean found = false; - for (Map.Entry e: regionMap.entrySet()) { - HRegionInfo hri = e.getKey(); - String hriRegionName = hri.getRegionNameAsString(); - String regionName = region.getName(); - if (hriRegionName.startsWith(regionName)) { - found = true; - byte[] startKey = hri.getStartKey(); - byte[] endKey = hri.getEndKey(); - InetSocketAddress sa = e.getValue().getInetSocketAddress(); - String location = sa.getHostName() + ":" + - Integer.valueOf(sa.getPort()); - assertEquals(hri.getRegionId(), region.getId()); - assertTrue(Bytes.equals(startKey, region.getStartKey())); - assertTrue(Bytes.equals(endKey, region.getEndKey())); - assertEquals(location, region.getLocation()); - break; - } - } - assertTrue(found); - } - } - - void doTestTableInfoText() throws IOException { - Response response = client.get("/" + TABLE + "/regions", MIMETYPE_TEXT); - assertEquals(response.getCode(), 200); - } - - void doTestTableInfoXML() throws IOException, JAXBException { - Response response = client.get("/" + TABLE + "/regions", MIMETYPE_XML); - assertEquals(response.getCode(), 200); - TableInfoModel model = (TableInfoModel) - context.createUnmarshaller() - .unmarshal(new ByteArrayInputStream(response.getBody())); - checkTableInfo(model); - } - - void doTestTableInfoJSON() throws IOException { - Response response = client.get("/" + TABLE + "/regions", MIMETYPE_JSON); - assertEquals(response.getCode(), 200); - } - - void doTestTableInfoPB() throws IOException, JAXBException { - Response response = - client.get("/" + TABLE + "/regions", MIMETYPE_PROTOBUF); - assertEquals(response.getCode(), 200); - TableInfoModel model = new TableInfoModel(); - model.getObjectFromMessage(response.getBody()); - checkTableInfo(model); - } - - public void testTableResource() throws Exception { - doTestTableListText(); - doTestTableListXML(); - doTestTableListJSON(); - doTestTableListPB(); - doTestTableInfoText(); - doTestTableInfoXML(); - doTestTableInfoJSON(); - doTestTableInfoPB(); - } -}