HBASE-22002 Remove the deprecated methods in Admin interface
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestCompleteResultScanResultCache.java
blobe6b31cb9eaa7ffa60f16d310196f631fa2e78fec
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.assertEquals;
21 import static org.junit.Assert.assertSame;
23 import java.io.IOException;
24 import java.util.Arrays;
25 import org.apache.hadoop.hbase.Cell;
26 import org.apache.hadoop.hbase.HBaseClassTestRule;
27 import org.apache.hadoop.hbase.KeyValue;
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 TestCompleteResultScanResultCache {
40 @ClassRule
41 public static final HBaseClassTestRule CLASS_RULE =
42 HBaseClassTestRule.forClass(TestCompleteResultScanResultCache.class);
44 private static byte[] CF = Bytes.toBytes("cf");
46 private static byte[] CQ1 = Bytes.toBytes("cq1");
48 private static byte[] CQ2 = Bytes.toBytes("cq2");
50 private static byte[] CQ3 = Bytes.toBytes("cq3");
52 private CompleteScanResultCache resultCache;
54 @Before
55 public void setUp() {
56 resultCache = new CompleteScanResultCache();
59 @After
60 public void tearDown() {
61 resultCache.clear();
62 resultCache = null;
65 private static Cell createCell(int key, byte[] cq) {
66 return new KeyValue(Bytes.toBytes(key), CF, cq, Bytes.toBytes(key));
69 @Test
70 public void testNoPartial() throws IOException {
71 assertSame(ScanResultCache.EMPTY_RESULT_ARRAY,
72 resultCache.addAndGet(ScanResultCache.EMPTY_RESULT_ARRAY, false));
73 assertSame(ScanResultCache.EMPTY_RESULT_ARRAY,
74 resultCache.addAndGet(ScanResultCache.EMPTY_RESULT_ARRAY, true));
75 int count = 10;
76 Result[] results = new Result[count];
77 for (int i = 0; i < count; i++) {
78 results[i] = Result.create(Arrays.asList(createCell(i, CQ1)));
80 assertSame(results, resultCache.addAndGet(results, false));
83 @Test
84 public void testCombine1() throws IOException {
85 Result previousResult = Result.create(Arrays.asList(createCell(0, CQ1)), null, false, true);
86 Result result1 = Result.create(Arrays.asList(createCell(1, CQ1)), null, false, true);
87 Result result2 = Result.create(Arrays.asList(createCell(1, CQ2)), null, false, true);
88 Result result3 = Result.create(Arrays.asList(createCell(1, CQ3)), null, false, true);
89 Result[] results = resultCache.addAndGet(new Result[] { previousResult, result1 }, false);
90 assertEquals(1, results.length);
91 assertSame(previousResult, results[0]);
93 assertEquals(0, resultCache.addAndGet(new Result[] { result2 }, false).length);
94 assertEquals(0, resultCache.addAndGet(new Result[] { result3 }, false).length);
95 assertEquals(0, resultCache.addAndGet(new Result[0], true).length);
97 results = resultCache.addAndGet(new Result[0], false);
98 assertEquals(1, results.length);
99 assertEquals(1, Bytes.toInt(results[0].getRow()));
100 assertEquals(3, results[0].rawCells().length);
101 assertEquals(1, Bytes.toInt(results[0].getValue(CF, CQ1)));
102 assertEquals(1, Bytes.toInt(results[0].getValue(CF, CQ2)));
103 assertEquals(1, Bytes.toInt(results[0].getValue(CF, CQ3)));
106 @Test
107 public void testCombine2() throws IOException {
108 Result result1 = Result.create(Arrays.asList(createCell(1, CQ1)), null, false, true);
109 Result result2 = Result.create(Arrays.asList(createCell(1, CQ2)), null, false, true);
110 Result result3 = Result.create(Arrays.asList(createCell(1, CQ3)), null, false, true);
111 Result nextResult1 = Result.create(Arrays.asList(createCell(2, CQ1)), null, false, true);
112 Result nextToNextResult1 = Result.create(Arrays.asList(createCell(3, CQ2)), null, false, false);
114 assertEquals(0, resultCache.addAndGet(new Result[] { result1 }, false).length);
115 assertEquals(0, resultCache.addAndGet(new Result[] { result2 }, false).length);
116 assertEquals(0, resultCache.addAndGet(new Result[] { result3 }, false).length);
118 Result[] results = resultCache.addAndGet(new Result[] { nextResult1 }, false);
119 assertEquals(1, results.length);
120 assertEquals(1, Bytes.toInt(results[0].getRow()));
121 assertEquals(3, results[0].rawCells().length);
122 assertEquals(1, Bytes.toInt(results[0].getValue(CF, CQ1)));
123 assertEquals(1, Bytes.toInt(results[0].getValue(CF, CQ2)));
124 assertEquals(1, Bytes.toInt(results[0].getValue(CF, CQ3)));
126 results = resultCache.addAndGet(new Result[] { nextToNextResult1 }, false);
127 assertEquals(2, results.length);
128 assertEquals(2, Bytes.toInt(results[0].getRow()));
129 assertEquals(1, results[0].rawCells().length);
130 assertEquals(2, Bytes.toInt(results[0].getValue(CF, CQ1)));
131 assertEquals(3, Bytes.toInt(results[1].getRow()));
132 assertEquals(1, results[1].rawCells().length);
133 assertEquals(3, Bytes.toInt(results[1].getValue(CF, CQ2)));
136 @Test
137 public void testCombine3() throws IOException {
138 Result result1 = Result.create(Arrays.asList(createCell(1, CQ1)), null, false, true);
139 Result result2 = Result.create(Arrays.asList(createCell(1, CQ2)), null, false, true);
140 Result nextResult1 = Result.create(Arrays.asList(createCell(2, CQ1)), null, false, false);
141 Result nextToNextResult1 = Result.create(Arrays.asList(createCell(3, CQ1)), null, false, true);
143 assertEquals(0, resultCache.addAndGet(new Result[] { result1 }, false).length);
144 assertEquals(0, resultCache.addAndGet(new Result[] { result2 }, false).length);
146 Result[] results =
147 resultCache.addAndGet(new Result[] { nextResult1, nextToNextResult1 }, false);
148 assertEquals(2, results.length);
149 assertEquals(1, Bytes.toInt(results[0].getRow()));
150 assertEquals(2, results[0].rawCells().length);
151 assertEquals(1, Bytes.toInt(results[0].getValue(CF, CQ1)));
152 assertEquals(1, Bytes.toInt(results[0].getValue(CF, CQ2)));
153 assertEquals(2, Bytes.toInt(results[1].getRow()));
154 assertEquals(1, results[1].rawCells().length);
155 assertEquals(2, Bytes.toInt(results[1].getValue(CF, CQ1)));
157 results = resultCache.addAndGet(new Result[0], false);
158 assertEquals(1, results.length);
159 assertEquals(3, Bytes.toInt(results[0].getRow()));
160 assertEquals(1, results[0].rawCells().length);
161 assertEquals(3, Bytes.toInt(results[0].getValue(CF, CQ1)));
164 @Test
165 public void testCombine4() throws IOException {
166 Result result1 = Result.create(Arrays.asList(createCell(1, CQ1)), null, false, true);
167 Result result2 = Result.create(Arrays.asList(createCell(1, CQ2)), null, false, false);
168 Result nextResult1 = Result.create(Arrays.asList(createCell(2, CQ1)), null, false, true);
169 Result nextResult2 = Result.create(Arrays.asList(createCell(2, CQ2)), null, false, false);
171 assertEquals(0, resultCache.addAndGet(new Result[] { result1 }, false).length);
173 Result[] results = resultCache.addAndGet(new Result[] { result2, nextResult1 }, false);
174 assertEquals(1, results.length);
175 assertEquals(1, Bytes.toInt(results[0].getRow()));
176 assertEquals(2, results[0].rawCells().length);
177 assertEquals(1, Bytes.toInt(results[0].getValue(CF, CQ1)));
178 assertEquals(1, Bytes.toInt(results[0].getValue(CF, CQ2)));
180 results = resultCache.addAndGet(new Result[] { nextResult2 }, false);
181 assertEquals(1, results.length);
182 assertEquals(2, Bytes.toInt(results[0].getRow()));
183 assertEquals(2, results[0].rawCells().length);
184 assertEquals(2, Bytes.toInt(results[0].getValue(CF, CQ1)));
185 assertEquals(2, Bytes.toInt(results[0].getValue(CF, CQ2)));