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.SmallTests;
30 import org.apache.hadoop.hbase.MasterNotRunningException;
31 import org.apache.hadoop.hbase.PleaseHoldException;
32 import org.apache.hadoop.hbase.TableName;
33 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
34 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.CreateTableRequest;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37 import org.mockito.Mockito;
38 import org.mortbay.log.Log;
39 import org.apache.hadoop.hbase.client.HConnectionTestingUtility;
40
41 import com.google.protobuf.RpcController;
42 import com.google.protobuf.ServiceException;
43
44 @Category(SmallTests.class)
45 public class TestHBaseAdminNoCluster {
46
47
48
49
50
51
52
53
54 @Test
55 public void testMasterMonitorCollableRetries()
56 throws MasterNotRunningException, ZooKeeperConnectionException, IOException, ServiceException {
57 Configuration configuration = HBaseConfiguration.create();
58
59 configuration.setLong(HConstants.HBASE_CLIENT_PAUSE, 1);
60 final int count = 10;
61 configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, count);
62
63
64 HConnection connection = HConnectionTestingUtility.getMockedConnection(configuration);
65
66
67 MasterKeepAliveConnection masterAdmin =
68 Mockito.mock(MasterKeepAliveConnection.class);
69 Mockito.when(masterAdmin.createTable((RpcController)Mockito.any(),
70 (CreateTableRequest)Mockito.any())).
71 thenThrow(new ServiceException("Test fail").initCause(new PleaseHoldException("test")));
72 Mockito.when(connection.getKeepAliveMasterService()).thenReturn(masterAdmin);
73
74 HBaseAdmin admin = new HBaseAdmin(configuration);
75 try {
76 HTableDescriptor htd =
77 new HTableDescriptor(TableName.valueOf("testMasterMonitorCollableRetries"));
78
79 try {
80 admin.createTable(htd, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
81 fail();
82 } catch (RetriesExhaustedException e) {
83 Log.info("Expected fail", e);
84 }
85
86 Mockito.verify(masterAdmin, Mockito.atLeast(count)).createTable((RpcController)Mockito.any(),
87 (CreateTableRequest)Mockito.any());
88 } finally {
89 admin.close();
90 if (connection != null)HConnectionManager.deleteConnection(configuration);
91 }
92 }
93 }