1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.client;
19
20 import static org.junit.Assert.fail;
21
22 import java.io.IOException;
23
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseConfiguration;
26 import org.apache.hadoop.hbase.HBaseTestingUtility;
27 import org.apache.hadoop.hbase.HConstants;
28 import org.apache.hadoop.hbase.HTableDescriptor;
29 import org.apache.hadoop.hbase.MasterNotRunningException;
30 import org.apache.hadoop.hbase.PleaseHoldException;
31 import org.apache.hadoop.hbase.TableName;
32 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
33 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.CreateTableRequest;
34 import org.apache.hadoop.hbase.testclassification.SmallTests;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37 import org.mockito.Mockito;
38 import org.mortbay.log.Log;
39
40 import com.google.protobuf.RpcController;
41 import com.google.protobuf.ServiceException;
42
43 @Category(SmallTests.class)
44 public class TestHBaseAdminNoCluster {
45
46
47
48
49
50
51
52
53 @Test
54 public void testMasterMonitorCollableRetries()
55 throws MasterNotRunningException, ZooKeeperConnectionException, IOException, ServiceException {
56 Configuration configuration = HBaseConfiguration.create();
57
58 configuration.setLong(HConstants.HBASE_CLIENT_PAUSE, 1);
59 final int count = 10;
60 configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, count);
61
62
63 HConnection connection = HConnectionTestingUtility.getMockedConnection(configuration);
64
65
66 MasterKeepAliveConnection masterAdmin =
67 Mockito.mock(MasterKeepAliveConnection.class);
68 Mockito.when(masterAdmin.createTable((RpcController)Mockito.any(),
69 (CreateTableRequest)Mockito.any())).
70 thenThrow(new ServiceException("Test fail").initCause(new PleaseHoldException("test")));
71 Mockito.when(connection.getKeepAliveMasterService()).thenReturn(masterAdmin);
72
73 HBaseAdmin admin = new HBaseAdmin(configuration);
74 try {
75 HTableDescriptor htd =
76 new HTableDescriptor(TableName.valueOf("testMasterMonitorCollableRetries"));
77
78 try {
79 admin.createTable(htd, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
80 fail();
81 } catch (RetriesExhaustedException e) {
82 Log.info("Expected fail", e);
83 }
84
85 Mockito.verify(masterAdmin, Mockito.atLeast(count)).createTable((RpcController)Mockito.any(),
86 (CreateTableRequest)Mockito.any());
87 } finally {
88 admin.close();
89 if (connection != null)HConnectionManager.deleteConnection(configuration);
90 }
91 }
92 }