Skip to content

Commit 3c81b11

Browse files
authored
Merge pull request #182 from stuBirdFly/secondary_part
add hbase abnormal test case
2 parents 70eff4c + 345eeed commit 3c81b11

9 files changed

+272
-28
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/*-
2+
* #%L
3+
* OBKV HBase Client Framework
4+
* %%
5+
* Copyright (C) 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
18+
package com.alipay.oceanbase.hbase.secondary;
19+
20+
import com.alipay.oceanbase.hbase.OHTableClient;
21+
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
22+
import com.alipay.oceanbase.hbase.util.TableTemplateManager;
23+
import org.apache.hadoop.hbase.client.*;
24+
import org.apache.hadoop.hbase.filter.PageFilter;
25+
import org.apache.hadoop.hbase.util.Bytes;
26+
import org.junit.AfterClass;
27+
import org.junit.Before;
28+
import org.junit.BeforeClass;
29+
import org.junit.Test;
30+
31+
import java.io.IOException;
32+
import java.util.*;
33+
34+
import static com.alipay.oceanbase.hbase.util.ObHTableSecondaryPartUtil.*;
35+
import static com.alipay.oceanbase.hbase.util.ObHTableTestUtil.FOR_EACH;
36+
import static com.alipay.oceanbase.hbase.util.TableTemplateManager.SERIES_TABLES;
37+
import static com.alipay.oceanbase.hbase.util.TableTemplateManager.TableType.*;
38+
import static org.junit.Assert.*;
39+
40+
public class OHTableSecondaryPartAbnormal {
41+
private static List<String> tableNames = new LinkedList<String>();
42+
private static Map<String, List<String>> group2tableNames = new LinkedHashMap<String, List<String>>();
43+
private static byte[] ROW = Bytes.toBytes("testRow");
44+
private static byte[] QUALIFIER = Bytes.toBytes("testQualifier");
45+
private static byte[] VALUE_2 = Bytes.toBytes("abcd");
46+
47+
@BeforeClass
48+
public static void before() throws Exception {
49+
openDistributedExecute();
50+
for (TableTemplateManager.TableType type : SERIES_TABLES) {
51+
createTables(type, tableNames, group2tableNames, true);
52+
}
53+
}
54+
55+
@AfterClass
56+
public static void finish() throws Exception {
57+
closeDistributedExecute();
58+
// dropTables(tableNames, group2tableNames);
59+
}
60+
61+
@Before
62+
public void prepareCase() throws Exception {
63+
truncateTables(tableNames, group2tableNames);
64+
}
65+
66+
private static void testSeriesLimit(String tableName) throws Exception {
67+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
68+
hTable.init();
69+
byte[] FAMILY = getColumnFamilyName(tableName).getBytes();
70+
Put put2 = new Put(ROW);
71+
put2.add(FAMILY, QUALIFIER, VALUE_2);
72+
hTable.put(put2);
73+
Get get = new Get(ROW);
74+
get.addFamily(FAMILY);
75+
get.setFilter(new PageFilter(10));
76+
try {
77+
hTable.get(get);
78+
fail("unexpected, should failed before");
79+
} catch (IOException e) {
80+
assertTrue(e.getCause().getMessage()
81+
.contains("timeseries hbase table with filter query not supported"));
82+
}
83+
get = new Get(ROW);
84+
get.addFamily(FAMILY);
85+
get.setCheckExistenceOnly(true);
86+
try {
87+
hTable.get(get);
88+
fail("unexpected, should failed before");
89+
} catch (IOException e) {
90+
assertTrue(e.getCause().getMessage()
91+
.contains("timeseries hbase table with check existence only query not supported"));
92+
}
93+
get = new Get(ROW);
94+
get.addFamily(FAMILY);
95+
get.setClosestRowBefore(true);
96+
try {
97+
hTable.get(get);
98+
fail("unexpected, should failed before");
99+
} catch (IOException e) {
100+
assertTrue(e.getCause().getMessage()
101+
.contains("timeseries hbase table with reverse query not supported"));
102+
}
103+
Scan scan = new Scan(ROW);
104+
scan.addFamily(FAMILY);
105+
scan.setReversed(true);
106+
try {
107+
hTable.getScanner(scan);
108+
fail("unexpected, should failed before");
109+
} catch (IOException e) {
110+
assertTrue(e.getCause().getMessage()
111+
.contains("timeseries hbase table with reverse query not supported"));
112+
}
113+
scan = new Scan(ROW);
114+
scan.addFamily(FAMILY);
115+
scan.setCaching(1);
116+
try {
117+
hTable.getScanner(scan);
118+
fail("unexpected, should failed before");
119+
} catch (IOException e) {
120+
assertTrue(e.getCause().getMessage()
121+
.contains("timeseries hbase table with caching query not supported"));
122+
}
123+
scan = new Scan(ROW);
124+
scan.addFamily(FAMILY);
125+
scan.setBatch(1);
126+
try {
127+
hTable.getScanner(scan);
128+
fail("unexpected, should failed before");
129+
} catch (IOException e) {
130+
assertTrue(e.getCause().getMessage()
131+
.contains("timeseries hbase table with batch query not supported"));
132+
}
133+
scan = new Scan(ROW);
134+
scan.addFamily(FAMILY);
135+
scan.setAllowPartialResults(true);
136+
try {
137+
hTable.getScanner(scan);
138+
fail("unexpected, should failed before");
139+
} catch (IOException e) {
140+
assertTrue(e.getCause().getMessage()
141+
.contains("timeseries hbase table with allow partial results query not supported"));
142+
}
143+
scan = new Scan(ROW);
144+
scan.addFamily(FAMILY);
145+
scan.setMaxResultsPerColumnFamily(1);
146+
try {
147+
hTable.getScanner(scan);
148+
fail("unexpected, should failed before");
149+
} catch (IOException e) {
150+
assertTrue(e
151+
.getCause()
152+
.getMessage()
153+
.contains(
154+
"timeseries hbase table with max results per column family query not supported"));
155+
}
156+
scan = new Scan(ROW);
157+
scan.addFamily(FAMILY);
158+
scan.setRowOffsetPerColumnFamily(1);
159+
try {
160+
hTable.getScanner(scan);
161+
fail("unexpected, should failed before");
162+
} catch (IOException e) {
163+
assertTrue(e.getCause().getMessage()
164+
.contains("timeseries hbase table with row offset query not supported"));
165+
}
166+
scan = new Scan(ROW);
167+
scan.addFamily(FAMILY);
168+
ResultScanner scanner = hTable.getScanner(scan);
169+
assertEquals(1, scanner.next().size());
170+
hTable.close();
171+
}
172+
173+
private static void testSeriesWithCellTTL(String tableName) throws Exception {
174+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
175+
hTable.init();
176+
byte[] FAMILY = getColumnFamilyName(tableName).getBytes();
177+
Put put2 = new Put(ROW);
178+
put2.add(FAMILY, QUALIFIER, VALUE_2);
179+
try {
180+
hTable.put(put2);
181+
fail("unexpected, should failed before");
182+
} catch (IOException e) {
183+
assertTrue(e.getCause().getMessage()
184+
.contains("series table not support cell ttl not supported"));
185+
}
186+
hTable.close();
187+
}
188+
189+
private static void testSecondaryPartReverseScan(String tableName) throws Exception {
190+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
191+
hTable.init();
192+
byte[] FAMILY = getColumnFamilyName(tableName).getBytes();
193+
Put put2 = new Put(ROW);
194+
put2.add(FAMILY, QUALIFIER, VALUE_2);
195+
hTable.put(put2);
196+
Scan scan = new Scan(ROW);
197+
scan.addFamily(FAMILY);
198+
scan.setReversed(true);
199+
try {
200+
hTable.getScanners(scan);
201+
fail("unexpected, should failed before");
202+
} catch (IOException e) {
203+
assertTrue(e.getCause().getMessage()
204+
.contains("secondary partitioned hbase table with reverse query not supported"));
205+
}
206+
hTable.close();
207+
}
208+
209+
@Test
210+
public void testSeriesLimit() throws Throwable {
211+
FOR_EACH(tableNames, com.alipay.oceanbase.hbase.secondary.OHTableSecondaryPartAbnormal::testSeriesLimit);
212+
}
213+
214+
@Test
215+
public void testSeriesWithCellTTL() throws Throwable {
216+
List<String> tmpTable = new ArrayList<>();
217+
createTables(NON_PARTITIONED_TIME_CELL_TTL, tmpTable, null, true);
218+
FOR_EACH(tmpTable, OHTableSecondaryPartAbnormal::testSeriesWithCellTTL);
219+
dropTables(tmpTable, null);
220+
}
221+
222+
@Test
223+
public void testSecondaryPartReverseScan() throws Throwable {
224+
List<String> tmpTable = new ArrayList<>();
225+
createTables(SECONDARY_PARTITIONED_KEY_RANGE_GEN, tmpTable, null, true);
226+
FOR_EACH(tmpTable, OHTableSecondaryPartAbnormal::testSecondaryPartReverseScan);
227+
dropTables(tmpTable, null);
228+
}
229+
}

src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableSecondaryPartAppendTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141

4242
public class OHTableSecondaryPartAppendTest {
4343
private static List<String> tableNames = new LinkedList<String>();
44-
private static List<String> series_tables = new LinkedList<String>();
4544
private static Map<String, List<String>> group2tableNames = new LinkedHashMap<String, List<String>>();
4645

4746
@BeforeClass
@@ -74,8 +73,8 @@ private static void testAppend(String tableName) throws Exception {
7473
byte[] ROW = "appendKey".getBytes();
7574
byte[] v1 = Bytes.toBytes("42");
7675
byte[] v2 = Bytes.toBytes("23");
77-
byte[][] QUALIFIERS = new byte[][]{Bytes.toBytes("b"), Bytes.toBytes("a"),
78-
Bytes.toBytes("c")};
76+
byte[][] QUALIFIERS = new byte[][] { Bytes.toBytes("b"), Bytes.toBytes("a"),
77+
Bytes.toBytes("c") };
7978
Append a = new Append(ROW);
8079
a.add(FAMILY, QUALIFIERS[0], v1);
8180
a.add(FAMILY, QUALIFIERS[1], v2);
@@ -91,8 +90,8 @@ private static void testAppend(String tableName) throws Exception {
9190
assertEquals(0, Bytes.compareTo(Bytes.add(v2, v1), r.getValue(FAMILY, QUALIFIERS[1])));
9291
// QUALIFIERS[2] previously not exist, verify both value and timestamp are correct
9392
assertEquals(0, Bytes.compareTo(v2, r.getValue(FAMILY, QUALIFIERS[2])));
94-
assertEquals(r.getColumnLatest(FAMILY, QUALIFIERS[0]).getTimestamp(),
95-
r.getColumnLatest(FAMILY, QUALIFIERS[2]).getTimestamp());
93+
assertEquals(r.getColumnLatest(FAMILY, QUALIFIERS[0]).getTimestamp(), r
94+
.getColumnLatest(FAMILY, QUALIFIERS[2]).getTimestamp());
9695

9796
Get get = new Get(ROW);
9897
get.setMaxVersions(10);
@@ -102,11 +101,11 @@ private static void testAppend(String tableName) throws Exception {
102101
assertEquals(2, result.getColumnCells(FAMILY, QUALIFIERS[1]).size());
103102
assertEquals(1, result.getColumnCells(FAMILY, QUALIFIERS[2]).size());
104103
assertEquals(
105-
0,
106-
Bytes.compareTo(Bytes.add(v1, v2), result.getColumnCells(FAMILY, QUALIFIERS[0]).get(0)
107-
.getValue()));
104+
0,
105+
Bytes.compareTo(Bytes.add(v1, v2), result.getColumnCells(FAMILY, QUALIFIERS[0])
106+
.get(0).getValue()));
108107
assertEquals(0,
109-
Bytes.compareTo(v2, result.getColumnCells(FAMILY, QUALIFIERS[2]).get(0).getValue()));
108+
Bytes.compareTo(v2, result.getColumnCells(FAMILY, QUALIFIERS[2]).get(0).getValue()));
110109
} finally {
111110
hTable.close();
112111
}
@@ -119,8 +118,8 @@ private static void testAppendBorder(String tableName) throws Exception {
119118
byte[] FAMILY = getColumnFamilyName(tableName).getBytes();
120119
byte[] ROW = "appendKey".getBytes();
121120
byte[] v1 = Bytes.toBytes("ab");
122-
byte[][] QUALIFIERS = new byte[][]{Bytes.toBytes("b"), Bytes.toBytes("a"),
123-
Bytes.toBytes("c")};
121+
byte[][] QUALIFIERS = new byte[][] { Bytes.toBytes("b"), Bytes.toBytes("a"),
122+
Bytes.toBytes("c") };
124123
Put put = new Put(ROW);
125124
put.addColumn(FAMILY, QUALIFIERS[1], v1);
126125
hTable.put(put);
@@ -267,6 +266,7 @@ public void testAppendMultiCF() throws Throwable {
267266

268267
@Test
269268
public void testAppendSeires() throws Throwable {
269+
List<String> series_tables = new LinkedList<String>();
270270
createTables(TableTemplateManager.TableType.SECONDARY_PARTITIONED_TIME_RANGE_KEY, series_tables, null, true);
271271
FOR_EACH(series_tables, OHTableSecondaryPartAppendTest::testAppendSeires);
272272
}

src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableSecondaryPartBatchGetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static void testBatchGetImpl(String tableName) throws Exception {
9595
}
9696
hTable.close();
9797
}
98-
98+
9999
@Test
100100
public void testBatchGet() throws Throwable {
101101
FOR_EACH(tableNames, OHTableSecondaryPartBatchGetTest::testBatchGetImpl);

src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableSecondaryPartCellTTLTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,9 @@ public void testCellTTLWithRowkeyTTL() throws Throwable {
477477

478478
@Test
479479
public void testCellTTLWithNonTTLTable() throws Throwable {
480-
List<String> NonTTLTable = new LinkedList<String>();
481-
Map<String, List<String>> NonTTLTableMultiCF = new LinkedHashMap<>();
482-
createTables(TableTemplateManager.TableType.NON_PARTITIONED_REGULAR, NonTTLTable, NonTTLTableMultiCF, true);
480+
List<String> NonTTLTable = new LinkedList<String>();
481+
createTables(TableTemplateManager.TableType.NON_PARTITIONED_REGULAR, NonTTLTable, null, true);
483482
FOR_EACH(NonTTLTable, OHTableSecondaryPartCellTTLTest::testCellTTLWithNonTTLTable);
484-
dropTables(NonTTLTable, NonTTLTableMultiCF);
483+
dropTables(NonTTLTable, null);
485484
}
486485
}

src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableSecondaryPartCheckAndMutateTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import static com.alipay.oceanbase.hbase.util.ObHTableSecondaryPartUtil.*;
3535
import static com.alipay.oceanbase.hbase.util.ObHTableTestUtil.FOR_EACH;
36-
import static com.alipay.oceanbase.hbase.util.TableTemplateManager.COLUMN_FAMILY;
3736
import static com.alipay.oceanbase.hbase.util.TableTemplateManager.NORMAL_TABLES;
3837
import static org.junit.Assert.*;
3938

@@ -436,9 +435,9 @@ public void testCheckAndMutateMultiCF() throws Throwable {
436435

437436
@Test
438437
public void testCheckAndMutateSeires() throws Throwable {
439-
List<String> seriesTables = new LinkedList<String>();
440-
Map<String, List<String>> seriesTablesMultiCF = new LinkedHashMap<String, List<String>>();
441-
createTables(TableTemplateManager.TableType.SECONDARY_PARTITIONED_TIME_RANGE_KEY, seriesTables, seriesTablesMultiCF, true);
442-
FOR_EACH(seriesTables, OHTableSecondaryPartCheckAndMutateTest::testCheckAndMutateSeires);
438+
List<String> series_tables = new LinkedList<String>();
439+
createTables(TableTemplateManager.TableType.SECONDARY_PARTITIONED_TIME_RANGE_KEY, series_tables, null, true);
440+
FOR_EACH(series_tables, OHTableSecondaryPartCheckAndMutateTest::testCheckAndMutateSeires);
441+
dropTables(series_tables, null);
443442
}
444443
}

src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableSecondaryPartIncrementTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ private static void testIncBorder(String tableName) throws Exception {
105105
byte[] FAMILY = getColumnFamilyName(tableName).getBytes();
106106
byte[] ROW = "incKey".getBytes();
107107
byte[] v1 = Bytes.toBytes("ab");
108-
byte[][] QUALIFIERS = new byte[][]{Bytes.toBytes("b"), Bytes.toBytes("a"),
109-
Bytes.toBytes("c")};
108+
byte[][] QUALIFIERS = new byte[][] { Bytes.toBytes("b"), Bytes.toBytes("a"),
109+
Bytes.toBytes("c") };
110110
Put put = new Put(ROW);
111111
put.addColumn(FAMILY, QUALIFIERS[1], v1);
112112
hTable.put(put);
@@ -140,11 +140,11 @@ private static void testIncBorder(String tableName) throws Exception {
140140
result = hTable.get(get);
141141
assertEquals(3, result.size());
142142
assertEquals(4L,
143-
Bytes.toLong(result.getColumnCells(FAMILY, QUALIFIERS[1]).get(0).getValue()));
143+
Bytes.toLong(result.getColumnCells(FAMILY, QUALIFIERS[1]).get(0).getValue()));
144144
assertEquals(2L,
145-
Bytes.toLong(result.getColumnCells(FAMILY, QUALIFIERS[1]).get(1).getValue()));
145+
Bytes.toLong(result.getColumnCells(FAMILY, QUALIFIERS[1]).get(1).getValue()));
146146
assertEquals(2L,
147-
Bytes.toLong(result.getColumnCells(FAMILY, QUALIFIERS[0]).get(0).getValue()));
147+
Bytes.toLong(result.getColumnCells(FAMILY, QUALIFIERS[0]).get(0).getValue()));
148148
} finally {
149149
hTable.close();
150150
}

src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableSecondaryPartTTLTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public void testRowkeyTTL() throws Exception {
373373
testRowkeyTTL(tableNames, true, false);
374374
testRowkeyTTL(tableNames, false, false);
375375
// TODO: open the test after reverse scan is ok
376-
// testRowkeyTTL(tableNames, true, true);
376+
// testRowkeyTTL(tableNames, true, true);
377377
}
378378

379379
@Test

src/test/java/com/alipay/oceanbase/hbase/util/ObHTableSecondaryPartUtil.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ public static List<Cell> getCellsFromScanner(ResultScanner scanner) {
340340
return cells;
341341
}
342342

343-
344343
public static void checkUtilTimeout(List<String> tableNames, Supplier<Boolean> function, long timeout, long interval) throws Exception {
345344
long startTime = System.currentTimeMillis();
346345
while (System.currentTimeMillis() - startTime < timeout) {

0 commit comments

Comments
 (0)