3535import com .alipay .oceanbase .rpc .util .ObTableClientTestUtil ;
3636import org .junit .Assert ;
3737import org .junit .Before ;
38+ import org .junit .Ignore ;
3839import org .junit .Test ;
3940
4041import java .sql .Connection ;
@@ -326,30 +327,33 @@ public void testOneLevelHashPartition() throws Exception {
326327
327328 /*
328329 * CREATE TABLE IF NOT EXISTS `testRange` (
329- `c1` int NOT NULL,
330- `c2` varchar(20) NOT NULL,
331- `c3` varbinary(1024) DEFAULT NULL,
332- `c4` bigint DEFAULT NULL,
333- PRIMARY KEY(`c1`, `c2`)) partition by range columns (`c1`, `c2`) (
334- PARTITION p0 VALUES LESS THAN (300, 't'),
335- PARTITION p1 VALUES LESS THAN (1000, 'T'),
336- PARTITION p2 VALUES LESS THAN (MAXVALUE, MAXVALUE));
330+ `K` varbinary(1024),
331+ `Q` varbinary(256),
332+ `T` bigint,
333+ `V` varbinary(10240),
334+ INDEX i1(`K`, `V`) local,
335+ PRIMARY KEY(`K`, `Q`, `T`)
336+ ) partition by range columns (`K`) (
337+ PARTITION p0 VALUES LESS THAN ('a'),
338+ PARTITION p1 VALUES LESS THAN ('w'),
339+ PARTITION p2 VALUES LESS THAN MAXVALUE
340+ );
337341 * */
338342 @ Test
339343 public void testOneLevelRangePartition () throws Exception {
340344 BatchOperation batchOperation = client .batchOperation (TABLE_NAME3 );
341- Object values [][] = { { 1 , "c2_val1" , "c3_val1" , 1L }, { 101 , "c2_val1" , "c3_val1" , 101L },
342- { 501 , "c2_val1" , "c3_val1" , 501L }, { 901 , "c2_val1" , "c3_val1" , 901L },
343- { 1001 , "c2_val1" , "c3_val1" , 1001L }, { 1501 , "c2_val1" , "c3_val1" , 1501L }, };
345+ Object values [][] = { { "ah" , "c2_val1" , 1L , "c3_val1" }, { "bw" , "c2_val1" , 101L , "c3_val1" },
346+ { "ht" , "c2_val1" , 501L , "c3_val1" }, { "tw" , "c2_val1" , 901L , "c3_val1" },
347+ { "xy" , "c2_val1" , 1001L , "c3_val1" }, { "zw" , "c2_val1" , 1501L , "c3_val1" } };
344348 int rowCnt = values .length ;
345349
346350 try {
347351 // test batch insert in ODP mode
348352 for (int i = 0 ; i < rowCnt ; i ++) {
349353 Object [] curRow = values [i ];
350354 InsertOrUpdate insertOrUpdate = new InsertOrUpdate ();
351- insertOrUpdate .setRowKey (row (colVal ("c1 " , curRow [0 ]), colVal ("c2 " , curRow [1 ])));
352- insertOrUpdate .addMutateRow (row (colVal ("c3" , curRow [ 2 ]), colVal ( "c4 " , curRow [3 ])));
355+ insertOrUpdate .setRowKey (row (colVal ("K " , curRow [0 ]), colVal ("Q " , curRow [1 ]), colVal ( "T" , curRow [ 2 ])));
356+ insertOrUpdate .addMutateRow (row (colVal ("V " , curRow [3 ])));
353357 batchOperation .addOperation (insertOrUpdate );
354358 }
355359 BatchOperationResult batchOperationResult = batchOperation .execute ();
@@ -360,26 +364,26 @@ public void testOneLevelRangePartition() throws Exception {
360364 System .out .println (partition .toString ());
361365 }
362366
363- // test get the first partition
367+ // test get the first partition using nonexistent row
364368 Partition first_partition = client .getPartition (TABLE_NAME3 ,
365- row (colVal ("c1 " , 1L ), colVal ("c2 " , "c2_val" )), false );
369+ row (colVal ("K " , "A" ), colVal ("Q " , "bw" ), colVal ( "T" , 1L )), false );
366370 Assert .assertEquals (partitions .get (0 ).getPartitionId (),
367371 first_partition .getPartitionId ());
368372 // test get the second partition
369373 Partition sec_partition = client .getPartition (TABLE_NAME3 ,
370- row (colVal ("c1 " , 401L ), colVal ("c2 " , "c2_val" )), false );
374+ row (colVal ("K " , "ah" ), colVal ("Q " , "bw" ), colVal ( "T" , 1L )), false );
371375 Assert .assertEquals (partitions .get (1 ).getPartitionId (), sec_partition .getPartitionId ());
372376 // test get the same partition with the first partition key
373377 Partition partition1 = client .getPartition (TABLE_NAME3 ,
374- row (colVal ("c1 " , 101L ), colVal ( "c2" , "c2_val " )), false );
378+ row (colVal ("K " , "B " )), false );
375379 Assert .assertEquals (first_partition .getPartitionId (), partition1 .getPartitionId ());
376380 } catch (Exception e ) {
377381 e .printStackTrace ();
378382 Assert .assertTrue (false );
379383 } finally {
380384 for (int j = 0 ; j < rowCnt ; j ++) {
381385 Delete delete = client .delete (TABLE_NAME3 );
382- delete .setRowKey (row (colVal ("c1 " , values [j ][0 ]), colVal ("c2 " , values [j ][1 ])));
386+ delete .setRowKey (row (colVal ("K " , values [j ][0 ]), colVal ("Q " , values [j ][1 ]), colVal ( "T" , values [ j ][ 2 ])));
383387 MutationResult res = delete .execute ();
384388 Assert .assertEquals (1 , res .getAffectedRows ());
385389 }
@@ -537,9 +541,11 @@ public void testConcurrentGetPartition() throws Exception {
537541 }
538542 cnt .getAndIncrement ();
539543 } else {
544+ byte [] bytes = new byte [10 ];
545+ random .nextBytes (bytes );
540546 MutationResult resultSet = client .insert (TABLE_NAME3 )
541- .setRowKey (row (colVal ("c1 " , random . nextInt ()) , colVal ("c2 " , "c2_val1" )))
542- .addMutateRow (row (colVal ("c3 " , "c3_val1" ), colVal ( "c4" , 10L ))).execute ();
547+ .setRowKey (row (colVal ("K " , bytes ) , colVal ("Q " , "c2_val1" ), colVal ( "T" , random . nextLong () )))
548+ .addMutateRow (row (colVal ("V " , "c3_val1" ))).execute ();
543549 Assert .assertEquals (1 , resultSet .getAffectedRows ());
544550 List <Partition > partitions = client .getPartition (table_name , false );
545551 Assert .assertEquals (3 , partitions .size ());
@@ -583,18 +589,18 @@ public void testConcurrentGetPartition() throws Exception {
583589 }
584590 }
585591
586- @ Test
592+ @ Ignore
587593 public void testReFetchPartitionMeta () throws Exception {
588594 String table_name = TABLE_NAME3 ;
589595 BatchOperation batchOperation = client .batchOperation (table_name );
590- Object values [][] = { { 1 , "c2_val1" , "c3_val1" , 1L }, { 101 , "c2_val1" , "c3_val1" , 101L },
591- { 501 , "c2_val1" , "c3_val1" , 501L }, { 901 , "c2_val1" , "c3_val1" , 901L },
592- { 1001 , "c2_val1" , "c3_val1" , 1001L }, { 1501 , "c2_val1" , "c3_val1" , 1501L }, };
596+ Object values [][] = { { "ah" , "c2_val1" , 1L , "c3_val1" }, { "bw" , "c2_val1" , 101L , "c3_val1" },
597+ { "ht" , "c2_val1" , 501L , "c3_val1" }, { "tw" , "c2_val1" , 901L , "c3_val1" },
598+ { "xy" , "c2_val1" , 1001L , "c3_val1" }, { "zw" , "c2_val1" , 1501L , "c3_val1" } };
593599 int rowCnt = values .length ;
594600 try {
595601 MutationResult resultSet = client .insertOrUpdate (TABLE_NAME3 )
596- .setRowKey (row (colVal ("c1 " , 10 ), colVal ("c2 " , "c2_val1" )))
597- .addMutateRow (row (colVal ("c3 " , "c3_val1" ), colVal ( "c4" , 10L ))).execute ();
602+ .setRowKey (row (colVal ("K " , "ah" ), colVal ("Q " , "c2_val1" ), colVal ( "T" , 1L )))
603+ .addMutateRow (row (colVal ("T " , "c3_val1" ))).execute ();
598604 Assert .assertEquals (1 , resultSet .getAffectedRows ());
599605 // need to manually breakpoint here to change table schema in database
600606 resultSet = client .insertOrUpdate (TABLE_NAME3 )
0 commit comments