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.*;
24 import org.apache.hadoop.hbase.client.HBaseAdmin;
25 import org.apache.hadoop.hbase.rest.HBaseRESTTestingUtility;
26 import org.apache.hadoop.hbase.rest.client.Client;
27 import org.apache.hadoop.hbase.util.Bytes;
28
29 import static org.junit.Assert.*;
30 import org.junit.AfterClass;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.junit.experimental.categories.Category;
34
35 @Category(MediumTests.class)
36 public class TestRemoteAdmin {
37 private static final String TABLE_1 = "TestRemoteAdmin_Table_1";
38 private static final byte[] COLUMN_1 = Bytes.toBytes("a");
39 static final HTableDescriptor DESC_1 = new HTableDescriptor(TABLE_1);
40 private static final HBaseTestingUtility TEST_UTIL =
41 new HBaseTestingUtility();
42 private static final HBaseRESTTestingUtility REST_TEST_UTIL =
43 new HBaseRESTTestingUtility();
44 private static RemoteAdmin remoteAdmin;
45
46 @BeforeClass
47 public static void setUpBeforeClass() throws Exception {
48 DESC_1.addFamily(new HColumnDescriptor(COLUMN_1));
49
50 TEST_UTIL.startMiniCluster();
51 REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
52
53 remoteAdmin = new RemoteAdmin(new Client(
54 new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())),
55 TEST_UTIL.getConfiguration());
56 }
57
58 @AfterClass
59 public static void tearDownAfterClass() throws Exception {
60 REST_TEST_UTIL.shutdownServletContainer();
61 TEST_UTIL.shutdownMiniCluster();
62 }
63
64 @Test
65 public void testCreateAnDeleteTable() throws Exception {
66 assertFalse(remoteAdmin.isTableAvailable(TABLE_1));
67 remoteAdmin.createTable(DESC_1);
68 assertTrue(remoteAdmin.isTableAvailable(TABLE_1));
69 remoteAdmin.deleteTable(TABLE_1);
70 assertFalse(remoteAdmin.isTableAvailable(TABLE_1));
71 }
72
73 @org.junit.Rule
74 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
75 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
76 }
77