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 E1AA018938 for ; Mon, 26 Oct 2015 17:34:08 +0000 (UTC) Received: (qmail 33720 invoked by uid 500); 26 Oct 2015 17:34:08 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 33595 invoked by uid 500); 26 Oct 2015 17:34:08 -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 33199 invoked by uid 99); 26 Oct 2015 17:34:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Oct 2015 17:34:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CB6E1E08CD; Mon, 26 Oct 2015 17:34:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: syuanjiang@apache.org To: commits@hbase.apache.org Date: Mon, 26 Oct 2015 17:34:13 -0000 Message-Id: <7d65d7b2657243068b0e413f1d7bd687@git.apache.org> In-Reply-To: <6e215107a0774303a2c8eceb02a0da89@git.apache.org> References: <6e215107a0774303a2c8eceb02a0da89@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/14] hbase git commit: HBASE-14676 HBaseTestCase clean out: Purge Incommon Interface and Table and Region implementations: ADDENDUM -- forgot to add file HBASE-14676 HBaseTestCase clean out: Purge Incommon Interface and Table and Region implementations: ADDENDUM -- forgot to add file Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/80a6fd01 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/80a6fd01 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/80a6fd01 Branch: refs/heads/hbase-12439 Commit: 80a6fd01a170fd2e4798eaa44f6cd3e0c7b63d4c Parents: 9925e9a Author: stack Authored: Sat Oct 24 11:09:08 2015 -0700 Committer: stack Committed: Sat Oct 24 11:09:18 2015 -0700 ---------------------------------------------------------------------- .../hbase/regionserver/RegionAsTable.java | 324 +++++++++++++++++++ 1 file changed, 324 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/80a6fd01/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/RegionAsTable.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/RegionAsTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/RegionAsTable.java new file mode 100644 index 0000000..f65bc5d --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/RegionAsTable.java @@ -0,0 +1,324 @@ +/** + * 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.regionserver; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Append; +import org.apache.hadoop.hbase.client.Delete; +import org.apache.hadoop.hbase.client.Durability; +import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.client.Increment; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.client.Row; +import org.apache.hadoop.hbase.client.RowMutations; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.client.coprocessor.Batch.Call; +import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback; +import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp; +import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel; + +import com.google.protobuf.Descriptors.MethodDescriptor; +import com.google.protobuf.Message; +import com.google.protobuf.Service; +import com.google.protobuf.ServiceException; + +/** + * An implementation of {@link Table} that sits directly on a Region; it decorates the passed in + * Region instance with the Table API. Some API is not implemented yet (throws + * {@link UnsupportedOperationException}) mostly because no need as yet or it necessitates copying + * a load of code local from RegionServer. + * + *

Use as an instance of a {@link Table} in-the-small -- no networking or servers + * necessary -- or to write a test that can run directly against the datastore and then + * over the network. + */ +public class RegionAsTable implements Table { + private final Region region; + + /** + * @param region Region to decorate with Table API. + */ + public RegionAsTable(final Region region) { + this.region = region; + } + + @Override + public TableName getName() { + return this.region.getTableDesc().getTableName(); + } + + @Override + public Configuration getConfiguration() { + throw new UnsupportedOperationException(); + } + + @Override + public HTableDescriptor getTableDescriptor() throws IOException { + return this.region.getTableDesc(); + } + + @Override + public boolean exists(Get get) throws IOException { + if (!get.isCheckExistenceOnly()) throw new IllegalArgumentException(); + return get(get) != null; + } + + @Override + public boolean[] existsAll(List gets) throws IOException { + boolean [] results = new boolean[gets.size()]; + int index = 0; + for (Get get: gets) { + results[index++] = exists(get); + } + return results; + } + + @Override + public void batch(List actions, Object[] results) + throws IOException, InterruptedException { + throw new UnsupportedOperationException(); + } + + @Override + public void batchCallback(List actions, Object[] results, + Callback callback) + throws IOException, InterruptedException { + throw new UnsupportedOperationException(); + } + + @Override + public Result get(Get get) throws IOException { + return this.region.get(get); + } + + @Override + public Result[] get(List gets) throws IOException { + Result [] results = new Result[gets.size()]; + int index = 0; + for (Get get: gets) { + results[index++] = get(get); + } + return results; + } + + static class RegionScannerToResultScannerAdaptor implements ResultScanner { + private static final Result [] EMPTY_RESULT_ARRAY = new Result[0]; + private final RegionScanner regionScanner; + + RegionScannerToResultScannerAdaptor(final RegionScanner regionScanner) { + this.regionScanner = regionScanner; + } + + @Override + public Iterator iterator() { + throw new UnsupportedOperationException(); + } + + @Override + public Result next() throws IOException { + List cells = new ArrayList(); + return regionScanner.next(cells)? Result.create(cells): null; + } + + @Override + public Result[] next(int nbRows) throws IOException { + List results = new ArrayList(nbRows); + for (int i = 0; i < nbRows; i++) { + Result result = next(); + if (result == null) break; + results.add(result); + } + return results.toArray(EMPTY_RESULT_ARRAY); + } + + @Override + public void close() { + try { + regionScanner.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean renewLease() { + throw new UnsupportedOperationException(); + } + }; + + @Override + public ResultScanner getScanner(Scan scan) throws IOException { + return new RegionScannerToResultScannerAdaptor(this.region.getScanner(scan)); + } + + @Override + public ResultScanner getScanner(byte[] family) throws IOException { + return getScanner(new Scan().addFamily(family)); + } + + @Override + public ResultScanner getScanner(byte[] family, byte[] qualifier) throws IOException { + return getScanner(new Scan().addColumn(family, qualifier)); + } + + @Override + public void put(Put put) throws IOException { + this.region.put(put); + } + + @Override + public void put(List puts) throws IOException { + for (Put put: puts) put(put); + } + + @Override + public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put) + throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp, + byte[] value, Put put) + throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void delete(Delete delete) throws IOException { + this.region.delete(delete); + } + + @Override + public void delete(List deletes) throws IOException { + for(Delete delete: deletes) delete(delete); + } + + @Override + public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, byte[] value, + Delete delete) + throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, + CompareOp compareOp, byte[] value, Delete delete) + throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void mutateRow(RowMutations rm) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public Result append(Append append) throws IOException { + return this.region.append(append, HConstants.NO_NONCE, HConstants.NO_NONCE); + } + + @Override + public Result increment(Increment increment) throws IOException { + return this.region.increment(increment, HConstants.NO_NONCE, HConstants.NO_NONCE); + } + + @Override + public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount) + throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount, + Durability durability) + throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * This call will NOT close the underlying region. + */ + @Override + public void close() throws IOException { + } + + @Override + public CoprocessorRpcChannel coprocessorService(byte[] row) { + throw new UnsupportedOperationException(); + } + + @Override + public Map coprocessorService(Class service, byte[] startKey, + byte[] endKey, Call callable) + throws ServiceException, Throwable { + throw new UnsupportedOperationException(); + } + + @Override + public void coprocessorService(Class service, byte[] startKey, + byte[] endKey, Call callable, Callback callback) + throws ServiceException, Throwable { + throw new UnsupportedOperationException(); + } + + @Override + public long getWriteBufferSize() { + throw new UnsupportedOperationException(); + } + + @Override + public void setWriteBufferSize(long writeBufferSize) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public Map batchCoprocessorService(MethodDescriptor + methodDescriptor, Message request, + byte[] startKey, byte[] endKey, R responsePrototype) + throws ServiceException, Throwable { + throw new UnsupportedOperationException(); + } + + @Override + public void batchCoprocessorService(MethodDescriptor methodDescriptor, + Message request, byte[] startKey, byte[] endKey, R responsePrototype, Callback callback) + throws ServiceException, Throwable { + throw new UnsupportedOperationException(); + } + + @Override + public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp, + byte[] value, RowMutations mutation) + throws IOException { + throw new UnsupportedOperationException(); + } +} \ No newline at end of file