From d77f44414d1ae33d905335aeff11ba3eaad69a5a Mon Sep 17 00:00:00 2001 From: Kaushik Raina <103954755+k-raina@users.noreply.github.com> Date: Thu, 27 Feb 2025 21:19:13 +0530 Subject: [PATCH] KAFKA-18780: Extend RetriableException related exceptions (#19020) - Added a unit test to validate the exception hierarchy for all KIP-1050 transaction related exceptions. - RetriableException is correctly extended by all child classes - Included test for RetriableException exception with verification that all exceptions extending `RetriableException` do not inadvertently extend `RefreshRetriableException, preserving the intended behavior. Reviewers: Kirk True , TaiJuWu , TengYao Chi , Ken Huang , Justine Olshan --- .../TransactionExceptionHierarchyTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 clients/src/test/java/org/apache/kafka/common/errors/TransactionExceptionHierarchyTest.java diff --git a/clients/src/test/java/org/apache/kafka/common/errors/TransactionExceptionHierarchyTest.java b/clients/src/test/java/org/apache/kafka/common/errors/TransactionExceptionHierarchyTest.java new file mode 100644 index 00000000000..64cd0167845 --- /dev/null +++ b/clients/src/test/java/org/apache/kafka/common/errors/TransactionExceptionHierarchyTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.common.errors; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class TransactionExceptionHierarchyTest { + + /** + * Verifies that the given exception class extends `RetriableException` + * and does **not** extend `RefreshRetriableException`. + * + * Using `RefreshRetriableException` changes the exception handling behavior, + * so only exceptions extending `RetriableException` directly are considered valid here. + * + * @param exceptionClass the exception class to check + */ + @ParameterizedTest + @ValueSource(classes = { + TimeoutException.class, + NotEnoughReplicasException.class, + CoordinatorLoadInProgressException.class, + CorruptRecordException.class, + NotEnoughReplicasAfterAppendException.class, + ConcurrentTransactionsException.class + }) + void testRetriableExceptionHierarchy(Class exceptionClass) { + assertTrue(RetriableException.class.isAssignableFrom(exceptionClass), + exceptionClass.getSimpleName() + " should extend RetriableException"); + assertFalse(RefreshRetriableException.class.isAssignableFrom(exceptionClass), + exceptionClass.getSimpleName() + " should NOT extend RefreshRetriableException"); + } +}