Skip to content

Commit 4fc32d4

Browse files
authored
Merge pull request #181 from shenyunlong/sec_part_2
[Test] add testcases for hbase timeseries model get/scan
2 parents 758aa18 + f5d91c6 commit 4fc32d4

13 files changed

+403
-16
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public static void before() throws Exception {
5555
@AfterClass
5656
public static void finish() throws Exception {
5757
closeDistributedExecute();
58-
// dropTables(tableNames, group2tableNames);
5958
}
6059

6160
@Before
@@ -270,6 +269,5 @@ public void testAppendMultiCF() throws Throwable {
270269
public void testAppendSeires() throws Throwable {
271270
createTables(TableTemplateManager.TableType.SECONDARY_PARTITIONED_TIME_RANGE_KEY, series_tables, null, true);
272271
FOR_EACH(series_tables, OHTableSecondaryPartAppendTest::testAppendSeires);
273-
dropTables(series_tables, null);
274272
}
275273
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public static void before() throws Exception {
5050
@AfterClass
5151
public static void finish() throws Exception {
5252
closeDistributedExecute();
53-
dropTables(tableNames, group2tableNames);
5453
}
5554

5655
@Before

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public static void before() throws Exception {
5252
@AfterClass
5353
public static void finish() throws Exception {
5454
closeDistributedExecute();
55-
dropTables(tableNames, group2tableNames);
5655
}
5756

5857
@Before

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public static void before() throws Exception {
5757
@AfterClass
5858
public static void finish() throws Exception {
5959
closeDistributedExecute();
60-
dropTables(tableNames, group2tableNames);
6160
}
6261

6362
@Before
@@ -441,6 +440,5 @@ public void testCheckAndMutateSeires() throws Throwable {
441440
Map<String, List<String>> seriesTablesMultiCF = new LinkedHashMap<String, List<String>>();
442441
createTables(TableTemplateManager.TableType.SECONDARY_PARTITIONED_TIME_RANGE_KEY, seriesTables, seriesTablesMultiCF, true);
443442
FOR_EACH(seriesTables, OHTableSecondaryPartCheckAndMutateTest::testCheckAndMutateSeires);
444-
dropTables(seriesTables, seriesTablesMultiCF);
445443
}
446444
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public static void before() throws Exception {
4848
@AfterClass
4949
public static void finish() throws Exception {
5050
closeDistributedExecute();
51-
dropTables(tableNames, group2tableNames);
5251
}
5352

5453
@Before

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public static void before() throws Exception {
5757
@AfterClass
5858
public static void finish() throws Exception {
5959
closeDistributedExecute();
60-
dropTables(tableNames, group2tableNames);
6160
}
6261

6362
@Before

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public static void before() throws Exception {
5454
@AfterClass
5555
public static void finish() throws Exception {
5656
closeDistributedExecute();
57-
dropTables(tableNames, group2tableNames);
5857
}
5958

6059
@Before
@@ -262,6 +261,5 @@ public void testIncrementSeires() throws Throwable {
262261
List<String> series_tables = new LinkedList<String>();
263262
createTables(TableTemplateManager.TableType.SECONDARY_PARTITIONED_TIME_RANGE_KEY, series_tables, null, true);
264263
FOR_EACH(series_tables, OHTableSecondaryPartIncrementTest::testIncrementSeires);
265-
dropTables(series_tables, null);
266264
}
267265
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public static void before() throws Exception {
4848
@AfterClass
4949
public static void finish() throws Exception {
5050
closeDistributedExecute();
51-
dropTables(tableNames, group2tableNames);
5251
}
5352

5453
@Before

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public static void before() throws Exception {
4949
@AfterClass
5050
public static void finish() throws Exception {
5151
closeDistributedExecute();
52-
dropTables(tableNames, group2tableNames);
5352
}
5453

5554
@Before
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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.ObHTableSecondaryPartUtil;
22+
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
23+
import com.alipay.oceanbase.hbase.util.TableTemplateManager;
24+
import org.apache.hadoop.hbase.Cell;
25+
import org.apache.hadoop.hbase.client.Get;
26+
import org.apache.hadoop.hbase.client.Put;
27+
import org.apache.hadoop.hbase.client.Result;
28+
import org.junit.*;
29+
30+
import java.util.LinkedHashMap;
31+
import java.util.LinkedList;
32+
import java.util.List;
33+
import java.util.Map;
34+
35+
import static com.alipay.oceanbase.hbase.util.ObHTableSecondaryPartUtil.*;
36+
import static com.alipay.oceanbase.hbase.util.ObHTableTestUtil.FOR_EACH;
37+
import static com.alipay.oceanbase.hbase.util.TableTemplateManager.TIMESERIES_TABLES;
38+
import static org.apache.hadoop.hbase.util.Bytes.toBytes;
39+
import static org.junit.Assert.assertEquals;
40+
41+
42+
public class OHTableTimeSeriesGetTest {
43+
private static List<String> tableNames = new LinkedList<String>();
44+
private static Map<String, List<String>> group2tableNames = new LinkedHashMap<>();
45+
46+
47+
@BeforeClass
48+
public static void before() throws Exception {
49+
openDistributedExecute();
50+
for (TableTemplateManager.TableType type : TIMESERIES_TABLES) {
51+
createTables(type, tableNames, group2tableNames, true);
52+
}
53+
}
54+
55+
@AfterClass
56+
public static void finish() throws Exception {
57+
closeDistributedExecute();
58+
}
59+
60+
@Before
61+
public void prepareCase() throws Exception {
62+
truncateTables(tableNames, group2tableNames);
63+
}
64+
65+
66+
public static void testGetImpl(String tableName) throws Exception {
67+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
68+
hTable.init();
69+
70+
// 0. prepare data
71+
String family = getColumnFamilyName(tableName);
72+
String key = "putKey";
73+
String[] columns = {"putColumn1", "putColumn2", "putColumn3"};
74+
String[] columns1 = {"putColumn1", "putColumn2"};
75+
String[] columns2 = {"putColumn3"};
76+
String[] values = {"version1", "version2"}; // each column have two versions
77+
long curTs = System.currentTimeMillis();
78+
long[] ts = {curTs, curTs+1}; // each column have two versions
79+
for (int i = 0; i < values.length; i++) {
80+
for (int j = 0; j < columns1.length; j++) {
81+
Put put = new Put(toBytes(key));
82+
put.add(family.getBytes(), columns1[j].getBytes(), ts[i], toBytes(values[i]));
83+
hTable.put(put);
84+
}
85+
}
86+
87+
Put put = new Put(toBytes(key));
88+
for (int i = 0; i < values.length; i++) {
89+
for (int j = 0; j < columns2.length; j++) {
90+
put.add(family.getBytes(), columns2[j].getBytes(), ts[i], toBytes(values[i]));
91+
}
92+
}
93+
hTable.put(put);
94+
95+
96+
// 1. get specify column
97+
{
98+
int index = 0;
99+
Get get = new Get(key.getBytes());
100+
get.addColumn(family.getBytes(), columns[index].getBytes());
101+
Result r = hTable.get(get);
102+
Cell cells[] = r.rawCells();
103+
assertEquals(2, cells.length);
104+
sortCells(cells);
105+
for (int i = values.length - 1; i >= 0; i--) {
106+
AssertKeyValue(key, columns[index], ts[i], values[i], cells[values.length - 1-i]);
107+
}
108+
}
109+
110+
// 2. get do not specify column
111+
{
112+
Get get = new Get(key.getBytes());
113+
get.addFamily(family.getBytes());
114+
Result result = hTable.get(get);
115+
Cell[] cells = result.rawCells();
116+
assertEquals(columns.length * values.length, cells.length);
117+
sortCells(cells);
118+
int idx = 0;
119+
for (int i = 0; i < columns.length; i++) {
120+
for (int j = values.length - 1; j >= 0; j--) {
121+
ObHTableSecondaryPartUtil.AssertKeyValue(key, columns[i], ts[j], values[j], cells[idx]);
122+
idx++;
123+
}
124+
}
125+
}
126+
127+
// 3. get specify time range
128+
{
129+
Get get = new Get(key.getBytes());
130+
get.addFamily(family.getBytes());
131+
get.setTimeStamp(ts[1]);
132+
Result r = hTable.get(get);
133+
Cell cells[] = r.rawCells();
134+
assertEquals(columns.length, cells.length);
135+
sortCells(cells);
136+
for (int i = 0; i < columns.length; i++) {
137+
AssertKeyValue(key, columns[i], values[1],cells[i]);
138+
}
139+
}
140+
141+
hTable.close();
142+
}
143+
144+
@Test
145+
public void testGet() throws Throwable {
146+
FOR_EACH(tableNames, OHTableTimeSeriesGetTest::testGetImpl);
147+
}
148+
}

0 commit comments

Comments
 (0)