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.jupiter.api.Assertions.assertArrayEquals; 021import static org.junit.jupiter.api.Assertions.assertNotNull; 022 023import java.io.IOException; 024import java.util.function.Supplier; 025import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; 026import org.apache.hadoop.hbase.testclassification.ClientTests; 027import org.apache.hadoop.hbase.testclassification.MediumTests; 028import org.apache.hadoop.hbase.util.Bytes; 029import org.junit.jupiter.api.BeforeAll; 030import org.junit.jupiter.api.Tag; 031 032@Tag(MediumTests.TAG) 033@Tag(ClientTests.TAG) 034@HBaseParameterizedTestTemplate 035public class TestAsyncTableRegionReplicasScan extends AbstractTestAsyncTableRegionReplicasRead { 036 037 private static int ROW_COUNT = 1000; 038 039 public TestAsyncTableRegionReplicasScan(Supplier<AsyncTable<?>> getTable) { 040 super(getTable); 041 } 042 043 private static byte[] getRow(int i) { 044 return Bytes.toBytes(String.format("%s-%03d", Bytes.toString(ROW), i)); 045 } 046 047 private static byte[] getValue(int i) { 048 return Bytes.toBytes(String.format("%s-%03d", Bytes.toString(VALUE), i)); 049 } 050 051 @BeforeAll 052 public static void setUpBeforeClass() throws Exception { 053 startClusterAndCreateTable(); 054 AsyncTable<?> table = ASYNC_CONN.getTable(TABLE_NAME); 055 for (int i = 0; i < ROW_COUNT; i++) { 056 table.put(new Put(getRow(i)).addColumn(FAMILY, QUALIFIER, getValue(i))).get(); 057 } 058 waitUntilAllReplicasHaveRow(getRow(ROW_COUNT - 1)); 059 } 060 061 @Override 062 protected void readAndCheck(AsyncTable<?> table, int replicaId) throws IOException { 063 Scan scan = new Scan().setConsistency(Consistency.TIMELINE).setCaching(1); 064 if (replicaId >= 0) { 065 scan.setReplicaId(replicaId); 066 } 067 try (ResultScanner scanner = table.getScanner(scan)) { 068 for (int i = 0; i < ROW_COUNT; i++) { 069 Result result = scanner.next(); 070 assertNotNull(result); 071 assertArrayEquals(getValue(i), result.getValue(FAMILY, QUALIFIER)); 072 } 073 } 074 } 075}