HBASE-26481 Consider rolling upgrading from old region replication framework (#3880)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestAllowPartialScanResultCache.java
blob14123b31f5b4d3e9f450300866a0cdcffe4116d7
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.apache.hadoop.hbase.client.TestBatchScanResultCache.createCells;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertSame;
24 import java.io.IOException;
25 import java.util.Arrays;
26 import org.apache.hadoop.hbase.Cell;
27 import org.apache.hadoop.hbase.HBaseClassTestRule;
28 import org.apache.hadoop.hbase.testclassification.ClientTests;
29 import org.apache.hadoop.hbase.testclassification.SmallTests;
30 import org.apache.hadoop.hbase.util.Bytes;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.ClassRule;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
37 @Category({ SmallTests.class, ClientTests.class })
38 public class TestAllowPartialScanResultCache {
40 @ClassRule
41 public static final HBaseClassTestRule CLASS_RULE =
42 HBaseClassTestRule.forClass(TestAllowPartialScanResultCache.class);
44 private static byte[] CF = Bytes.toBytes("cf");
46 private AllowPartialScanResultCache resultCache;
48 @Before
49 public void setUp() {
50 resultCache = new AllowPartialScanResultCache();
53 @After
54 public void tearDown() {
55 resultCache.clear();
56 resultCache = null;
59 @Test
60 public void test() throws IOException {
61 assertSame(ScanResultCache.EMPTY_RESULT_ARRAY,
62 resultCache.addAndGet(ScanResultCache.EMPTY_RESULT_ARRAY, false));
63 assertSame(ScanResultCache.EMPTY_RESULT_ARRAY,
64 resultCache.addAndGet(ScanResultCache.EMPTY_RESULT_ARRAY, true));
66 Cell[] cells1 = createCells(CF, 1, 10);
67 Cell[] cells2 = createCells(CF, 2, 10);
69 Result[] results1 = resultCache.addAndGet(
70 new Result[] { Result.create(Arrays.copyOf(cells1, 5), null, false, true) }, false);
71 assertEquals(1, results1.length);
72 assertEquals(1, Bytes.toInt(results1[0].getRow()));
73 assertEquals(5, results1[0].rawCells().length);
74 for (int i = 0; i < 5; i++) {
75 assertEquals(1, Bytes.toInt(results1[0].getValue(CF, Bytes.toBytes("cq" + i))));
78 Result[] results2 = resultCache.addAndGet(
79 new Result[] { Result.create(Arrays.copyOfRange(cells1, 1, 10), null, false, true) }, false);
80 assertEquals(1, results2.length);
81 assertEquals(1, Bytes.toInt(results2[0].getRow()));
82 assertEquals(5, results2[0].rawCells().length);
83 for (int i = 5; i < 10; i++) {
84 assertEquals(1, Bytes.toInt(results2[0].getValue(CF, Bytes.toBytes("cq" + i))));
87 Result[] results3 =
88 resultCache.addAndGet(new Result[] { Result.create(cells1), Result.create(cells2) }, false);
89 assertEquals(1, results3.length);
90 assertEquals(2, Bytes.toInt(results3[0].getRow()));
91 assertEquals(10, results3[0].rawCells().length);
92 for (int i = 0; i < 10; i++) {
93 assertEquals(2, Bytes.toInt(results3[0].getValue(CF, Bytes.toBytes("cq" + i))));