HBASE-26481 Consider rolling upgrading from old region replication framework (#3880)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestClientSideRegionScanner.java
blob859e36f00cbb35413abfc84daba460650f38cff8
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;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertTrue;
23 import java.io.IOException;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.fs.FileSystem;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.hbase.HBaseClassTestRule;
28 import org.apache.hadoop.hbase.HBaseTestingUtil;
29 import org.apache.hadoop.hbase.HConstants;
30 import org.apache.hadoop.hbase.TableName;
31 import org.apache.hadoop.hbase.io.hfile.BlockCache;
32 import org.apache.hadoop.hbase.io.hfile.IndexOnlyLruBlockCache;
33 import org.apache.hadoop.hbase.testclassification.ClientTests;
34 import org.apache.hadoop.hbase.testclassification.SmallTests;
35 import org.junit.AfterClass;
36 import org.junit.Before;
37 import org.junit.BeforeClass;
38 import org.junit.ClassRule;
39 import org.junit.Test;
40 import org.junit.experimental.categories.Category;
42 @Category({ SmallTests.class, ClientTests.class })
43 public class TestClientSideRegionScanner {
44 @ClassRule
45 public static final HBaseClassTestRule CLASS_RULE =
46 HBaseClassTestRule.forClass(TestClientSideRegionScanner.class);
48 private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
50 private Configuration conf;
51 private Path rootDir;
52 private FileSystem fs;
53 private TableDescriptor htd;
54 private RegionInfo hri;
55 private Scan scan;
57 @BeforeClass
58 public static void setUpBeforeClass() throws Exception {
59 TEST_UTIL.startMiniCluster(1);
62 @AfterClass
63 public static void tearDownAfterClass() throws Exception {
64 TEST_UTIL.shutdownMiniCluster();
67 @Before
68 public void setup() throws IOException {
69 conf = TEST_UTIL.getConfiguration();
70 rootDir = TEST_UTIL.getDefaultRootDirPath();
71 fs = TEST_UTIL.getTestFileSystem();
72 htd = TEST_UTIL.getAdmin().getDescriptor(TableName.META_TABLE_NAME);
73 hri = TEST_UTIL.getAdmin().getRegions(TableName.META_TABLE_NAME).get(0);
74 scan = new Scan();
77 @Test
78 public void testDefaultBlockCache() throws IOException {
79 Configuration copyConf = new Configuration(conf);
80 ClientSideRegionScanner clientSideRegionScanner =
81 new ClientSideRegionScanner(copyConf, fs, rootDir, htd, hri, scan, null);
83 BlockCache blockCache = clientSideRegionScanner.getRegion().getBlockCache();
84 assertNotNull(blockCache);
85 assertTrue(blockCache instanceof IndexOnlyLruBlockCache);
86 assertTrue(HConstants.HBASE_CLIENT_SCANNER_ONHEAP_BLOCK_CACHE_FIXED_SIZE_DEFAULT == blockCache
87 .getMaxSize());
90 @Test
91 public void testConfiguredBlockCache() throws IOException {
92 Configuration copyConf = new Configuration(conf);
93 // tiny 1MB fixed cache size
94 long blockCacheFixedSize = 1024 * 1024L;
95 copyConf.setLong(HConstants.HFILE_ONHEAP_BLOCK_CACHE_FIXED_SIZE_KEY, blockCacheFixedSize);
96 ClientSideRegionScanner clientSideRegionScanner =
97 new ClientSideRegionScanner(copyConf, fs, rootDir, htd, hri, scan, null);
99 BlockCache blockCache = clientSideRegionScanner.getRegion().getBlockCache();
100 assertNotNull(blockCache);
101 assertTrue(blockCache instanceof IndexOnlyLruBlockCache);
102 assertTrue(blockCacheFixedSize == blockCache.getMaxSize());
105 @Test
106 public void testNoBlockCache() throws IOException {
107 Configuration copyConf = new Configuration(conf);
108 copyConf.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0.0f);
109 ClientSideRegionScanner clientSideRegionScanner =
110 new ClientSideRegionScanner(copyConf, fs, rootDir, htd, hri, scan, null);
112 BlockCache blockCache = clientSideRegionScanner.getRegion().getBlockCache();
113 assertNull(blockCache);