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
.assertEquals
;
23 import java
.util
.Arrays
;
24 import java
.util
.List
;
25 import java
.util
.concurrent
.ThreadLocalRandom
;
26 import java
.util
.stream
.Collectors
;
27 import java
.util
.stream
.IntStream
;
28 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
29 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
30 import org
.apache
.hadoop
.hbase
.HConstants
;
31 import org
.apache
.hadoop
.hbase
.TableName
;
32 import org
.apache
.hadoop
.hbase
.testclassification
.ClientTests
;
33 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
34 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
35 import org
.apache
.log4j
.Level
;
36 import org
.apache
.log4j
.LogManager
;
37 import org
.junit
.AfterClass
;
38 import org
.junit
.BeforeClass
;
39 import org
.junit
.ClassRule
;
40 import org
.junit
.Test
;
41 import org
.junit
.experimental
.categories
.Category
;
43 @Category({ MediumTests
.class, ClientTests
.class })
44 public class TestAsyncTableBatchRetryImmediately
{
47 public static final HBaseClassTestRule CLASS_RULE
=
48 HBaseClassTestRule
.forClass(TestAsyncTableBatchRetryImmediately
.class);
50 private static final HBaseTestingUtility UTIL
= new HBaseTestingUtility();
52 private static TableName TABLE_NAME
= TableName
.valueOf("async");
54 private static byte[] FAMILY
= Bytes
.toBytes("cf");
56 private static byte[] QUAL
= Bytes
.toBytes("cq");
58 private static byte[] VALUE_PREFIX
= new byte[768];
60 private static int COUNT
= 1000;
62 private static AsyncConnection CONN
;
65 public static void setUp() throws Exception
{
66 // disable the debug log to avoid flooding the output
67 LogManager
.getLogger(AsyncRegionLocatorHelper
.class).setLevel(Level
.INFO
);
68 UTIL
.getConfiguration().setLong(HConstants
.HBASE_SERVER_SCANNER_MAX_RESULT_SIZE_KEY
, 1024);
69 UTIL
.startMiniCluster(1);
70 Table table
= UTIL
.createTable(TABLE_NAME
, FAMILY
);
71 UTIL
.waitTableAvailable(TABLE_NAME
);
72 ThreadLocalRandom
.current().nextBytes(VALUE_PREFIX
);
73 for (int i
= 0; i
< COUNT
; i
++) {
74 table
.put(new Put(Bytes
.toBytes(i
)).addColumn(FAMILY
, QUAL
,
75 Bytes
.add(VALUE_PREFIX
, Bytes
.toBytes(i
))));
77 CONN
= ConnectionFactory
.createAsyncConnection(UTIL
.getConfiguration()).get();
81 public static void tearDown() throws Exception
{
83 UTIL
.shutdownMiniCluster();
88 AsyncTable
<?
> table
= CONN
.getTable(TABLE_NAME
);
89 // if we do not deal with RetryImmediatelyException, we will timeout here since we need to retry
91 List
<Get
> gets
= IntStream
.range(0, COUNT
).mapToObj(i
-> new Get(Bytes
.toBytes(i
)))
92 .collect(Collectors
.toList());
93 List
<Result
> results
= table
.getAll(gets
).join();
94 for (int i
= 0; i
< COUNT
; i
++) {
95 byte[] value
= results
.get(i
).getValue(FAMILY
, QUAL
);
96 assertEquals(VALUE_PREFIX
.length
+ 4, value
.length
);
97 assertArrayEquals(VALUE_PREFIX
, Arrays
.copyOf(value
, VALUE_PREFIX
.length
));
98 assertEquals(i
, Bytes
.toInt(value
, VALUE_PREFIX
.length
));