1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.regionserver;
21
22 import org.apache.hadoop.fs.Path;
23 import org.apache.hadoop.hbase.*;
24 import org.apache.hadoop.hbase.client.Get;
25 import org.apache.hadoop.hbase.client.Put;
26 import org.apache.hadoop.hbase.testclassification.MediumTests;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.junit.AfterClass;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.junit.experimental.categories.Category;
32
33 import java.io.IOException;
34
35
36
37
38
39 @Category(MediumTests.class)
40 public class TestRowTooBig {
41 private final static HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU();
42 private static Path rootRegionDir;
43 private static final HTableDescriptor TEST_HTD =
44 new HTableDescriptor(TableName.valueOf(TestRowTooBig.class.getSimpleName()));
45
46 @BeforeClass
47 public static void before() throws Exception {
48 HTU.startMiniCluster();
49 HTU.getConfiguration().setLong(HConstants.TABLE_MAX_ROWSIZE_KEY,
50 10 * 1024 * 1024L);
51 rootRegionDir = HTU.getDataTestDirOnTestFS("TestRowTooBig");
52 }
53
54 @AfterClass
55 public static void after() throws Exception {
56 HTU.shutdownMiniCluster();
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70 @Test(expected = RowTooBigException.class)
71 public void testScannersSeekOnFewLargeCells() throws IOException {
72 byte[] row1 = Bytes.toBytes("row1");
73 byte[] fam1 = Bytes.toBytes("fam1");
74
75 HTableDescriptor htd = TEST_HTD;
76 HColumnDescriptor hcd = new HColumnDescriptor(fam1);
77 if (htd.hasFamily(hcd.getName())) {
78 htd.modifyFamily(hcd);
79 } else {
80 htd.addFamily(hcd);
81 }
82
83 final HRegionInfo hri =
84 new HRegionInfo(htd.getTableName(), HConstants.EMPTY_END_ROW,
85 HConstants.EMPTY_END_ROW);
86 Region region = HTU.createHRegion(hri, rootRegionDir, HTU.getConfiguration(), htd);
87 try {
88
89 for (int i = 0; i < 5 ; i++) {
90 Put put = new Put(row1);
91
92 put.add(fam1, Bytes.toBytes("col_" + i ), new byte[5 * 1024 * 1024]);
93 region.put(put);
94 region.flush(true);
95 }
96
97 Get get = new Get(row1);
98 region.get(get);
99 } finally {
100 HBaseTestingUtility.closeRegion(region);
101 }
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115 @Test(expected = RowTooBigException.class)
116 public void testScanAcrossManySmallColumns() throws IOException {
117 byte[] row1 = Bytes.toBytes("row1");
118 byte[] fam1 = Bytes.toBytes("fam1");
119
120 HTableDescriptor htd = TEST_HTD;
121 HColumnDescriptor hcd = new HColumnDescriptor(fam1);
122 if (htd.hasFamily(hcd.getName())) {
123 htd.modifyFamily(hcd);
124 } else {
125 htd.addFamily(hcd);
126 }
127
128 final HRegionInfo hri =
129 new HRegionInfo(htd.getTableName(), HConstants.EMPTY_END_ROW,
130 HConstants.EMPTY_END_ROW);
131 Region region = HTU.createHRegion(hri, rootRegionDir, HTU.getConfiguration(), htd);
132 try {
133
134 for (int i = 0; i < 10; i++) {
135 Put put = new Put(row1);
136 for (int j = 0; j < 10 * 10000; j++) {
137 put.add(fam1, Bytes.toBytes("col_" + i + "_" + j), new byte[10]);
138 }
139 region.put(put);
140 region.flush(true);
141 }
142 region.compact(true);
143
144 Get get = new Get(row1);
145 region.get(get);
146 } finally {
147 HBaseTestingUtility.closeRegion(region);
148 }
149 }
150 }