HBASE-22002 Remove the deprecated methods in Admin interface
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestFromClientSideNoCodec.java
blob74bb57de1263a6d12459ab9966c9763dd20088e3
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.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;
41 /**
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 {
48 @ClassRule
49 public static final HBaseClassTestRule CLASS_RULE =
50 HBaseClassTestRule.forClass(TestFromClientSideNoCodec.class);
52 protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
54 @Rule
55 public TestName name = new TestName();
57 /**
58 * @throws java.lang.Exception
60 @BeforeClass
61 public static void setUpBeforeClass() throws Exception {
62 // Turn off codec use
63 TEST_UTIL.getConfiguration().set("hbase.client.default.rpc.codec", "");
64 TEST_UTIL.startMiniCluster(1);
67 /**
68 * @throws java.lang.Exception
70 @AfterClass
71 public static void tearDownAfterClass() throws Exception {
72 TEST_UTIL.shutdownMiniCluster();
75 @Test
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);
81 // Check put and get.
82 final byte [] row = Bytes.toBytes("row");
83 Put p = new Put(row);
84 for (byte [] f: fs) {
85 p.addColumn(f, f, f);
87 ht.put(p);
88 Result r = ht.get(new Get(row));
89 int i = 0;
90 for (CellScanner cellScanner = r.cellScanner(); cellScanner.advance();) {
91 Cell cell = cellScanner.current();
92 byte [] f = fs[i++];
93 assertTrue(Bytes.toString(f),
94 Bytes.equals(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(),
95 f, 0, f.length));
97 // Check getRowOrBefore
98 byte[] f = fs[0];
99 Get get = new Get(row);
100 get.addFamily(f);
101 r = ht.get(get);
102 assertTrue(r.toString(), r.containsColumn(f, f));
103 // Check scan.
104 ResultScanner scanner = ht.getScanner(new Scan());
105 int count = 0;
106 while ((r = scanner.next()) != null) {
107 assertTrue(r.listCells().size() == 3);
108 count++;
110 assertTrue(count == 1);
113 @Test
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);