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
.client
;
20 import static org
.junit
.Assert
.assertTrue
;
22 import java
.io
.IOException
;
23 import org
.apache
.hadoop
.conf
.Configuration
;
24 import org
.apache
.hadoop
.hbase
.Cell
;
25 import org
.apache
.hadoop
.hbase
.CellScanner
;
26 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
27 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
28 import org
.apache
.hadoop
.hbase
.TableName
;
29 import org
.apache
.hadoop
.hbase
.ipc
.AbstractRpcClient
;
30 import org
.apache
.hadoop
.hbase
.testclassification
.ClientTests
;
31 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
32 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
33 import org
.junit
.AfterClass
;
34 import org
.junit
.BeforeClass
;
35 import org
.junit
.ClassRule
;
36 import org
.junit
.Rule
;
37 import org
.junit
.Test
;
38 import org
.junit
.experimental
.categories
.Category
;
39 import org
.junit
.rules
.TestName
;
42 * Do some ops and prove that client and server can work w/o codecs; that we can pb all the time.
43 * Good for third-party clients or simple scripts that want to talk direct to hbase.
45 @Category({MediumTests
.class, ClientTests
.class})
46 public class TestFromClientSideNoCodec
{
49 public static final HBaseClassTestRule CLASS_RULE
=
50 HBaseClassTestRule
.forClass(TestFromClientSideNoCodec
.class);
52 protected final static HBaseTestingUtility TEST_UTIL
= new HBaseTestingUtility();
55 public TestName name
= new TestName();
58 * @throws java.lang.Exception
61 public static void setUpBeforeClass() throws Exception
{
63 TEST_UTIL
.getConfiguration().set("hbase.client.default.rpc.codec", "");
64 TEST_UTIL
.startMiniCluster(1);
68 * @throws java.lang.Exception
71 public static void tearDownAfterClass() throws Exception
{
72 TEST_UTIL
.shutdownMiniCluster();
76 public void testBasics() throws IOException
{
77 final TableName tableName
= TableName
.valueOf(name
.getMethodName());
78 final byte [][] fs
= new byte[][] {Bytes
.toBytes("cf1"), Bytes
.toBytes("cf2"),
79 Bytes
.toBytes("cf3") };
80 Table ht
= TEST_UTIL
.createTable(tableName
, fs
);
82 final byte [] row
= Bytes
.toBytes("row");
88 Result r
= ht
.get(new Get(row
));
90 for (CellScanner cellScanner
= r
.cellScanner(); cellScanner
.advance();) {
91 Cell cell
= cellScanner
.current();
93 assertTrue(Bytes
.toString(f
),
94 Bytes
.equals(cell
.getValueArray(), cell
.getValueOffset(), cell
.getValueLength(),
97 // Check getRowOrBefore
99 Get get
= new Get(row
);
102 assertTrue(r
.toString(), r
.containsColumn(f
, f
));
104 ResultScanner scanner
= ht
.getScanner(new Scan());
106 while ((r
= scanner
.next()) != null) {
107 assertTrue(r
.listCells().size() == 3);
110 assertTrue(count
== 1);
114 public void testNoCodec() {
115 Configuration c
= new Configuration();
116 c
.set("hbase.client.default.rpc.codec", "");
117 String codec
= AbstractRpcClient
.getDefaultCodec(c
);
118 assertTrue(codec
== null || codec
.length() == 0);