Skip to content

Commit cc25a35

Browse files
authored
add hbase put case for perf opt (#231)
1 parent 4c5a936 commit cc25a35

File tree

1 file changed

+256
-0
lines changed

1 file changed

+256
-0
lines changed

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

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.hadoop.hbase.client.Get;
2525
import org.apache.hadoop.hbase.client.Put;
2626
import org.apache.hadoop.hbase.client.Result;
27+
import org.apache.hadoop.hbase.util.Bytes;
2728
import org.apache.hadoop.hbase.util.Pair;
2829
import org.junit.*;
2930

@@ -330,4 +331,259 @@ public void testMultiCFPut() throws Throwable {
330331
public void testMultiCFPutBatch() throws Throwable {
331332
FOR_EACH(group2tableNames, OHTableSecondaryPartPutTest::testMltiCFPutBatchImpl);
332333
}
334+
335+
@Test
336+
public void testPutOpt() throws Throwable {
337+
FOR_EACH(tableNames, OHTableSecondaryPartPutTest::testPutOptImpl);
338+
FOR_EACH(group2tableNames, OHTableSecondaryPartPutTest::testMultiCFPutOptImpl);
339+
}
340+
341+
public static void testPutOptImpl(String tableName) throws Exception {
342+
int NUM_QUALIFIERS = 10;
343+
int NUM_PUTS = 10;
344+
byte[] family = toBytes(getColumnFamilyName(tableName));
345+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
346+
hTable.init();
347+
{ // 单put,10个Qualifier
348+
Put put = new Put(toBytes("row1"));
349+
List<String> qualifiers = new ArrayList<>();
350+
for (int i = 1; i <= NUM_QUALIFIERS; i++) {
351+
byte[] qualifier = toBytes("q" + i);
352+
byte[] value = toBytes("value" + i);
353+
put.addColumn(family, qualifier, value);
354+
qualifiers.add(Bytes.toString(qualifier));
355+
}
356+
hTable.put(put);
357+
// verify
358+
Get get = new Get(Bytes.toBytes("row1"));
359+
Result result = hTable.get(get);
360+
Assert.assertEquals(NUM_QUALIFIERS, result.getFamilyMap(family).size());
361+
qualifiers.forEach(q ->
362+
Assert.assertNotNull("Qualifier " + q + " not found",
363+
result.getValue(family, Bytes.toBytes(q)))
364+
);
365+
}
366+
367+
{ // 单put,10个Qualifier,指定相同timestamp
368+
Put put = new Put(toBytes("row2"));
369+
List<String> qualifiers = new ArrayList<>();
370+
long timestamp = System.currentTimeMillis();
371+
for (int i = 1; i <= NUM_QUALIFIERS; i++) {
372+
byte[] qualifier = toBytes("q" + i);
373+
byte[] value = toBytes("value" + i);
374+
put.addColumn(family, qualifier, timestamp, value);
375+
qualifiers.add(Bytes.toString(qualifier));
376+
}
377+
hTable.put(put);
378+
// verify
379+
Get get = new Get(Bytes.toBytes("row2"));
380+
Result result = hTable.get(get);
381+
Assert.assertEquals(NUM_QUALIFIERS, result.getFamilyMap(family).size());
382+
qualifiers.forEach(q ->
383+
Assert.assertNotNull("Qualifier " + q + " not found",
384+
result.getValue(family, Bytes.toBytes(q)))
385+
);
386+
}
387+
{ // batch put,相同key, 多个Qualifier
388+
byte[] rowKey = Bytes.toBytes("batch_row");
389+
List<Put> puts = new ArrayList<>();
390+
List<String> qualifiers = new ArrayList<>();
391+
for (int i = 1; i <= NUM_PUTS; i++) {
392+
Put put = new Put(rowKey);
393+
byte[] qualifier = Bytes.toBytes("batch_q" + i);
394+
put.addColumn(family, qualifier, Bytes.toBytes("batch_val" + i));
395+
puts.add(put);
396+
qualifiers.add(Bytes.toString(qualifier));
397+
}
398+
hTable.put(puts);
399+
// verify
400+
Get get = new Get(rowKey);
401+
Result result = hTable.get(get);
402+
Assert.assertEquals(NUM_QUALIFIERS, result.getFamilyMap(family).size());
403+
qualifiers.forEach(q ->
404+
Assert.assertNotNull("Qualifier " + q + " not found",
405+
result.getValue(family, Bytes.toBytes(q)))
406+
);
407+
}
408+
409+
{ // batch put,相同key,多个Qualifier,指定相同timestamp
410+
byte[] rowKey = Bytes.toBytes("batch_row_ts");
411+
List<Put> puts = new ArrayList<>();
412+
List<String> qualifiers = new ArrayList<>();
413+
for (int i = 1; i <= NUM_PUTS; i++) {
414+
Put put = new Put(rowKey);
415+
byte[] qualifier = Bytes.toBytes("batch_ts_q" + i);
416+
put.addColumn(family, qualifier, Bytes.toBytes("batch_val" + i));
417+
puts.add(put);
418+
qualifiers.add(Bytes.toString(qualifier));
419+
}
420+
hTable.put(puts);
421+
// verify
422+
Get get = new Get(rowKey);
423+
Result result = hTable.get(get);
424+
Assert.assertEquals(NUM_QUALIFIERS, result.getFamilyMap(family).size());
425+
qualifiers.forEach(q ->
426+
Assert.assertNotNull("Qualifier " + q + " not found",
427+
result.getValue(family, Bytes.toBytes(q)))
428+
);
429+
}
430+
}
431+
432+
public static void testMultiCFPutOptImpl(Map.Entry<String, List<String>> entry) throws Exception {
433+
int NUM_QUALIFIERS = 10;
434+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(entry.getKey()));
435+
hTable.init();
436+
{
437+
Put put = new Put(toBytes("multi_cf_row"));
438+
for (String tableName : entry.getValue()) {
439+
byte[] family = toBytes(getColumnFamilyName(tableName));
440+
// 单put,10个Qualifier
441+
List<String> qualifiers = new ArrayList<>();
442+
for (int i = 0; i < NUM_QUALIFIERS; i++) {
443+
byte[] qualifier = toBytes("q" + i);
444+
byte[] value = toBytes("value_" + i);
445+
put.addColumn(family, qualifier, value);
446+
qualifiers.add(Bytes.toString(qualifier));
447+
}
448+
}
449+
hTable.put(put);
450+
// verify
451+
Get get = new Get(Bytes.toBytes("multi_cf_row"));
452+
Result result = hTable.get(get);
453+
for (String tableName : entry.getValue()) {
454+
byte[] family = toBytes(getColumnFamilyName(tableName));
455+
Assert.assertEquals(NUM_QUALIFIERS,
456+
result.getFamilyMap(family).size());
457+
458+
for (int i = 0; i < NUM_QUALIFIERS; i++) {
459+
byte[] val = result.getValue(family, Bytes.toBytes("q" + i));
460+
Assert.assertEquals( "value_" + i,
461+
Bytes.toString(val));
462+
}
463+
}
464+
}
465+
466+
{ // 指定timestamp
467+
long currentTimestamp = System.currentTimeMillis();
468+
Put put = new Put(toBytes("multi_cf_ts_row"));
469+
for (String tableName : entry.getValue()) {
470+
byte[] family = toBytes(getColumnFamilyName(tableName));
471+
// 单put,10个Qualifier
472+
List<String> qualifiers = new ArrayList<>();
473+
for (int i = 0; i < NUM_QUALIFIERS; i++) {
474+
byte[] qualifier = toBytes("q" + i);
475+
byte[] value = toBytes("value_" + i);
476+
put.addColumn(family, qualifier, currentTimestamp, value);
477+
qualifiers.add(Bytes.toString(qualifier));
478+
}
479+
}
480+
hTable.put(put);
481+
// verify
482+
Get get = new Get(Bytes.toBytes("multi_cf_ts_row"));
483+
Result result = hTable.get(get);
484+
for (String tableName : entry.getValue()) {
485+
byte[] family = toBytes(getColumnFamilyName(tableName));
486+
Assert.assertEquals(NUM_QUALIFIERS,
487+
result.getFamilyMap(family).size());
488+
489+
for (int i = 0; i < NUM_QUALIFIERS; i++) {
490+
byte[] val = result.getValue(family, Bytes.toBytes("q" + i));
491+
Assert.assertEquals( "value_" + i,
492+
Bytes.toString(val));
493+
}
494+
}
495+
}
496+
497+
{
498+
byte[] ROW = Bytes.toBytes("batch_row");
499+
List<Put> puts = new ArrayList<>();
500+
for (String tableName : entry.getValue()) {
501+
byte[] family = toBytes(getColumnFamilyName(tableName));
502+
Put put = new Put(ROW);
503+
for (int i = 0; i < NUM_QUALIFIERS; i++) {
504+
put.addColumn(family,
505+
Bytes.toBytes("q" + i),
506+
Bytes.toBytes("value_" + i));
507+
}
508+
puts.add(put);
509+
}
510+
hTable.put(puts);
511+
// verify
512+
Get get = new Get(ROW);
513+
Result result = hTable.get(get);
514+
for (String tableName : entry.getValue()) {
515+
byte[] family = toBytes(getColumnFamilyName(tableName));
516+
Assert.assertEquals(NUM_QUALIFIERS,
517+
result.getFamilyMap(family).size());
518+
519+
for (int i = 0; i < NUM_QUALIFIERS; i++) {
520+
byte[] val = result.getValue(family, Bytes.toBytes("q" + i));
521+
Assert.assertEquals( "value_" + i,
522+
Bytes.toString(val));
523+
}
524+
}
525+
}
526+
527+
{
528+
long timestamp = System.currentTimeMillis();
529+
byte[] ROW = Bytes.toBytes("batch_ts_row");
530+
List<Put> puts = new ArrayList<>();
531+
for (String tableName : entry.getValue()) {
532+
byte[] family = toBytes(getColumnFamilyName(tableName));
533+
for (int i = 0; i < NUM_QUALIFIERS; i++) {
534+
Put put = new Put(ROW);
535+
put.addColumn(family,
536+
Bytes.toBytes("q" + i),
537+
timestamp,
538+
Bytes.toBytes("value_" + i));
539+
puts.add(put);
540+
}
541+
}
542+
hTable.put(puts);
543+
// verify
544+
Get get = new Get(ROW);
545+
Result result = hTable.get(get);
546+
for (String tableName : entry.getValue()) {
547+
byte[] family = toBytes(getColumnFamilyName(tableName));
548+
Assert.assertEquals(NUM_QUALIFIERS,
549+
result.getFamilyMap(family).size());
550+
551+
for (int i = 0; i < NUM_QUALIFIERS; i++) {
552+
byte[] val = result.getValue(family, Bytes.toBytes("q" + i));
553+
Assert.assertEquals( "value_" + i,
554+
Bytes.toString(val));
555+
}
556+
}
557+
}
558+
559+
{
560+
byte[] ROW = Bytes.toBytes("batch_row_2");
561+
List<Put> puts = new ArrayList<>();
562+
for (int i = 0; i < NUM_QUALIFIERS; i++) {
563+
Put put = new Put(ROW);
564+
for (String tableName : entry.getValue()) {
565+
byte[] family = toBytes(getColumnFamilyName(tableName));
566+
put.addColumn(family,
567+
Bytes.toBytes("q" + i),
568+
Bytes.toBytes("value_" + i));
569+
}
570+
puts.add(put);
571+
}
572+
hTable.put(puts);
573+
// verify
574+
Get get = new Get(ROW);
575+
Result result = hTable.get(get);
576+
for (String tableName : entry.getValue()) {
577+
byte[] family = toBytes(getColumnFamilyName(tableName));
578+
Assert.assertEquals(NUM_QUALIFIERS,
579+
result.getFamilyMap(family).size());
580+
581+
for (int i = 0; i < NUM_QUALIFIERS; i++) {
582+
byte[] val = result.getValue(family, Bytes.toBytes("q" + i));
583+
Assert.assertEquals( "value_" + i,
584+
Bytes.toString(val));
585+
}
586+
}
587+
}
588+
}
333589
}

0 commit comments

Comments
 (0)