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
.util
.ArrayList
;
22 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
23 import org
.apache
.hadoop
.hbase
.testclassification
.ClientTests
;
24 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
25 import org
.apache
.hadoop
.hbase
.thrift
.TestThriftHttpServer
;
26 import org
.apache
.hadoop
.hbase
.thrift2
.generated
.TColumnFamilyDescriptor
;
27 import org
.apache
.hadoop
.hbase
.thrift2
.generated
.THBaseService
;
28 import org
.apache
.hadoop
.hbase
.thrift2
.generated
.TTableDescriptor
;
29 import org
.apache
.hadoop
.hbase
.thrift2
.generated
.TTableName
;
30 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
31 import org
.apache
.thrift
.protocol
.TBinaryProtocol
;
32 import org
.apache
.thrift
.protocol
.TProtocol
;
33 import org
.apache
.thrift
.transport
.THttpClient
;
34 import org
.junit
.Assert
;
35 import org
.junit
.ClassRule
;
36 import org
.junit
.experimental
.categories
.Category
;
38 @Category({ ClientTests
.class, MediumTests
.class})
39 public class TestThrift2HttpServer
extends TestThriftHttpServer
{
40 private static final String TABLENAME
= "TestThrift2HttpServerTable";
43 public static final HBaseClassTestRule CLASS_RULE
=
44 HBaseClassTestRule
.forClass(TestThrift2HttpServer
.class);
49 protected ThriftServer
createThriftServer() {
50 return new ThriftServer(TEST_UTIL
.getConfiguration());
54 protected void talkToThriftServer(String url
, int customHeaderSize
) throws Exception
{
55 THttpClient httpClient
= new THttpClient(url
);
58 if (customHeaderSize
> 0) {
59 StringBuilder sb
= new StringBuilder();
60 for (int i
= 0; i
< customHeaderSize
; i
++) {
63 httpClient
.setCustomHeader("User-Agent", sb
.toString());
68 prot
= new TBinaryProtocol(httpClient
);
69 THBaseService
.Client client
= new THBaseService
.Client(prot
);
70 TTableName tTableName
= new TTableName();
71 tTableName
.setNs(Bytes
.toBytes(""));
72 tTableName
.setQualifier(Bytes
.toBytes(TABLENAME
));
74 Assert
.assertTrue(!client
.tableExists(tTableName
));
75 TTableDescriptor tTableDescriptor
= new TTableDescriptor();
76 tTableDescriptor
.setTableName(tTableName
);
77 TColumnFamilyDescriptor columnFamilyDescriptor
= new TColumnFamilyDescriptor();
78 columnFamilyDescriptor
.setName(Bytes
.toBytes(TABLENAME
));
79 tTableDescriptor
.addToColumns(columnFamilyDescriptor
);
80 client
.createTable(tTableDescriptor
, new ArrayList
<>());
83 Assert
.assertTrue(client
.tableExists(tTableName
));