@@ -3799,14 +3799,12 @@ MAX_REQUEST_SIZE, ACKS_ALL, MAX_RETRIES, new SenderMetricsRegistry(new Metrics(t
3799
3799
3800
3800
@ Test
3801
3801
public void testBackgroundInvalidStateTransitionIsFatal () {
3802
- // The default logic is to poison the transaction manager on an invalid state transition attempt if that
3803
- // attempt happens on the Sender thread. Here the logic is altered to always poison on invalid attempts to
3804
- // mimic as though it's being invoked by the Sender.
3805
3802
initializeTransactionManager (Optional .of (transactionalId ), true );
3806
- transactionManager .setShouldSetToFatalErrorStateOverride (true );
3807
3803
doInitTransactions ();
3808
3804
assertTrue (transactionManager .isTransactional ());
3809
3805
3806
+ transactionManager .setShouldSetToFatalErrorStateOverride (true );
3807
+
3810
3808
// Intentionally perform an operation that will cause an invalid state transition. The detection of this
3811
3809
// will result in a poisoning of the transaction manager for all subsequent transactional operations since
3812
3810
// it was performed in the background.
@@ -4376,6 +4374,10 @@ private void runUntil(Supplier<Boolean> condition) {
4376
4374
ProducerTestUtils .runUntil (sender , condition );
4377
4375
}
4378
4376
4377
+ /**
4378
+ * This subclass exists only to optionally change the default behavior related to poisoning the state
4379
+ * on invalid state transition attempts.
4380
+ */
4379
4381
private static class TestableTransactionManager extends TransactionManager {
4380
4382
4381
4383
private Optional <Boolean > shouldPoisonStateOnInvalidTransitionOverride ;
@@ -4395,6 +4397,7 @@ private void setShouldSetToFatalErrorStateOverride(boolean override) {
4395
4397
4396
4398
@ Override
4397
4399
protected boolean shouldPoisonStateOnInvalidTransition () {
4400
+ // If there's an override, use it, otherwise invoke the default (i.e. super class) logic.
4398
4401
return shouldPoisonStateOnInvalidTransitionOverride .orElseGet (super ::shouldPoisonStateOnInvalidTransition );
4399
4402
}
4400
4403
}
0 commit comments