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 static org.junit.Assert.assertArrayEquals;
021import static org.junit.Assert.assertFalse;
022import static org.junit.Assert.assertTrue;
023
024import java.io.IOException;
025import org.junit.Test;
026
027public abstract class AbstractTestResultScannerCursor extends AbstractTestScanCursor {
028
029  protected abstract ResultScanner getScanner(Scan scan) throws Exception;
030
031  @Test
032  public void testHeartbeatWithSparseFilter() throws Exception {
033    try (ResultScanner scanner = getScanner(createScanWithSparseFilter())) {
034      int num = 0;
035      Result r;
036      while ((r = scanner.next()) != null) {
037        if (num < (NUM_ROWS - 1) * NUM_FAMILIES * NUM_QUALIFIERS) {
038          assertTrue(r.isCursor());
039          assertArrayEquals(ROWS[num / NUM_FAMILIES / NUM_QUALIFIERS], r.getCursor().getRow());
040        } else {
041          assertFalse(r.isCursor());
042          assertArrayEquals(ROWS[num / NUM_FAMILIES / NUM_QUALIFIERS], r.getRow());
043        }
044        num++;
045      }
046    }
047  }
048
049  @Test
050  public void testHeartbeatWithSparseFilterReversed() throws Exception {
051    try (ResultScanner scanner = getScanner(createReversedScanWithSparseFilter())) {
052      int num = 0;
053      Result r;
054      while ((r = scanner.next()) != null) {
055        if (num < (NUM_ROWS - 1) * NUM_FAMILIES * NUM_QUALIFIERS) {
056          assertTrue(r.isCursor());
057          assertArrayEquals(ROWS[NUM_ROWS - 1 - num / NUM_FAMILIES / NUM_QUALIFIERS],
058            r.getCursor().getRow());
059        } else {
060          assertFalse(r.isCursor());
061          assertArrayEquals(ROWS[0], r.getRow());
062        }
063        num++;
064      }
065    }
066  }
067
068  @Test
069  public void testSizeLimit() throws IOException {
070    try (ResultScanner scanner =
071      TEST_UTIL.getConnection().getTable(TABLE_NAME).getScanner(createScanWithSizeLimit())) {
072      int num = 0;
073      Result r;
074      while ((r = scanner.next()) != null) {
075        if (num % (NUM_FAMILIES * NUM_QUALIFIERS) != (NUM_FAMILIES * NUM_QUALIFIERS) - 1) {
076          assertTrue(r.isCursor());
077          assertArrayEquals(ROWS[num / NUM_FAMILIES / NUM_QUALIFIERS], r.getCursor().getRow());
078        } else {
079          assertFalse(r.isCursor());
080          assertArrayEquals(ROWS[num / NUM_FAMILIES / NUM_QUALIFIERS], r.getRow());
081        }
082        num++;
083      }
084    }
085  }
086}