001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.client;
019
020import java.util.ArrayList;
021import java.util.List;
022import java.util.concurrent.ForkJoinPool;
023import java.util.function.Supplier;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.testclassification.ClientTests;
026import org.apache.hadoop.hbase.testclassification.LargeTests;
027import org.junit.ClassRule;
028import org.junit.experimental.categories.Category;
029import org.junit.runner.RunWith;
030import org.junit.runners.Parameterized;
031import org.junit.runners.Parameterized.Parameter;
032import org.junit.runners.Parameterized.Parameters;
033
034@RunWith(Parameterized.class)
035@Category({ LargeTests.class, ClientTests.class })
036public class TestAsyncTableScanner extends AbstractTestAsyncTableScan {
037
038  @ClassRule
039  public static final HBaseClassTestRule CLASS_RULE =
040      HBaseClassTestRule.forClass(TestAsyncTableScanner.class);
041
042  @Parameter(0)
043  public String tableType;
044
045  @Parameter(1)
046  public Supplier<AsyncTable<?>> getTable;
047
048  @Parameter(2)
049  public String scanType;
050
051  @Parameter(3)
052  public Supplier<Scan> scanCreator;
053
054  @Parameters(name = "{index}: table={0}, scan={2}")
055  public static List<Object[]> params() {
056    return getTableAndScanCreatorParams();
057  }
058
059  @Override
060  protected Scan createScan() {
061    return scanCreator.get();
062  }
063
064  @Override
065  protected List<Result> doScan(Scan scan) throws Exception {
066    AsyncTable<?> table = ASYNC_CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool());
067    List<Result> results = new ArrayList<>();
068    try (ResultScanner scanner = table.getScanner(scan)) {
069      for (Result result; (result = scanner.next()) != null;) {
070        results.add(result);
071      }
072    }
073    if (scan.getBatch() > 0) {
074      results = convertFromBatchResult(results);
075    }
076    return results;
077  }
078}