1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.client;
19
20 import static org.junit.Assert.assertTrue;
21
22 import java.io.IOException;
23
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.Cell;
26 import org.apache.hadoop.hbase.CellScanner;
27 import org.apache.hadoop.hbase.HBaseTestingUtility;
28 import org.apache.hadoop.hbase.testclassification.MediumTests;
29 import org.apache.hadoop.hbase.ipc.RpcClient;
30 import org.apache.hadoop.hbase.util.Bytes;
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35
36
37
38
39
40 @Category(MediumTests.class)
41 public class TestFromClientSideNoCodec {
42 protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
43
44
45
46 @BeforeClass
47 public static void setUpBeforeClass() throws Exception {
48
49 TEST_UTIL.getConfiguration().set("hbase.client.default.rpc.codec", "");
50 TEST_UTIL.startMiniCluster(1);
51 }
52
53
54
55
56 @AfterClass
57 public static void tearDownAfterClass() throws Exception {
58 TEST_UTIL.shutdownMiniCluster();
59 }
60
61 @Test
62 public void testBasics() throws IOException {
63 final byte [] t = Bytes.toBytes("testBasics");
64 final byte [][] fs = new byte[][] {Bytes.toBytes("cf1"), Bytes.toBytes("cf2"),
65 Bytes.toBytes("cf3") };
66 HTable ht = TEST_UTIL.createTable(t, fs);
67
68 final byte [] row = Bytes.toBytes("row");
69 Put p = new Put(row);
70 for (byte [] f: fs) p.add(f, f, f);
71 ht.put(p);
72 Result r = ht.get(new Get(row));
73 int i = 0;
74 for (CellScanner cellScanner = r.cellScanner(); cellScanner.advance();) {
75 Cell cell = cellScanner.current();
76 byte [] f = fs[i++];
77 assertTrue(Bytes.toString(f),
78 Bytes.equals(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(),
79 f, 0, f.length));
80 }
81
82 byte [] f = fs[0];
83 r = ht.getRowOrBefore(row, f);
84 assertTrue(r.toString(), r.containsColumn(f, f));
85
86 ResultScanner scanner = ht.getScanner(new Scan());
87 int count = 0;
88 while ((r = scanner.next()) != null) {
89 assertTrue(r.listCells().size() == 3);
90 count++;
91 }
92 assertTrue(count == 1);
93 }
94
95 @Test
96 public void testNoCodec() {
97 Configuration c = new Configuration();
98 c.set("hbase.client.default.rpc.codec", "");
99 String codec = RpcClient.getDefaultCodec(c);
100 assertTrue(codec == null || codec.length() == 0);
101 }
102 }