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
2 changes: 0 additions & 2 deletions src/main/java/com/alipay/oceanbase/hbase/OHTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1324,8 +1324,6 @@ private boolean checkAndMutation(byte[] row, byte[] family, byte[] qualifier,
RowMutations rowMutations) throws Exception {
checkArgument(row != null, "row is null");
checkArgument(isNotBlank(Bytes.toString(family)), "family is blank");
checkArgument(Bytes.equals(row, rowMutations.getRow()),
"mutation row is not equal check row");
checkArgument(!rowMutations.getMutations().isEmpty(), "mutation is empty");
List<Mutation> mutations = rowMutations.getMutations();
// only one family operation is allowed
Expand Down
49 changes: 33 additions & 16 deletions src/test/java/com/alipay/oceanbase/hbase/HTableTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4761,7 +4761,7 @@ public void testDeleteIllegal() throws IOException {

@Test
public void testCheckAndMutationIllegal() throws IOException {
// check and mute 只支持一行操作
// checkAndPut 只支持一行操作
try {
Put put = new Put("key_7".getBytes());
put.add("family1".getBytes(), "column1_1".getBytes(), "value2".getBytes());
Expand All @@ -4772,20 +4772,6 @@ public void testCheckAndMutationIllegal() throws IOException {
Assert.assertTrue(e.getMessage().contains("doesn't match the original one"));
}

// check and mute 只支持一行操作
try {
RowMutations mutations = new RowMutations("key_7".getBytes());
Put put = new Put("key_7".getBytes());
put.add("family1".getBytes(), "column1_1".getBytes(), "value2".getBytes());
mutations.add(put);
boolean ret = hTable.checkAndMutate("key_8".getBytes(), "family1".getBytes(),
"column1_1".getBytes(), CompareFilter.CompareOp.EQUAL, "value1".getBytes(),
mutations);
fail();
} catch (IOException e) {
Assert.assertTrue(e.getMessage().contains("mutation row is not equal check row error"));
}

try {
Put put = new Put("key_8".getBytes());
put.add("family2".getBytes(), "column1_1".getBytes(), "value2".getBytes());
Expand Down Expand Up @@ -4942,6 +4928,7 @@ public void testCheckAndDelete() throws IOException {
public void testCheckAndMutate() throws IOException {
// Mutate 只支持操作一行数据
String key = "checkAndMutateKey";
String key1 = "checkAndMutateKey1";
String column1 = "checkAndMutateColumn";
String column2 = "checkAndMutateColumn2";
String value1 = "value1";
Expand Down Expand Up @@ -5080,6 +5067,36 @@ public void testCheckAndMutate() throws IOException {
get.setMaxVersions(Integer.MAX_VALUE);
r = hTable.get(get);
Assert.assertEquals(10, r.raw().length);

// test different row operations
put1 = new Put(key1.getBytes());
put1.add(family.getBytes(), column1.getBytes(), t, value1.getBytes());
put1.add(family.getBytes(), column2.getBytes(), t, value2.getBytes());

put2 = new Put(key1.getBytes());
put2.add(family.getBytes(), column1.getBytes(), t + 3, value2.getBytes());
put2.add(family.getBytes(), column2.getBytes(), t + 3, value1.getBytes());

put3 = new Put(key1.getBytes());
put3.add(family.getBytes(), column1.getBytes(), t + 5, value1.getBytes());
put3.add(family.getBytes(), column2.getBytes(), t + 5, value2.getBytes());

rowMutations = new RowMutations(key1.getBytes());
rowMutations.add(put1);
rowMutations.add(put2);
rowMutations.add(put3);
// check specific row in server and execute different row operations
assertTrue(hTable.checkAndMutate(key.getBytes(), family.getBytes(), column1.getBytes(),
CompareFilter.CompareOp.EQUAL, value1.getBytes(), rowMutations));

assertTrue(hTable.checkAndMutate(key.getBytes(), family.getBytes(), column2.getBytes(),
CompareFilter.CompareOp.GREATER, value1.getBytes(), rowMutations));

assertFalse(hTable.checkAndMutate(key.getBytes(), family.getBytes(), column1.getBytes(),
CompareFilter.CompareOp.LESS, value1.getBytes(), rowMutations));

assertFalse(hTable.checkAndMutate(key.getBytes(), family.getBytes(), column2.getBytes(),
CompareFilter.CompareOp.GREATER, value2.getBytes(), rowMutations));
}

@Test
Expand Down Expand Up @@ -5189,7 +5206,7 @@ public void testCellTTL() throws Exception {
try {
tryPut(hTable, errorPut);
} catch (Exception e) {
assertTrue(e.getCause().getCause().toString().contains("Unknown column 'TTL'"));
assertTrue(e.getCause().toString().contains("Unknown column 'TTL'"));
}
// test put and get
tryPut(hTable, put1);
Expand Down