Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

371 changes: 0 additions & 371 deletions src/test/java/com/alipay/oceanbase/hbase/OHTableSecondaryPartTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*-
* #%L
* OBKV HBase Client Framework
* %%
* Copyright (C) 2025 OceanBase Group
* %%
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* #L%
*/


package com.alipay.oceanbase.hbase.secondary;

import com.alipay.oceanbase.hbase.OHTableClient;
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
import com.alipay.oceanbase.hbase.util.TableTemplateManager;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Append;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static com.alipay.oceanbase.hbase.util.ObHTableSecondaryPartUtil.*;
import static com.alipay.oceanbase.hbase.util.ObHTableTestUtil.FOR_EACH;
import static org.junit.Assert.assertEquals;

public class OHTableSecondaryPartAppendTest {
private static List<String> tableNames = new LinkedList<String>();
private static Map<String, List<String>> group2tableNames = null;


@BeforeClass
public static void before() throws Exception {
for (TableTemplateManager.TableType type : TableTemplateManager.TableType.values()) {
createTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
dropTables(tableNames, group2tableNames);
}

@Before
public void prepareCase() throws Exception {
truncateTables(tableNames, group2tableNames);
}

public static void testAppendImpl(String tableName) throws Exception {
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
hTable.init();

String family = getColumnFamilyName(tableName);
String key = "putKey";
String column1 = "putColumn1";
String column2 = "putColumn2";
String value = "value";
Append append = new Append(key.getBytes());
KeyValue kv1 = new KeyValue(key.getBytes(), family.getBytes(), column1.getBytes(), value.getBytes());
KeyValue kv2 = new KeyValue(key.getBytes(), family.getBytes(), column2.getBytes(), value.getBytes());
append.add(kv1);
append.add(kv2);
hTable.append(append);

Get get = new Get(key.getBytes());
get.addFamily(family.getBytes());
Result result = hTable.get(get);
Cell[] cells = result.rawCells();
assertEquals(2, cells.length);

for (Cell cell : cells) {
if (Bytes.toString(CellUtil.cloneQualifier(cell)).equals(column1)) {
assertEquals("valuevalue", Bytes.toString(CellUtil.cloneValue(cell)));
} else if (Bytes.toString(CellUtil.cloneQualifier(cell)).equals(column2)) {
assertEquals("valuevalue", Bytes.toString(CellUtil.cloneValue(cell)));
}
}
hTable.close();
}

@Test
public void testAppend() throws Exception {
FOR_EACH(tableNames, OHTableSecondaryPartAppendTest::testAppendImpl);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*-
* #%L
* OBKV HBase Client Framework
* %%
* Copyright (C) 2025 OceanBase Group
* %%
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* #L%
*/

package com.alipay.oceanbase.hbase.secondary;

import com.alipay.oceanbase.hbase.OHTableClient;
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
import com.alipay.oceanbase.hbase.util.TableTemplateManager;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.*;

import static com.alipay.oceanbase.hbase.util.ObHTableSecondaryPartUtil.*;
import static com.alipay.oceanbase.hbase.util.ObHTableTestUtil.FOR_EACH;
import static org.apache.hadoop.hbase.util.Bytes.toBytes;
import static org.junit.Assert.assertEquals;


public class OHTableSecondaryPartBatchGetTest {
private static List<String> tableNames = new LinkedList<String>();
private static Map<String, List<String>> group2tableNames = new LinkedHashMap<>();


@BeforeClass
public static void before() throws Exception {
for (TableTemplateManager.TableType type : TableTemplateManager.TableType.values()) {
createTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
dropTables(tableNames, group2tableNames);
}

@Before
public void prepareCase() throws Exception {
truncateTables(tableNames, group2tableNames);
}


public static void testBatchGetImpl(String tableName) throws Exception {
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
hTable.init();

String family = getColumnFamilyName(tableName);
String key = "putKey";
String column1 = "putColumn1";
String column2 = "putColumn2";
long timestamp = System.currentTimeMillis();
Put put = new Put(toBytes(key));
put.add(family.getBytes(), column1.getBytes(), timestamp, toBytes("1"));
put.add(family.getBytes(), column2.getBytes(), timestamp, toBytes("1"));
hTable.put(put);

List<Get> gets = new ArrayList<>();
Get get1 = new Get(key.getBytes());
get1.addFamily(family.getBytes());
gets.add(get1);

Get get2 = new Get(key.getBytes());
get2.addColumn(family.getBytes(), column1.getBytes());
gets.add(get2);

Get get3 = new Get(key.getBytes());
get3.addColumn(family.getBytes(), column2.getBytes());
gets.add(get3);


Result[] results = hTable.get(gets);
for (Result result : results) {
for (Cell cell : result.listCells()) {
String Q = Bytes.toString(CellUtil.cloneQualifier(cell));
String V = Bytes.toString(CellUtil.cloneValue(cell));
System.out.println("Column: " + Q + ", Value: " + V);
}
}
}

@Test
public void testBatchGet() throws Exception {
FOR_EACH(tableNames, OHTableSecondaryPartBatchGetTest::testBatchGetImpl);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*-
* #%L
* OBKV HBase Client Framework
* %%
* Copyright (C) 2025 OceanBase Group
* %%
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* #L%
*/

package com.alipay.oceanbase.hbase.secondary;

import com.alipay.oceanbase.hbase.OHTableClient;
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
import com.alipay.oceanbase.hbase.util.TableTemplateManager;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static com.alipay.oceanbase.hbase.util.ObHTableSecondaryPartUtil.*;
import static com.alipay.oceanbase.hbase.util.ObHTableTestUtil.FOR_EACH;
import static org.apache.hadoop.hbase.util.Bytes.toBytes;
import static org.junit.Assert.assertEquals;


public class OHTableSecondaryPartCheckAndMutateTest {
private static List<String> tableNames = new LinkedList<String>();
private static Map<String, List<String>> group2tableNames = new LinkedHashMap<>();


@BeforeClass
public static void before() throws Exception {
for (TableTemplateManager.TableType type : TableTemplateManager.TableType.values()) {
createTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
dropTables(tableNames, group2tableNames);
}

@Before
public void prepareCase() throws Exception {
truncateTables(tableNames, group2tableNames);
}

public static void testCheckAndMutateImpl(String tableName) throws Exception {
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
hTable.init();

String family = getColumnFamilyName(tableName);
String key = "putKey";
String column = "putColumn";
String value = "value";
String newValue = "newValue";
RowMutations mutations = new RowMutations(key.getBytes());
Put put = new Put(key.getBytes());
long timestamp = System.currentTimeMillis();
put.add(family.getBytes(), column.getBytes(), timestamp, toBytes(value));
hTable.put(put);

Put newPut = new Put(key.getBytes());
newPut.add(family.getBytes(), column.getBytes(), timestamp, toBytes(newValue));
mutations.add(newPut);
hTable.checkAndMutate(key.getBytes(), family.getBytes(),
column.getBytes(), CompareFilter.CompareOp.EQUAL, value.getBytes(),
mutations);

hTable.close();
}

@Test
public void testCheckAndMutate() throws Exception {
FOR_EACH(tableNames, OHTableSecondaryPartCheckAndMutateTest::testCheckAndMutateImpl);
}

}
Loading