HBASE-23846 Removed deprecated setMaxVersions(int) from Scan
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / mob / TestMobDataBlockEncoding.java
blob2b1595d4a13cd7e4db82aa9ceeab5ab6a31bf90e
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.mob;
20 import java.util.Random;
21 import org.apache.hadoop.hbase.HBaseClassTestRule;
22 import org.apache.hadoop.hbase.HBaseTestingUtility;
23 import org.apache.hadoop.hbase.TableName;
24 import org.apache.hadoop.hbase.client.Admin;
25 import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
26 import org.apache.hadoop.hbase.client.ConnectionFactory;
27 import org.apache.hadoop.hbase.client.Put;
28 import org.apache.hadoop.hbase.client.Scan;
29 import org.apache.hadoop.hbase.client.Table;
30 import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
31 import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
32 import org.apache.hadoop.hbase.testclassification.MediumTests;
33 import org.apache.hadoop.hbase.util.Bytes;
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.ClassRule;
37 import org.junit.Test;
38 import org.junit.experimental.categories.Category;
40 @Category(MediumTests.class)
41 public class TestMobDataBlockEncoding {
43 @ClassRule
44 public static final HBaseClassTestRule CLASS_RULE =
45 HBaseClassTestRule.forClass(TestMobDataBlockEncoding.class);
47 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
48 private final static byte [] row1 = Bytes.toBytes("row1");
49 private final static byte [] family = Bytes.toBytes("family");
50 private final static byte [] qf1 = Bytes.toBytes("qualifier1");
51 private final static byte [] qf2 = Bytes.toBytes("qualifier2");
52 protected final byte[] qf3 = Bytes.toBytes("qualifier3");
53 private static Table table;
54 private static Admin admin;
55 private static ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor
56 columnFamilyDescriptor;
57 private static TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor;
58 private static Random random = new Random();
59 private static long defaultThreshold = 10;
61 @BeforeClass
62 public static void setUpBeforeClass() throws Exception {
63 TEST_UTIL.startMiniCluster(1);
66 @AfterClass
67 public static void tearDownAfterClass() throws Exception {
68 TEST_UTIL.shutdownMiniCluster();
71 public void setUp(long threshold, String TN, DataBlockEncoding encoding)
72 throws Exception {
73 tableDescriptor =
74 new TableDescriptorBuilder.ModifyableTableDescriptor(TableName.valueOf(TN));
75 columnFamilyDescriptor =
76 new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family);
77 columnFamilyDescriptor.setMobEnabled(true);
78 columnFamilyDescriptor.setMobThreshold(threshold);
79 columnFamilyDescriptor.setMaxVersions(4);
80 columnFamilyDescriptor.setDataBlockEncoding(encoding);
81 tableDescriptor.setColumnFamily(columnFamilyDescriptor);
82 admin = TEST_UTIL.getAdmin();
83 admin.createTable(tableDescriptor);
84 table = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())
85 .getTable(TableName.valueOf(TN));
88 /**
89 * Generate the mob value.
91 * @param size the size of the value
92 * @return the mob value generated
94 private static byte[] generateMobValue(int size) {
95 byte[] mobVal = new byte[size];
96 random.nextBytes(mobVal);
97 return mobVal;
100 @Test
101 public void testDataBlockEncoding() throws Exception {
102 for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
103 testDataBlockEncoding(encoding);
107 public void testDataBlockEncoding(DataBlockEncoding encoding) throws Exception {
108 String TN = "testDataBlockEncoding" + encoding;
109 setUp(defaultThreshold, TN, encoding);
110 long ts1 = System.currentTimeMillis();
111 long ts2 = ts1 + 1;
112 long ts3 = ts1 + 2;
113 byte[] value = generateMobValue((int) defaultThreshold + 1);
115 Put put1 = new Put(row1);
116 put1.addColumn(family, qf1, ts3, value);
117 put1.addColumn(family, qf2, ts2, value);
118 put1.addColumn(family, qf3, ts1, value);
119 table.put(put1);
120 admin.flush(TableName.valueOf(TN));
122 Scan scan = new Scan();
123 scan.readVersions(4);
124 MobTestUtil.assertCellsValue(table, scan, value, 3);