@@ -53,6 +53,9 @@ public static void main(String[] args) {
53
53
SimpleTest .run ();
54
54
ParallelWriteTest .run ();
55
55
MultiNodeWriteTest .run ();
56
+ P2PModeWriteTest .run ();
57
+ AbortBeforeCommitTest .run ();
58
+ AbortAfterCommitAsyncTest .run ();
56
59
}
57
60
58
61
private static void prepareTestTable () throws Exception {
@@ -111,6 +114,12 @@ private static ObDirectLoadStatement buildStatement(ObDirectLoadConnection conne
111
114
.setParallel (parallel ).setQueryTimeout (timeout ).build ();
112
115
}
113
116
117
+ private static ObDirectLoadStatement buildP2PModeStatement (ObDirectLoadConnection connection )
118
+ throws ObDirectLoadException {
119
+ return connection .getStatementBuilder ().setTableName (tableName ).setDupAction (dupAction )
120
+ .setParallel (parallel ).setQueryTimeout (timeout ).setP2PMode ().build ();
121
+ }
122
+
114
123
private static class SimpleTest {
115
124
116
125
public static void run () {
@@ -309,4 +318,196 @@ public static void run() {
309
318
310
319
};
311
320
321
+ private static class P2PModeWriteTest {
322
+
323
+ private static class P2PModeWriter implements Runnable {
324
+
325
+ private final byte [] executionIdBytes ;
326
+ private final int id ;
327
+ boolean needCommit ;
328
+ Thread [] threads ;
329
+
330
+ P2PModeWriter (byte [] executionIdBytes , int id ) {
331
+ this .executionIdBytes = executionIdBytes ;
332
+ this .id = id ;
333
+ }
334
+
335
+ P2PModeWriter (byte [] executionIdBytes , int id , Thread [] threads ) {
336
+ this .executionIdBytes = executionIdBytes ;
337
+ this .id = id ;
338
+ this .needCommit = true ;
339
+ this .threads = threads ;
340
+ }
341
+
342
+ @ Override
343
+ public void run () {
344
+ ObDirectLoadConnection connection = null ;
345
+ ObDirectLoadStatement statement = null ;
346
+ try {
347
+ ObDirectLoadStatementExecutionId executionId = new ObDirectLoadStatementExecutionId ();
348
+ executionId .decode (executionIdBytes );
349
+
350
+ connection = buildConnection (1 );
351
+ statement = buildP2PModeStatement (connection );
352
+
353
+ statement .resume (executionId );
354
+
355
+ statement .startHeartBeat ();
356
+
357
+ ObDirectLoadBucket bucket = new ObDirectLoadBucket ();
358
+ ObObj [] rowObjs = new ObObj [2 ];
359
+ rowObjs [0 ] = new ObObj (ObObjType .ObInt32Type .getDefaultObjMeta (), id );
360
+ rowObjs [1 ] = new ObObj (ObObjType .ObInt32Type .getDefaultObjMeta (), id );
361
+ bucket .addRow (rowObjs );
362
+ statement .write (bucket );
363
+
364
+ if (needCommit ) {
365
+ for (int i = 0 ; i < threads .length ; ++i ) {
366
+ threads [i ].join ();
367
+ }
368
+ statement .commit ();
369
+ }
370
+
371
+ } catch (Exception e ) {
372
+ throw new RuntimeException (e );
373
+ } finally {
374
+ if (null != statement ) {
375
+ statement .close ();
376
+ }
377
+ if (null != connection ) {
378
+ connection .close ();
379
+ }
380
+ }
381
+ }
382
+
383
+ };
384
+
385
+ public static void run () {
386
+ System .out .println ("P2PModeWriteTest start" );
387
+ final int writeThreadNum = 10 ;
388
+ ObDirectLoadConnection connection = null ;
389
+ ObDirectLoadStatement statement = null ;
390
+ try {
391
+ prepareTestTable ();
392
+
393
+ connection = buildConnection (1 );
394
+ statement = buildP2PModeStatement (connection );
395
+
396
+ statement .begin ();
397
+
398
+ ObDirectLoadStatementExecutionId executionId = statement .getExecutionId ();
399
+ byte [] executionIdBytes = executionId .encode ();
400
+
401
+ Thread [] threads = new Thread [writeThreadNum ];
402
+ for (int i = 0 ; i < threads .length ; ++i ) {
403
+ P2PModeWriter NodeWriter = new P2PModeWriter (executionIdBytes , i );
404
+ Thread thread = new Thread (NodeWriter );
405
+ threads [i ] = thread ;
406
+ }
407
+ P2PModeWriter commitNodeWriter = new P2PModeWriter (executionIdBytes , writeThreadNum , threads );
408
+ Thread commitThread = new Thread (commitNodeWriter );
409
+ commitThread .start ();
410
+ for (int i = 0 ; i < threads .length ; ++i ) {
411
+ threads [i ].start ();
412
+ }
413
+ commitThread .join ();
414
+ queryTestTable (writeThreadNum + 1 );
415
+
416
+ } catch (Exception e ) {
417
+ throw new RuntimeException (e );
418
+ } finally {
419
+ if (null != statement ) {
420
+ statement .close ();
421
+ }
422
+ if (null != connection ) {
423
+ connection .close ();
424
+ }
425
+ }
426
+ System .out .println ("P2PModeWriteTest successful" );
427
+ }
428
+
429
+ };
430
+
431
+ private static class AbortBeforeCommitTest {
432
+
433
+ public static void run () {
434
+ System .out .println ("AbortBeforeCommitTest start" );
435
+ ObDirectLoadConnection connection = null ;
436
+ ObDirectLoadStatement statement = null ;
437
+ try {
438
+ prepareTestTable ();
439
+ System .out .println ("prepareTestTable" );
440
+
441
+ connection = buildConnection (1 );
442
+ statement = buildStatement (connection );
443
+
444
+ statement .begin ();
445
+
446
+ ObDirectLoadBucket bucket = new ObDirectLoadBucket ();
447
+ ObObj [] rowObjs = new ObObj [2 ];
448
+ rowObjs [0 ] = new ObObj (ObObjType .ObInt32Type .getDefaultObjMeta (), 1 );
449
+ rowObjs [1 ] = new ObObj (ObObjType .ObInt32Type .getDefaultObjMeta (), 2 );
450
+ bucket .addRow (rowObjs );
451
+ statement .write (bucket );
452
+
453
+ statement .abort ();
454
+
455
+ queryTestTable (0 );
456
+ } catch (Exception e ) {
457
+ throw new RuntimeException (e );
458
+ } finally {
459
+ if (null != statement ) {
460
+ statement .close ();
461
+ }
462
+ if (null != connection ) {
463
+ connection .close ();
464
+ }
465
+ }
466
+ System .out .println ("AbortBeforeCommitTest successful" );
467
+ }
468
+
469
+ };
470
+
471
+ private static class AbortAfterCommitAsyncTest {
472
+
473
+ public static void run () {
474
+ System .out .println ("AbortAfterCommitAsyncTest start" );
475
+ ObDirectLoadConnection connection = null ;
476
+ ObDirectLoadStatement statement = null ;
477
+ try {
478
+ prepareTestTable ();
479
+ System .out .println ("prepareTestTable" );
480
+
481
+ connection = buildConnection (1 );
482
+ statement = buildStatement (connection );
483
+
484
+ statement .begin ();
485
+
486
+ ObDirectLoadBucket bucket = new ObDirectLoadBucket ();
487
+ ObObj [] rowObjs = new ObObj [2 ];
488
+ rowObjs [0 ] = new ObObj (ObObjType .ObInt32Type .getDefaultObjMeta (), 1 );
489
+ rowObjs [1 ] = new ObObj (ObObjType .ObInt32Type .getDefaultObjMeta (), 2 );
490
+ bucket .addRow (rowObjs );
491
+ statement .write (bucket );
492
+
493
+ statement .commitAsync ();
494
+
495
+ statement .abort ();
496
+
497
+ queryTestTable (0 );
498
+ } catch (Exception e ) {
499
+ throw new RuntimeException (e );
500
+ } finally {
501
+ if (null != statement ) {
502
+ statement .close ();
503
+ }
504
+ if (null != connection ) {
505
+ connection .close ();
506
+ }
507
+ }
508
+ System .out .println ("AbortAfterCommitAsyncTest successful" );
509
+ }
510
+
511
+ };
512
+
312
513
}
0 commit comments