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