HBASE-23798 Remove hbase-prototcol module (#1360)
[hbase.git] / hbase-thrift / src / test / java / org / apache / hadoop / hbase / thrift2 / TestThrift2ServerCmdLine.java
blob7a1994c003ce5cdbf199da974bc6152b8bb92d00
1 /**
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.thrift2;
20 import java.net.InetAddress;
21 import java.util.ArrayList;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
24 import org.apache.hadoop.hbase.testclassification.ClientTests;
25 import org.apache.hadoop.hbase.testclassification.MediumTests;
26 import org.apache.hadoop.hbase.thrift.ImplType;
27 import org.apache.hadoop.hbase.thrift.TestThriftServerCmdLine;
28 import org.apache.hadoop.hbase.thrift2.generated.TColumnFamilyDescriptor;
29 import org.apache.hadoop.hbase.thrift2.generated.THBaseService;
30 import org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor;
31 import org.apache.hadoop.hbase.thrift2.generated.TTableName;
32 import org.apache.hadoop.hbase.util.Bytes;
33 import org.apache.thrift.protocol.TBinaryProtocol;
34 import org.apache.thrift.protocol.TCompactProtocol;
35 import org.apache.thrift.protocol.TProtocol;
36 import org.apache.thrift.transport.TFramedTransport;
37 import org.apache.thrift.transport.TSocket;
38 import org.apache.thrift.transport.TTransport;
39 import org.junit.Assert;
40 import org.junit.ClassRule;
41 import org.junit.experimental.categories.Category;
43 @Category({ ClientTests.class, MediumTests.class})
44 public class TestThrift2ServerCmdLine extends TestThriftServerCmdLine {
45 @ClassRule
46 public static final HBaseClassTestRule CLASS_RULE =
47 HBaseClassTestRule.forClass(TestThrift2ServerCmdLine.class);
49 private static final String TABLENAME = "TestThrift2ServerCmdLineTable";
52 @Override
53 protected ThriftServer createThriftServer() {
54 return new ThriftServer(TEST_UTIL.getConfiguration());
57 public TestThrift2ServerCmdLine(ImplType implType, boolean specifyFramed,
58 boolean specifyBindIP, boolean specifyCompact) {
59 super(implType, specifyFramed, specifyBindIP, specifyCompact);
62 @Override
63 protected void talkToThriftServer() throws Exception {
64 TSocket sock = new TSocket(InetAddress.getLocalHost().getHostName(),
65 port);
66 TTransport transport = sock;
67 if (specifyFramed || implType.isAlwaysFramed()) {
68 transport = new TFramedTransport(transport);
71 sock.open();
72 try {
73 TProtocol tProtocol;
74 if (specifyCompact) {
75 tProtocol = new TCompactProtocol(transport);
76 } else {
77 tProtocol = new TBinaryProtocol(transport);
79 THBaseService.Client client = new THBaseService.Client(tProtocol);
80 TTableName tTableName = new TTableName();
81 tTableName.setNs(Bytes.toBytes(""));
82 tTableName.setQualifier(Bytes.toBytes(TABLENAME));
83 if (!tableCreated){
84 Assert.assertTrue(!client.tableExists(tTableName));
85 TTableDescriptor tTableDescriptor = new TTableDescriptor();
86 tTableDescriptor.setTableName(tTableName);
87 TColumnFamilyDescriptor columnFamilyDescriptor = new TColumnFamilyDescriptor();
88 columnFamilyDescriptor.setName(Bytes.toBytes(TABLENAME));
89 tTableDescriptor.addToColumns(columnFamilyDescriptor);
90 client.createTable(tTableDescriptor, new ArrayList<>());
91 tableCreated = true;
93 Assert.assertTrue("tableCreated " + tableCreated, client.tableExists(tTableName));
94 } finally {
95 sock.close();