jolshan commented on code in PR #15685:
URL: https://github.com/apache/kafka/pull/15685#discussion_r1618018029
##########
server-common/src/test/java/org/apache/kafka/server/common/FeaturesTest.java:
##########
@@ -14,37 +14,86 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.kafka.server.common;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
import java.util.Collections;
-import static org.apache.kafka.server.common.MetadataVersion.FEATURE_NAME;
-import static
org.apache.kafka.server.common.MetadataVersion.MINIMUM_KRAFT_VERSION;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-class FeaturesTest {
- @Test
- public void testKRaftModeFeatures() {
- Features features = new Features(MINIMUM_KRAFT_VERSION,
- Collections.singletonMap("foo", (short) 2), 123, true);
- assertEquals(MINIMUM_KRAFT_VERSION.featureLevel(),
- features.finalizedFeatures().get(FEATURE_NAME));
- assertEquals((short) 2,
- features.finalizedFeatures().get("foo"));
- assertEquals(2, features.finalizedFeatures().size());
+public class FeaturesTest {
+
+ @ParameterizedTest
+ @EnumSource(Features.class)
+ public void testFromFeatureLevelAllFeatures(Features feature) {
+ FeatureVersion[] featureImplementations = feature.featureVersions();
+ int numFeatures = featureImplementations.length;
+ for (short i = 1; i < numFeatures; i++) {
+ assertEquals(featureImplementations[i - 1],
feature.fromFeatureLevel(i));
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(Features.class)
+ public void testValidateVersionAllFeatures(Features feature) {
+ for (FeatureVersion featureImpl : feature.featureVersions()) {
+ // Ensure that the feature is valid given the typical
metadataVersionMapping and the dependencies.
+ // Note: Other metadata versions are valid, but this one should
always be valid.
+ Features.validateVersion(featureImpl,
featureImpl.bootstrapMetadataVersion(), featureImpl.dependencies());
+ }
}
@Test
- public void testZkModeFeatures() {
- Features features = new Features(MINIMUM_KRAFT_VERSION,
- Collections.singletonMap("foo", (short) 2), 123, false);
- assertNull(features.finalizedFeatures().get(FEATURE_NAME));
- assertEquals((short) 2,
- features.finalizedFeatures().get("foo"));
- assertEquals(1, features.finalizedFeatures().size());
+ public void testInvalidValidateVersion() {
+ // Using too low of a MetadataVersion is invalid
+ assertThrows(IllegalArgumentException.class,
+ () -> Features.validateVersion(
+ TestFeatureVersion.TEST_1,
+ MetadataVersion.IBP_2_8_IV0,
+ Collections.emptyMap()
+ )
+ );
+
+ // Using a version that is lower than the dependency will fail.
+ assertThrows(IllegalArgumentException.class,
+ () -> Features.validateVersion(
+ TestFeatureVersion.TEST_2,
+ MetadataVersion.MINIMUM_BOOTSTRAP_VERSION,
Review Comment:
I thought it would be easier, but I see there is room for mistakes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]