You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "dajac (via GitHub)" <gi...@apache.org> on 2025/04/19 14:12:19 UTC

[PR] MINOR: Extend @ApiKeyVersionsSource annotation [kafka]

dajac opened a new pull request, #19516:
URL: https://github.com/apache/kafka/pull/19516

   This patch extends the `@ApiKeyVersionsSource` annotation to allow specifying the `fromVersion` and the `toVersion`. This is pretty handy when we only want to test a subset of the versions.
   


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Extend @ApiKeyVersionsSource annotation [kafka]

Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on code in PR #19516:
URL: https://github.com/apache/kafka/pull/19516#discussion_r2051494673


##########
clients/src/test/java/org/apache/kafka/common/utils/annotation/ApiKeyVersionsProvider.java:
##########
@@ -23,16 +23,36 @@
 import org.junit.jupiter.params.provider.ArgumentsProvider;
 import org.junit.jupiter.params.support.AnnotationConsumer;
 
+import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 public class ApiKeyVersionsProvider implements ArgumentsProvider, AnnotationConsumer<ApiKeyVersionsSource> {
     private ApiKeys apiKey;
+    private short fromVersion;
+    private short toVersion;
 
     public void accept(ApiKeyVersionsSource source) {
         apiKey = source.apiKey();
+        fromVersion = source.fromVersion() == -1 ? apiKey.oldestVersion() : source.fromVersion();
+        toVersion = source.toVersion() == -1 ? apiKey.latestVersion(source.enableUnstableLastVersion()) : source.toVersion();
+
+        if (fromVersion > toVersion) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is larger than the toVersion %s",
+                fromVersion, toVersion));
+        }
+
+        if (fromVersion < apiKey.oldestVersion()) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is older than the oldest version %s",
+                fromVersion, apiKey.oldestVersion()));
+        }
+
+        if (toVersion < apiKey.latestVersion(source.enableUnstableLastVersion())) {

Review Comment:
   +1



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Extend @ApiKeyVersionsSource annotation [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #19516:
URL: https://github.com/apache/kafka/pull/19516#discussion_r2051729958


##########
clients/src/test/java/org/apache/kafka/common/utils/annotation/ApiKeyVersionsProvider.java:
##########
@@ -23,16 +23,40 @@
 import org.junit.jupiter.params.provider.ArgumentsProvider;
 import org.junit.jupiter.params.support.AnnotationConsumer;
 
+import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 public class ApiKeyVersionsProvider implements ArgumentsProvider, AnnotationConsumer<ApiKeyVersionsSource> {
     private ApiKeys apiKey;
+    private short fromVersion;
+    private short toVersion;
 
     public void accept(ApiKeyVersionsSource source) {
         apiKey = source.apiKey();
+
+        short oldestVersion = apiKey.oldestVersion();
+        short latestVersion = apiKey.latestVersion(source.enableUnstableLastVersion());
+
+        fromVersion = source.fromVersion() == -1 ? oldestVersion : source.fromVersion();
+        toVersion = source.toVersion() == -1 ? latestVersion : source.toVersion();
+
+        if (fromVersion > toVersion) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is larger than the toVersion %s",
+                fromVersion, toVersion));
+        }
+
+        if (fromVersion < oldestVersion) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is older than the oldest version %s",
+                fromVersion, oldestVersion));
+        }
+
+        if (toVersion > latestVersion) {
+            throw new IllegalArgumentException(String.format("The toVersion %s is newer than the latest version %s",
+                fromVersion, latestVersion));

Review Comment:
   nit: `fromVersion` -> `toVersion`



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Extend @ApiKeyVersionsSource annotation [kafka]

Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky merged PR #19516:
URL: https://github.com/apache/kafka/pull/19516


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Extend @ApiKeyVersionsSource annotation [kafka]

Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on code in PR #19516:
URL: https://github.com/apache/kafka/pull/19516#discussion_r2051494839


##########
clients/src/test/java/org/apache/kafka/common/utils/annotation/ApiKeyVersionsProvider.java:
##########
@@ -23,16 +23,36 @@
 import org.junit.jupiter.params.provider.ArgumentsProvider;
 import org.junit.jupiter.params.support.AnnotationConsumer;
 
+import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 public class ApiKeyVersionsProvider implements ArgumentsProvider, AnnotationConsumer<ApiKeyVersionsSource> {
     private ApiKeys apiKey;
+    private short fromVersion;
+    private short toVersion;
 
     public void accept(ApiKeyVersionsSource source) {
         apiKey = source.apiKey();
+        fromVersion = source.fromVersion() == -1 ? apiKey.oldestVersion() : source.fromVersion();
+        toVersion = source.toVersion() == -1 ? apiKey.latestVersion(source.enableUnstableLastVersion()) : source.toVersion();

Review Comment:
   nit: Could we extract `apiKey.latestVersion(source.enableUnstableLastVersion())` as a variable?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Extend @ApiKeyVersionsSource annotation [kafka]

Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on code in PR #19516:
URL: https://github.com/apache/kafka/pull/19516#discussion_r2051496075


##########
clients/src/test/java/org/apache/kafka/common/utils/annotation/ApiKeyVersionsProvider.java:
##########
@@ -23,16 +23,36 @@
 import org.junit.jupiter.params.provider.ArgumentsProvider;
 import org.junit.jupiter.params.support.AnnotationConsumer;
 
+import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 public class ApiKeyVersionsProvider implements ArgumentsProvider, AnnotationConsumer<ApiKeyVersionsSource> {
     private ApiKeys apiKey;
+    private short fromVersion;
+    private short toVersion;
 
     public void accept(ApiKeyVersionsSource source) {
         apiKey = source.apiKey();
+        fromVersion = source.fromVersion() == -1 ? apiKey.oldestVersion() : source.fromVersion();
+        toVersion = source.toVersion() == -1 ? apiKey.latestVersion(source.enableUnstableLastVersion()) : source.toVersion();
+
+        if (fromVersion > toVersion) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is larger than the toVersion %s",
+                fromVersion, toVersion));
+        }
+
+        if (fromVersion < apiKey.oldestVersion()) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is older than the oldest version %s",
+                fromVersion, apiKey.oldestVersion()));
+        }
+
+        if (toVersion < apiKey.latestVersion(source.enableUnstableLastVersion())) {

Review Comment:
   Since this enhancement introduces some logic, do we need to add some unit tests for it?
   We could add tests to this patch or create a Jira ticket to track this issue.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Extend @ApiKeyVersionsSource annotation [kafka]

Posted by "apalan60 (via GitHub)" <gi...@apache.org>.
apalan60 commented on code in PR #19516:
URL: https://github.com/apache/kafka/pull/19516#discussion_r2051734950


##########
clients/src/test/java/org/apache/kafka/common/utils/annotation/ApiKeyVersionsProvider.java:
##########
@@ -23,16 +23,40 @@
 import org.junit.jupiter.params.provider.ArgumentsProvider;
 import org.junit.jupiter.params.support.AnnotationConsumer;
 
+import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 public class ApiKeyVersionsProvider implements ArgumentsProvider, AnnotationConsumer<ApiKeyVersionsSource> {
     private ApiKeys apiKey;
+    private short fromVersion;
+    private short toVersion;
 
     public void accept(ApiKeyVersionsSource source) {
         apiKey = source.apiKey();
+
+        short oldestVersion = apiKey.oldestVersion();
+        short latestVersion = apiKey.latestVersion(source.enableUnstableLastVersion());
+
+        fromVersion = source.fromVersion() == -1 ? oldestVersion : source.fromVersion();
+        toVersion = source.toVersion() == -1 ? latestVersion : source.toVersion();
+
+        if (fromVersion > toVersion) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is larger than the toVersion %s",
+                fromVersion, toVersion));
+        }
+
+        if (fromVersion < oldestVersion) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is older than the oldest version %s",
+                fromVersion, oldestVersion));
+        }
+
+        if (toVersion > latestVersion) {
+            throw new IllegalArgumentException(String.format("The toVersion %s is newer than the latest version %s",
+                fromVersion, latestVersion));

Review Comment:
   I’ve just opened PR #19521 to fix this typo. PTAL, thanks!



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Extend @ApiKeyVersionsSource annotation [kafka]

Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #19516:
URL: https://github.com/apache/kafka/pull/19516#discussion_r2051507598


##########
clients/src/test/java/org/apache/kafka/common/utils/annotation/ApiKeyVersionsProvider.java:
##########
@@ -23,16 +23,36 @@
 import org.junit.jupiter.params.provider.ArgumentsProvider;
 import org.junit.jupiter.params.support.AnnotationConsumer;
 
+import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 public class ApiKeyVersionsProvider implements ArgumentsProvider, AnnotationConsumer<ApiKeyVersionsSource> {
     private ApiKeys apiKey;
+    private short fromVersion;
+    private short toVersion;
 
     public void accept(ApiKeyVersionsSource source) {
         apiKey = source.apiKey();
+        fromVersion = source.fromVersion() == -1 ? apiKey.oldestVersion() : source.fromVersion();
+        toVersion = source.toVersion() == -1 ? apiKey.latestVersion(source.enableUnstableLastVersion()) : source.toVersion();
+
+        if (fromVersion > toVersion) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is larger than the toVersion %s",
+                fromVersion, toVersion));
+        }
+
+        if (fromVersion < apiKey.oldestVersion()) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is older than the oldest version %s",
+                fromVersion, apiKey.oldestVersion()));
+        }
+
+        if (toVersion < apiKey.latestVersion(source.enableUnstableLastVersion())) {

Review Comment:
   Sorry, copy-pasting issue. Fixed it and added some tests.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Extend @ApiKeyVersionsSource annotation [kafka]

Posted by "brandboat (via GitHub)" <gi...@apache.org>.
brandboat commented on code in PR #19516:
URL: https://github.com/apache/kafka/pull/19516#discussion_r2051493735


##########
clients/src/test/java/org/apache/kafka/common/utils/annotation/ApiKeyVersionsProvider.java:
##########
@@ -23,16 +23,36 @@
 import org.junit.jupiter.params.provider.ArgumentsProvider;
 import org.junit.jupiter.params.support.AnnotationConsumer;
 
+import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 public class ApiKeyVersionsProvider implements ArgumentsProvider, AnnotationConsumer<ApiKeyVersionsSource> {
     private ApiKeys apiKey;
+    private short fromVersion;
+    private short toVersion;
 
     public void accept(ApiKeyVersionsSource source) {
         apiKey = source.apiKey();
+        fromVersion = source.fromVersion() == -1 ? apiKey.oldestVersion() : source.fromVersion();
+        toVersion = source.toVersion() == -1 ? apiKey.latestVersion(source.enableUnstableLastVersion()) : source.toVersion();
+
+        if (fromVersion > toVersion) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is larger than the toVersion %s",
+                fromVersion, toVersion));
+        }
+
+        if (fromVersion < apiKey.oldestVersion()) {
+            throw new IllegalArgumentException(String.format("The fromVersion %s is older than the oldest version %s",
+                fromVersion, apiKey.oldestVersion()));
+        }
+
+        if (toVersion < apiKey.latestVersion(source.enableUnstableLastVersion())) {

Review Comment:
   Pardon me, not sure if I misunderstand anything, but shouldn't this be `toVersion > apiKey.latestVersion(source.enableUnstableLastVersion())`? 



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org