From 49efb2031d51e0eb9c2187e5e1d3948c8a92af7d Mon Sep 17 00:00:00 2001 From: Swaminathan Balachandran Date: Wed, 18 Dec 2024 21:33:47 -0800 Subject: [PATCH 1/4] HDDS-11963. Unify client version and layout version under one interface to accomodate in the request validator framework Change-Id: I4c1844a1dfb6127a73b46a92933db33b09c6b06e --- .../apache/hadoop/hdds/ComponentVersion.java | 9 ++- .../apache/hadoop/ozone/ClientVersion.java | 5 +- .../java/org/apache/hadoop/ozone/Version.java | 26 ++++++++ .../hadoop/ozone/upgrade/LayoutFeature.java | 9 ++- .../request/validation/VersionExtractor.java | 63 +++++++++++++++++++ .../validation/TestVersionExtractor.java | 58 +++++++++++++++++ 6 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Version.java create mode 100644 hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/VersionExtractor.java create mode 100644 hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ComponentVersion.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ComponentVersion.java index 9545869e163..a86d07fa586 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ComponentVersion.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ComponentVersion.java @@ -17,10 +17,12 @@ */ package org.apache.hadoop.hdds; +import org.apache.hadoop.ozone.Version; + /** * Base type for component version enums. */ -public interface ComponentVersion { +public interface ComponentVersion extends Version { /** * Returns the description of the version enum value. @@ -34,4 +36,9 @@ public interface ComponentVersion { * @return the version associated with the enum value. */ int toProtoValue(); + + @Override + default int version() { + return toProtoValue(); + } } diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/ClientVersion.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/ClientVersion.java index cc6695dc7d6..08e29356343 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/ClientVersion.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/ClientVersion.java @@ -20,6 +20,7 @@ import org.apache.hadoop.hdds.ComponentVersion; import java.util.Arrays; +import java.util.Comparator; import java.util.Map; import static java.util.function.Function.identity; @@ -75,8 +76,8 @@ public static ClientVersion fromProtoValue(int value) { } private static ClientVersion latest() { - ClientVersion[] versions = ClientVersion.values(); - return versions[versions.length - 2]; + return Arrays.stream(ClientVersion.values()) + .max(Comparator.comparingInt(ComponentVersion::toProtoValue)).orElse(null); } } diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Version.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Version.java new file mode 100644 index 00000000000..b6dc636e248 --- /dev/null +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Version.java @@ -0,0 +1,26 @@ +/* + * 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.hadoop.ozone; + + +/** + * Base class defining the version in the entire system. + */ +public interface Version { + int version(); +} diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutFeature.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutFeature.java index 92dd706f4bb..93c5ef0a0b7 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutFeature.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutFeature.java @@ -18,12 +18,14 @@ package org.apache.hadoop.ozone.upgrade; +import org.apache.hadoop.ozone.Version; + import java.util.Optional; /** * Generic Layout feature interface for Ozone. */ -public interface LayoutFeature { +public interface LayoutFeature extends Version { String name(); int layoutVersion(); @@ -48,6 +50,11 @@ default String name() { void execute(T arg) throws Exception; } + @Override + default int version() { + return this.layoutVersion(); + } + /** * Phase of execution for this action. */ diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/VersionExtractor.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/VersionExtractor.java new file mode 100644 index 00000000000..94f833be456 --- /dev/null +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/VersionExtractor.java @@ -0,0 +1,63 @@ +/* + * 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.hadoop.ozone.om.request.validation; + +import org.apache.hadoop.ozone.ClientVersion; +import org.apache.hadoop.ozone.Version; +import org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature; +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; +import org.apache.hadoop.ozone.upgrade.LayoutVersionManager; + +/** + * Class to extract version out of OM request. + */ +public enum VersionExtractor { + /** + * Extracts current metadata layout version. + */ + LAYOUT_VERSION_EXTRACTOR { + @Override + public Version extractVersion(OMRequest req, ValidationContext ctx) { + LayoutVersionManager layoutVersionManager = ctx.versionManager(); + return ctx.versionManager().getFeature(layoutVersionManager.getMetadataLayoutVersion()); + } + + @Override + public Class getVersionClass() { + return OMLayoutFeature.class; + } + }, + + /** + * Extracts client version from the OMRequests. + */ + CLIENT_VERSION_EXTRACTOR { + @Override + public Version extractVersion(OMRequest req, ValidationContext ctx) { + return req.getVersion() > ClientVersion.CURRENT_VERSION ? + ClientVersion.FUTURE_VERSION : ClientVersion.fromProtoValue(req.getVersion()); + } + + @Override + public Class getVersionClass() { + return ClientVersion.class; + } + }; + + public abstract Version extractVersion(OMRequest req, ValidationContext ctx); + public abstract Class getVersionClass(); +} diff --git a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java new file mode 100644 index 00000000000..832cb751fd1 --- /dev/null +++ b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java @@ -0,0 +1,58 @@ +package org.apache.hadoop.ozone.om.request.validation; + +import org.apache.hadoop.ozone.ClientVersion; +import org.apache.hadoop.ozone.Version; +import org.apache.hadoop.ozone.om.exceptions.OMException; +import org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature; +import org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager; +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; +import org.apache.hadoop.ozone.upgrade.LayoutVersionManager; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.Arrays; +import java.util.function.Function; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class TestVersionExtractor { + + private static Stream layoutValues() { + return Arrays.stream(OMLayoutFeature.values()).map(Arguments::of); + } + + private static Stream clientVersionValues() { + return Stream.of( + Arrays.stream(ClientVersion.values()) + .map(clientVersion -> Arguments.of(clientVersion, clientVersion.version())), + IntStream.range(1, 10) + .mapToObj(delta -> Arguments.of(ClientVersion.FUTURE_VERSION, ClientVersion.CURRENT_VERSION + delta)) + ).flatMap(Function.identity()); + } + + @ParameterizedTest + @MethodSource("layoutValues") + void testLayoutVersionExtractor(OMLayoutFeature layoutVersionValue) throws OMException { + ValidationContext context = mock(ValidationContext.class); + LayoutVersionManager layoutVersionManager = new OMLayoutVersionManager(layoutVersionValue.version()); + when(context.versionManager()).thenReturn(layoutVersionManager); + Version version = VersionExtractor.LAYOUT_VERSION_EXTRACTOR.extractVersion(null, context); + assertEquals(layoutVersionValue, version); + assertEquals(OMLayoutFeature.class, VersionExtractor.LAYOUT_VERSION_EXTRACTOR.getVersionClass()); + } + + @ParameterizedTest + @MethodSource("clientVersionValues") + void testClientVersionExtractor(ClientVersion expectedClientVersion, int clientVersion) { + OMRequest request = mock(OMRequest.class); + when(request.getVersion()).thenReturn(clientVersion); + Version version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null); + assertEquals(expectedClientVersion, version); + assertEquals(ClientVersion.class, VersionExtractor.CLIENT_VERSION_EXTRACTOR.getVersionClass()); + } +} From b819b63bb7bae3eaa20304c8f247475692a71e4c Mon Sep 17 00:00:00 2001 From: Swaminathan Balachandran Date: Wed, 18 Dec 2024 21:38:04 -0800 Subject: [PATCH 2/4] HDDS-11963. Fix rat failure Change-Id: I63cddb955ea6178cd489c2a83922576e8d2ea5eb --- .../request/validation/TestVersionExtractor.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java index 832cb751fd1..0a2344840cf 100644 --- a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java +++ b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java @@ -1,3 +1,19 @@ +/* + * 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.hadoop.ozone.om.request.validation; import org.apache.hadoop.ozone.ClientVersion; From bfa7618271d151611ce9214bceb4b4b1c57e6533 Mon Sep 17 00:00:00 2001 From: Swaminathan Balachandran Date: Wed, 18 Dec 2024 22:25:10 -0800 Subject: [PATCH 3/4] HDDS-11963. Address review comments Change-Id: I11bff280f429d2eb64f8828887f7349e169e938f --- .../apache/hadoop/hdds/ComponentVersion.java | 4 +- .../ozone/{Version.java => Versioned.java} | 2 +- .../hadoop/ozone/upgrade/LayoutFeature.java | 4 +- .../request/validation/VersionExtractor.java | 10 ++--- .../validation/TestVersionExtractor.java | 40 +++++++++---------- 5 files changed, 30 insertions(+), 30 deletions(-) rename hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/{Version.java => Versioned.java} (96%) diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ComponentVersion.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ComponentVersion.java index a86d07fa586..7f65010e2c0 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ComponentVersion.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ComponentVersion.java @@ -17,12 +17,12 @@ */ package org.apache.hadoop.hdds; -import org.apache.hadoop.ozone.Version; +import org.apache.hadoop.ozone.Versioned; /** * Base type for component version enums. */ -public interface ComponentVersion extends Version { +public interface ComponentVersion extends Versioned { /** * Returns the description of the version enum value. diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Version.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Versioned.java similarity index 96% rename from hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Version.java rename to hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Versioned.java index b6dc636e248..7f89b403b34 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Version.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/Versioned.java @@ -21,6 +21,6 @@ /** * Base class defining the version in the entire system. */ -public interface Version { +public interface Versioned { int version(); } diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutFeature.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutFeature.java index 93c5ef0a0b7..9ec9b4cb589 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutFeature.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutFeature.java @@ -18,14 +18,14 @@ package org.apache.hadoop.ozone.upgrade; -import org.apache.hadoop.ozone.Version; +import org.apache.hadoop.ozone.Versioned; import java.util.Optional; /** * Generic Layout feature interface for Ozone. */ -public interface LayoutFeature extends Version { +public interface LayoutFeature extends Versioned { String name(); int layoutVersion(); diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/VersionExtractor.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/VersionExtractor.java index 94f833be456..e7acef45bfe 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/VersionExtractor.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/VersionExtractor.java @@ -17,7 +17,7 @@ package org.apache.hadoop.ozone.om.request.validation; import org.apache.hadoop.ozone.ClientVersion; -import org.apache.hadoop.ozone.Version; +import org.apache.hadoop.ozone.Versioned; import org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature; import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; import org.apache.hadoop.ozone.upgrade.LayoutVersionManager; @@ -31,7 +31,7 @@ public enum VersionExtractor { */ LAYOUT_VERSION_EXTRACTOR { @Override - public Version extractVersion(OMRequest req, ValidationContext ctx) { + public Versioned extractVersion(OMRequest req, ValidationContext ctx) { LayoutVersionManager layoutVersionManager = ctx.versionManager(); return ctx.versionManager().getFeature(layoutVersionManager.getMetadataLayoutVersion()); } @@ -47,7 +47,7 @@ public Class getVersionClass() { */ CLIENT_VERSION_EXTRACTOR { @Override - public Version extractVersion(OMRequest req, ValidationContext ctx) { + public Versioned extractVersion(OMRequest req, ValidationContext ctx) { return req.getVersion() > ClientVersion.CURRENT_VERSION ? ClientVersion.FUTURE_VERSION : ClientVersion.fromProtoValue(req.getVersion()); } @@ -58,6 +58,6 @@ public Class getVersionClass() { } }; - public abstract Version extractVersion(OMRequest req, ValidationContext ctx); - public abstract Class getVersionClass(); + public abstract Versioned extractVersion(OMRequest req, ValidationContext ctx); + public abstract Class getVersionClass(); } diff --git a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java index 0a2344840cf..c1eaf3b7c21 100644 --- a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java +++ b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java @@ -17,7 +17,7 @@ package org.apache.hadoop.ozone.om.request.validation; import org.apache.hadoop.ozone.ClientVersion; -import org.apache.hadoop.ozone.Version; +import org.apache.hadoop.ozone.Versioned; import org.apache.hadoop.ozone.om.exceptions.OMException; import org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature; import org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager; @@ -25,10 +25,9 @@ import org.apache.hadoop.ozone.upgrade.LayoutVersionManager; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.MethodSource; -import java.util.Arrays; -import java.util.function.Function; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -38,37 +37,38 @@ class TestVersionExtractor { - private static Stream layoutValues() { - return Arrays.stream(OMLayoutFeature.values()).map(Arguments::of); - } - - private static Stream clientVersionValues() { - return Stream.of( - Arrays.stream(ClientVersion.values()) - .map(clientVersion -> Arguments.of(clientVersion, clientVersion.version())), - IntStream.range(1, 10) - .mapToObj(delta -> Arguments.of(ClientVersion.FUTURE_VERSION, ClientVersion.CURRENT_VERSION + delta)) - ).flatMap(Function.identity()); + private static Stream futureClientVersionValues() { + return IntStream.range(1, 10).mapToObj(delta -> Arguments.of(ClientVersion.CURRENT_VERSION + delta)); } @ParameterizedTest - @MethodSource("layoutValues") + @EnumSource(OMLayoutFeature.class) void testLayoutVersionExtractor(OMLayoutFeature layoutVersionValue) throws OMException { ValidationContext context = mock(ValidationContext.class); LayoutVersionManager layoutVersionManager = new OMLayoutVersionManager(layoutVersionValue.version()); when(context.versionManager()).thenReturn(layoutVersionManager); - Version version = VersionExtractor.LAYOUT_VERSION_EXTRACTOR.extractVersion(null, context); + Versioned version = VersionExtractor.LAYOUT_VERSION_EXTRACTOR.extractVersion(null, context); assertEquals(layoutVersionValue, version); assertEquals(OMLayoutFeature.class, VersionExtractor.LAYOUT_VERSION_EXTRACTOR.getVersionClass()); } @ParameterizedTest - @MethodSource("clientVersionValues") - void testClientVersionExtractor(ClientVersion expectedClientVersion, int clientVersion) { + @EnumSource(ClientVersion.class) + void testClientVersionExtractor(ClientVersion expectedClientVersion) { OMRequest request = mock(OMRequest.class); - when(request.getVersion()).thenReturn(clientVersion); - Version version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null); + when(request.getVersion()).thenReturn(expectedClientVersion.version()); + Versioned version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null); assertEquals(expectedClientVersion, version); assertEquals(ClientVersion.class, VersionExtractor.CLIENT_VERSION_EXTRACTOR.getVersionClass()); } + + @ParameterizedTest + @MethodSource("futureClientVersionValues") + void testClientVersionExtractorForFutureValues(int clientVersion) { + OMRequest request = mock(OMRequest.class); + when(request.getVersion()).thenReturn(clientVersion); + Versioned version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null); + assertEquals(ClientVersion.FUTURE_VERSION, version); + assertEquals(ClientVersion.class, VersionExtractor.CLIENT_VERSION_EXTRACTOR.getVersionClass()); + } } From ded3450ade16e1414047b81e305cc39f85f56d83 Mon Sep 17 00:00:00 2001 From: Swaminathan Balachandran Date: Wed, 18 Dec 2024 22:27:46 -0800 Subject: [PATCH 4/4] HDDS-11963. Address review comments Change-Id: I9ebc447eb9b60caa69e140b06fe899c58dd712a3 --- .../request/validation/TestVersionExtractor.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java index c1eaf3b7c21..a3c9c76e70f 100644 --- a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java +++ b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java @@ -24,12 +24,8 @@ import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; import org.apache.hadoop.ozone.upgrade.LayoutVersionManager; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.stream.IntStream; -import java.util.stream.Stream; +import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; @@ -37,10 +33,6 @@ class TestVersionExtractor { - private static Stream futureClientVersionValues() { - return IntStream.range(1, 10).mapToObj(delta -> Arguments.of(ClientVersion.CURRENT_VERSION + delta)); - } - @ParameterizedTest @EnumSource(OMLayoutFeature.class) void testLayoutVersionExtractor(OMLayoutFeature layoutVersionValue) throws OMException { @@ -63,10 +55,10 @@ void testClientVersionExtractor(ClientVersion expectedClientVersion) { } @ParameterizedTest - @MethodSource("futureClientVersionValues") - void testClientVersionExtractorForFutureValues(int clientVersion) { + @ValueSource(ints = {1, 2, 5, 10, 1000, 10000}) + void testClientVersionExtractorForFutureValues(int futureVersion) { OMRequest request = mock(OMRequest.class); - when(request.getVersion()).thenReturn(clientVersion); + when(request.getVersion()).thenReturn(ClientVersion.CURRENT_VERSION + futureVersion); Versioned version = VersionExtractor.CLIENT_VERSION_EXTRACTOR.extractVersion(request, null); assertEquals(ClientVersion.FUTURE_VERSION, version); assertEquals(ClientVersion.class, VersionExtractor.CLIENT_VERSION_EXTRACTOR.getVersionClass());