1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.rest.client;
22
23 import org.apache.hadoop.hbase.HColumnDescriptor;
24 import org.apache.hadoop.hbase.HTableDescriptor;
25 import org.apache.hadoop.hbase.client.HBaseAdmin;
26 import org.apache.hadoop.hbase.rest.HBaseRESTClusterTestBase;
27 import org.apache.hadoop.hbase.rest.client.Client;
28 import org.apache.hadoop.hbase.util.Bytes;
29
30 public class TestRemoteAdmin extends HBaseRESTClusterTestBase {
31
32 static final String TABLE_1 = "TestRemoteAdmin_Table_1";
33 static final String TABLE_2 = "TestRemoteAdmin_Table_2";
34 static final byte[] COLUMN_1 = Bytes.toBytes("a");
35
36 static final HTableDescriptor DESC_1;
37 static {
38 DESC_1 = new HTableDescriptor(TABLE_1);
39 DESC_1.addFamily(new HColumnDescriptor(COLUMN_1));
40 }
41 static final HTableDescriptor DESC_2;
42 static {
43 DESC_2 = new HTableDescriptor(TABLE_2);
44 DESC_2.addFamily(new HColumnDescriptor(COLUMN_1));
45 }
46
47 Client client;
48 HBaseAdmin localAdmin;
49 RemoteAdmin remoteAdmin;
50
51 @Override
52 protected void setUp() throws Exception {
53 super.setUp();
54 localAdmin = new HBaseAdmin(conf);
55 remoteAdmin = new RemoteAdmin(new Client(
56 new Cluster().add("localhost", testServletPort)),
57 conf);
58 if (localAdmin.tableExists(TABLE_1)) {
59 localAdmin.disableTable(TABLE_1);
60 localAdmin.deleteTable(TABLE_1);
61 }
62 if (!localAdmin.tableExists(TABLE_2)) {
63 localAdmin.createTable(DESC_2);
64 }
65 }
66
67 @Override
68 protected void tearDown() throws Exception {
69 super.tearDown();
70 }
71
72 public void testCreateTable() throws Exception {
73 assertFalse(remoteAdmin.isTableAvailable(TABLE_1));
74 remoteAdmin.createTable(DESC_1);
75 assertTrue(remoteAdmin.isTableAvailable(TABLE_1));
76 }
77
78 public void testDeleteTable() throws Exception {
79 assertTrue(remoteAdmin.isTableAvailable(TABLE_2));
80 remoteAdmin.deleteTable(TABLE_2);
81 assertFalse(remoteAdmin.isTableAvailable(TABLE_2));
82 }
83 }