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
.AsyncProcess
.START_LOG_ERRORS_AFTER_COUNT_KEY
;
21 import static org
.junit
.Assert
.assertArrayEquals
;
22 import static org
.junit
.Assert
.assertFalse
;
23 import static org
.junit
.Assert
.assertTrue
;
25 import java
.util
.HashMap
;
27 import java
.util
.Random
;
28 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
29 import org
.apache
.hadoop
.hbase
.HConstants
;
30 import org
.apache
.hadoop
.hbase
.master
.snapshot
.SnapshotManager
;
31 import org
.apache
.hadoop
.hbase
.procedure
.ProcedureManagerHost
;
32 import org
.apache
.hadoop
.hbase
.procedure
.SimpleMasterProcedureManager
;
33 import org
.apache
.hadoop
.hbase
.procedure
.SimpleRSProcedureManager
;
34 import org
.apache
.hadoop
.hbase
.testclassification
.ClientTests
;
35 import org
.apache
.hadoop
.hbase
.testclassification
.LargeTests
;
36 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
37 import org
.junit
.Assert
;
38 import org
.junit
.BeforeClass
;
39 import org
.junit
.ClassRule
;
40 import org
.junit
.Test
;
41 import org
.junit
.experimental
.categories
.Category
;
42 import org
.junit
.runner
.RunWith
;
43 import org
.junit
.runners
.Parameterized
;
46 * Class to test asynchronous procedure admin operations.
48 @RunWith(Parameterized
.class)
49 @Category({ LargeTests
.class, ClientTests
.class })
50 public class TestAsyncProcedureAdminApi
extends TestAsyncAdminBase
{
53 public static final HBaseClassTestRule CLASS_RULE
=
54 HBaseClassTestRule
.forClass(TestAsyncProcedureAdminApi
.class);
57 public static void setUpBeforeClass() throws Exception
{
58 TEST_UTIL
.getConfiguration().setInt(HConstants
.HBASE_RPC_TIMEOUT_KEY
, 60000);
59 TEST_UTIL
.getConfiguration().setInt(HConstants
.HBASE_CLIENT_OPERATION_TIMEOUT
, 120000);
60 TEST_UTIL
.getConfiguration().setInt(HConstants
.HBASE_CLIENT_RETRIES_NUMBER
, 2);
61 TEST_UTIL
.getConfiguration().setInt(START_LOG_ERRORS_AFTER_COUNT_KEY
, 0);
62 TEST_UTIL
.getConfiguration().set(ProcedureManagerHost
.MASTER_PROCEDURE_CONF_KEY
,
63 SimpleMasterProcedureManager
.class.getName());
64 TEST_UTIL
.getConfiguration().set(ProcedureManagerHost
.REGIONSERVER_PROCEDURE_CONF_KEY
,
65 SimpleRSProcedureManager
.class.getName());
66 TEST_UTIL
.getConfiguration().setBoolean(SnapshotManager
.HBASE_SNAPSHOT_ENABLED
, true);
67 TEST_UTIL
.startMiniCluster(2);
68 ASYNC_CONN
= ConnectionFactory
.createAsyncConnection(TEST_UTIL
.getConfiguration()).get();
72 public void testExecProcedure() throws Exception
{
73 String snapshotString
= "offlineTableSnapshot";
75 Table table
= TEST_UTIL
.createTable(tableName
, Bytes
.toBytes("cf"));
76 for (int i
= 0; i
< 100; i
++) {
77 Put put
= new Put(Bytes
.toBytes(i
)).addColumn(Bytes
.toBytes("cf"), null, Bytes
.toBytes(i
));
80 // take a snapshot of the enabled table
81 Map
<String
, String
> props
= new HashMap
<>();
82 props
.put("table", tableName
.getNameAsString());
83 admin
.execProcedure(SnapshotManager
.ONLINE_SNAPSHOT_CONTROLLER_DESCRIPTION
, snapshotString
,
85 LOG
.debug("Snapshot completed.");
87 admin
.deleteSnapshot(snapshotString
).join();
88 TEST_UTIL
.deleteTable(tableName
);
93 public void testExecProcedureWithRet() throws Exception
{
94 byte[] result
= admin
.execProcedureWithReturn(SimpleMasterProcedureManager
.SIMPLE_SIGNATURE
,
95 "myTest2", new HashMap
<>()).get();
96 assertArrayEquals("Incorrect return data from execProcedure",
97 Bytes
.toBytes(SimpleMasterProcedureManager
.SIMPLE_DATA
), result
);
101 public void listProcedure() throws Exception
{
102 String procList
= admin
.getProcedures().get();
103 assertTrue(procList
.startsWith("["));
107 public void isProcedureFinished() throws Exception
{
108 boolean failed
= false;
110 admin
.isProcedureFinished("fake-signature", "fake-instance", new HashMap
<>()).get();
111 } catch (Exception e
) {
114 Assert
.assertTrue(failed
);
118 public void abortProcedure() throws Exception
{
119 Random randomGenerator
= new Random();
120 long procId
= randomGenerator
.nextLong();
121 boolean abortResult
= admin
.abortProcedure(procId
, true).get();
122 assertFalse(abortResult
);