HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestAsyncTableRegionReplicasScan.java
blobbd0f00c4864be205427be957eb3401da372bbe88
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.client;
20 import static org.junit.Assert.assertArrayEquals;
21 import static org.junit.Assert.assertNotNull;
23 import java.io.IOException;
24 import org.apache.hadoop.hbase.HBaseClassTestRule;
25 import org.apache.hadoop.hbase.testclassification.ClientTests;
26 import org.apache.hadoop.hbase.testclassification.MediumTests;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.junit.BeforeClass;
29 import org.junit.ClassRule;
30 import org.junit.experimental.categories.Category;
31 import org.junit.runner.RunWith;
32 import org.junit.runners.Parameterized;
34 @RunWith(Parameterized.class)
35 @Category({ MediumTests.class, ClientTests.class })
36 public class TestAsyncTableRegionReplicasScan extends AbstractTestAsyncTableRegionReplicasRead {
38 @ClassRule
39 public static final HBaseClassTestRule CLASS_RULE =
40 HBaseClassTestRule.forClass(TestAsyncTableRegionReplicasScan.class);
42 private static int ROW_COUNT = 1000;
44 private static byte[] getRow(int i) {
45 return Bytes.toBytes(String.format("%s-%03d", Bytes.toString(ROW), i));
48 private static byte[] getValue(int i) {
49 return Bytes.toBytes(String.format("%s-%03d", Bytes.toString(VALUE), i));
52 @BeforeClass
53 public static void setUpBeforeClass() throws Exception {
54 startClusterAndCreateTable();
55 AsyncTable<?> table = ASYNC_CONN.getTable(TABLE_NAME);
56 for (int i = 0; i < ROW_COUNT; i++) {
57 table.put(new Put(getRow(i)).addColumn(FAMILY, QUALIFIER, getValue(i))).get();
59 waitUntilAllReplicasHaveRow(getRow(ROW_COUNT - 1));
62 @Override
63 protected void readAndCheck(AsyncTable<?> table, int replicaId) throws IOException {
64 Scan scan = new Scan().setConsistency(Consistency.TIMELINE).setCaching(1);
65 if (replicaId >= 0) {
66 scan.setReplicaId(replicaId);
68 try (ResultScanner scanner = table.getScanner(scan)) {
69 for (int i = 0; i < ROW_COUNT; i++) {
70 Result result = scanner.next();
71 assertNotNull(result);
72 assertArrayEquals(getValue(i), result.getValue(FAMILY, QUALIFIER));