@@ -372,6 +372,9 @@ public function testBeginTransactionConsecutiveSuccess(): void
372
372
public function testBeginTransactionWithRetriableError (): void
373
373
{
374
374
self ::expectException (KafkaProducerTransactionRetryException::class);
375
+ self ::expectExceptionMessage (
376
+ sprintf (KafkaProducerTransactionRetryException::RETRIABLE_TRANSACTION_EXCEPTION_MESSAGE , '' )
377
+ );
375
378
376
379
$ errorMock = $ this ->createMock (RdKafkaErrorException::class);
377
380
$ errorMock ->expects (self ::once ())->method ('isRetriable ' )->willReturn (true );
@@ -393,6 +396,9 @@ public function testBeginTransactionWithRetriableError(): void
393
396
public function testBeginTransactionWithAbortError (): void
394
397
{
395
398
self ::expectException (KafkaProducerTransactionAbortException::class);
399
+ self ::expectExceptionMessage (
400
+ sprintf (KafkaProducerTransactionAbortException::TRANSACTION_REQUIRES_ABORT_EXCEPTION_MESSAGE , '' )
401
+ );
396
402
397
403
$ errorMock = $ this ->createMock (RdKafkaErrorException::class);
398
404
$ errorMock ->expects (self ::once ())->method ('isRetriable ' )->willReturn (false );
@@ -415,6 +421,9 @@ public function testBeginTransactionWithAbortError(): void
415
421
public function testBeginTransactionWithFatalError (): void
416
422
{
417
423
self ::expectException (KafkaProducerTransactionFatalException::class);
424
+ self ::expectExceptionMessage (
425
+ sprintf (KafkaProducerTransactionFatalException::FATAL_TRANSACTION_EXCEPTION_MESSAGE , '' )
426
+ );
418
427
419
428
$ errorMock = $ this ->createMock (RdKafkaErrorException::class);
420
429
$ errorMock ->expects (self ::once ())->method ('isRetriable ' )->willReturn (false );
@@ -439,6 +448,9 @@ public function testBeginTransactionWithFatalErrorWillTriggerInit(): void
439
448
$ firstExceptionCaught = false ;
440
449
441
450
self ::expectException (KafkaProducerTransactionFatalException::class);
451
+ self ::expectExceptionMessage (
452
+ sprintf (KafkaProducerTransactionFatalException::FATAL_TRANSACTION_EXCEPTION_MESSAGE , '' )
453
+ );
442
454
443
455
$ errorMock = $ this ->createMock (RdKafkaErrorException::class);
444
456
$ errorMock ->expects (self ::exactly (2 ))->method ('isRetriable ' )->willReturn (false );
@@ -481,7 +493,9 @@ public function testAbortTransactionSuccess(): void
481
493
public function testAbortTransactionFailure (): void
482
494
{
483
495
self ::expectException (KafkaProducerTransactionRetryException::class);
484
- self ::expectExceptionMessage (KafkaProducerTransactionRetryException::RETRIABLE_TRANSACTION_EXCEPTION_MESSAGE );
496
+ self ::expectExceptionMessage (
497
+ sprintf (KafkaProducerTransactionRetryException::RETRIABLE_TRANSACTION_EXCEPTION_MESSAGE , 'test ' )
498
+ );
485
499
486
500
$ exception = new RdKafkaErrorException ('test ' , 1 , 'some failure ' , false , true , false );
487
501
@@ -513,7 +527,9 @@ public function testCommitTransactionSuccess(): void
513
527
public function testCommitTransactionFailure (): void
514
528
{
515
529
self ::expectException (KafkaProducerTransactionRetryException::class);
516
- self ::expectExceptionMessage (KafkaProducerTransactionRetryException::RETRIABLE_TRANSACTION_EXCEPTION_MESSAGE );
530
+ self ::expectExceptionMessage (
531
+ sprintf (KafkaProducerTransactionRetryException::RETRIABLE_TRANSACTION_EXCEPTION_MESSAGE , 'test ' )
532
+ );
517
533
518
534
$ exception = new RdKafkaErrorException ('test ' , 1 , 'some failure ' , false , true , false );
519
535
@@ -525,4 +541,24 @@ public function testCommitTransactionFailure(): void
525
541
526
542
$ this ->kafkaProducer ->commitTransaction (10000 );
527
543
}
544
+
545
+ /**
546
+ * @return void
547
+ */
548
+ public function testCommitTransactionFailurePreviousException (): void
549
+ {
550
+ $ exception = new RdKafkaErrorException ('test ' , 1 , 'some failure ' , false , true , false );
551
+
552
+ $ this ->rdKafkaProducerMock
553
+ ->expects (self ::once ())
554
+ ->method ('commitTransaction ' )
555
+ ->with (10000 )
556
+ ->willThrowException ($ exception );
557
+
558
+ try {
559
+ $ this ->kafkaProducer ->commitTransaction (10000 );
560
+ } catch (KafkaProducerTransactionRetryException $ e ) {
561
+ self ::assertSame ($ exception , $ e ->getPrevious ());
562
+ }
563
+ }
528
564
}
0 commit comments