|
2 | 2 |
|
3 | 3 | import com.alipay.oceanbase.rpc.exception.ObTableException; |
4 | 4 | import com.alipay.oceanbase.rpc.get.Get; |
| 5 | +import com.alipay.oceanbase.rpc.get.result.GetResult; |
5 | 6 | import com.alipay.oceanbase.rpc.mutation.BatchOperation; |
6 | 7 | import com.alipay.oceanbase.rpc.mutation.result.BatchOperationResult; |
7 | 8 | import com.alipay.oceanbase.rpc.util.ObTableClientTestUtil; |
8 | 9 | import org.junit.Assert; |
9 | 10 | import org.junit.Before; |
10 | 11 | import org.junit.Test; |
11 | 12 |
|
| 13 | +import java.util.List; |
12 | 14 | import java.util.Map; |
13 | 15 |
|
14 | 16 | import static com.alipay.oceanbase.rpc.mutation.MutationFactory.colVal; |
15 | 17 | import static com.alipay.oceanbase.rpc.mutation.MutationFactory.row; |
16 | | -import static org.junit.Assert.assertThrows; |
17 | | -import static org.junit.Assert.assertTrue; |
| 18 | +import static org.junit.Assert.*; |
| 19 | +import static org.junit.Assert.assertEquals; |
18 | 20 |
|
19 | 21 | /* |
20 | 22 | CREATE TABLE IF NOT EXISTS `test_get` ( |
@@ -259,4 +261,37 @@ public void testBatchGet5() { |
259 | 261 | System.out.println(thrown.getMessage()); |
260 | 262 | assertTrue(thrown.getMessage().contains("[-4007][OB_NOT_SUPPORTED][operation is not supported to partially fill rowkey columns not supported]")); |
261 | 263 | } |
| 264 | + |
| 265 | + /* test same Get */ |
| 266 | + @Test |
| 267 | + public void testBatchGet6() throws Exception { |
| 268 | + try { |
| 269 | + // insert |
| 270 | + client.insertOrUpdate(tableName) |
| 271 | + .setRowKey(row(colVal("c1", "c1_val"), colVal("c2", "c2_val"))) |
| 272 | + .addMutateColVal(colVal("c3", "c3_val")).execute(); |
| 273 | + |
| 274 | + // select c1,c2 |
| 275 | + BatchOperation batch = client.batchOperation(tableName); |
| 276 | + Get get1 = client.get(tableName) |
| 277 | + .setRowKey(row(colVal("c1", "c1_val"), colVal("c2", "c2_val"))).select("c1", "c2", "c3"); |
| 278 | + Get get2 = client.get(tableName) |
| 279 | + .setRowKey(row(colVal("c1", "c1_val"), colVal("c2", "c2_val"))).select("c1", "c2", "c3"); |
| 280 | + batch.addOperation(get1, get2); |
| 281 | + BatchOperationResult res = batch.execute(); |
| 282 | + Assert.assertNotNull(res); |
| 283 | + List<Object> getResults = res.getResults(); |
| 284 | + assertEquals(2, getResults.size()); |
| 285 | + for (Object result : getResults) { |
| 286 | + GetResult getResult = (GetResult) result; |
| 287 | + Map<String, Object> row = getResult.getOperationRow().getMap(); |
| 288 | + assertEquals("c1_val", row.get("c1")); |
| 289 | + assertEquals("c2_val", row.get("c2")); |
| 290 | + assertEquals("c3_val", row.get("c3")); |
| 291 | + } |
| 292 | + } finally { |
| 293 | + client.delete(tableName).setRowKey(row(colVal("c1", "c1_val"), colVal("c2", "c2_val"))) |
| 294 | + .execute(); |
| 295 | + } |
| 296 | + } |
262 | 297 | } |
0 commit comments