HBASE-26567 Remove IndexType from ChunkCreator (#3947)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestAsyncTableLocatePrefetch.java
blob245d755548403bc7f5da3b4e71aa3448b6140d98
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.assertNotNull;
22 import java.util.concurrent.ExecutionException;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
24 import org.apache.hadoop.hbase.HBaseTestingUtil;
25 import org.apache.hadoop.hbase.TableName;
26 import org.apache.hadoop.hbase.testclassification.ClientTests;
27 import org.apache.hadoop.hbase.testclassification.MediumTests;
28 import org.apache.hadoop.hbase.util.Bytes;
29 import org.junit.AfterClass;
30 import org.junit.BeforeClass;
31 import org.junit.ClassRule;
32 import org.junit.Test;
33 import org.junit.experimental.categories.Category;
35 import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
37 @Category({ MediumTests.class, ClientTests.class })
38 public class TestAsyncTableLocatePrefetch {
40 @ClassRule
41 public static final HBaseClassTestRule CLASS_RULE =
42 HBaseClassTestRule.forClass(TestAsyncTableLocatePrefetch.class);
44 private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
46 private static TableName TABLE_NAME = TableName.valueOf("async");
48 private static byte[] FAMILY = Bytes.toBytes("cf");
50 private static AsyncConnection CONN;
52 private static AsyncNonMetaRegionLocator LOCATOR;
54 @BeforeClass
55 public static void setUp() throws Exception {
56 TEST_UTIL.getConfiguration().setInt(AsyncNonMetaRegionLocator.LOCATE_PREFETCH_LIMIT, 100);
57 TEST_UTIL.startMiniCluster(3);
58 TEST_UTIL.createMultiRegionTable(TABLE_NAME, FAMILY);
59 TEST_UTIL.waitTableAvailable(TABLE_NAME);
60 CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
61 LOCATOR = new AsyncNonMetaRegionLocator((AsyncConnectionImpl) CONN);
64 @AfterClass
65 public static void tearDown() throws Exception {
66 Closeables.close(CONN, true);
67 TEST_UTIL.shutdownMiniCluster();
70 @Test
71 public void test() throws InterruptedException, ExecutionException {
72 assertNotNull(LOCATOR.getRegionLocations(TABLE_NAME, Bytes.toBytes("zzz"),
73 RegionReplicaUtil.DEFAULT_REPLICA_ID, RegionLocateType.CURRENT, false).get());
74 // we finish the request before we adding the remaining results to cache so sleep a bit here
75 Thread.sleep(1000);
76 // confirm that the locations of all the regions have been cached.
77 assertNotNull(LOCATOR.getRegionLocationInCache(TABLE_NAME, Bytes.toBytes("aaa")));
78 for (byte[] row : HBaseTestingUtil.KEYS_FOR_HBA_CREATE_TABLE) {
79 assertNotNull(LOCATOR.getRegionLocationInCache(TABLE_NAME, row));