New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KAFKA-16677: Replace ClusterType#ALL and ClusterType#DEFAULT by Array #15897
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FrankYang0529 nice patch!
@@ -85,8 +86,8 @@ private ClusterConfig(Type type, int brokers, int controllers, int disksPerBroke | |||
this.perBrokerOverrideProperties = Objects.requireNonNull(perBrokerOverrideProperties); | |||
} | |||
|
|||
public Type clusterType() { | |||
return type; | |||
public List<Type> clusterTypes() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set
is better since we don't want to run duplicate clusters
@@ -219,8 +220,8 @@ public static class Builder { | |||
|
|||
private Builder() {} | |||
|
|||
public Builder setType(Type type) { | |||
this.type = type; | |||
public Builder setTypes(List<Type> types) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public Builder setTypes(Set<Type> types) {
this.types = Collections.unmodifiableSet(new HashSet<>(types));
return this;
}
@@ -73,7 +74,7 @@ public void testDescribeQuorumReplicationSuccessful() throws InterruptedExceptio | |||
); | |||
|
|||
List<String> outputs = stream(describeOutput.split("\n")).skip(1).collect(Collectors.toList()); | |||
if (cluster.config().clusterType() == Type.CO_KRAFT) | |||
if (cluster.config().clusterTypes().equals(Collections.singletonList(Type.CO_KRAFT))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cluster.config().clusterTypes().contains(Type.CO_KRAFT)
@@ -86,7 +87,7 @@ public void testDescribeQuorumReplicationSuccessful() throws InterruptedExceptio | |||
assertEquals(cluster.config().numControllers() - 1, outputs.stream().filter(o -> followerPattern.matcher(o).find()).count()); | |||
|
|||
Pattern observerPattern = Pattern.compile("\\d+\\s+\\d+\\s+\\d+\\s+[\\dmsago\\s]+-?[\\dmsago\\s]+Observer\\s*"); | |||
if (cluster.config().clusterType() == Type.CO_KRAFT) | |||
if (cluster.config().clusterTypes().equals(Collections.singletonList(Type.CO_KRAFT))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cluster.config().clusterTypes().contains(Type.CO_KRAFT)
@ClusterTest(clusterType = Type.KRAFT, brokers = 2, controllers = 1), | ||
@ClusterTest(clusterType = Type.CO_KRAFT, brokers = 1, controllers = 2), | ||
@ClusterTest(clusterType = Type.KRAFT, brokers = 1, controllers = 2) | ||
@ClusterTest(clusterTypes = {Type.CO_KRAFT}, brokers = 2, controllers = 2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ClusterTests({
@ClusterTest(clusterTypes = {Type.CO_KRAFT, Type.KRAFT}, brokers = 2, controllers = 2),
@ClusterTest(clusterTypes = {Type.CO_KRAFT, Type.KRAFT}, brokers = 2, controllers = 1),
@ClusterTest(clusterTypes = {Type.CO_KRAFT, Type.KRAFT}, brokers = 1, controllers = 2),
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address this comment
@ClusterTest(clusterType = Type.KRAFT, brokers = 2, controllers = 1), | ||
@ClusterTest(clusterType = Type.CO_KRAFT, brokers = 1, controllers = 2), | ||
@ClusterTest(clusterType = Type.KRAFT, brokers = 1, controllers = 2) | ||
@ClusterTest(clusterTypes = {Type.CO_KRAFT}, brokers = 2, controllers = 2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Hi @chia7712, I change For merging |
you are right. |
public Builder setType(Type type) { | ||
this.type = type; | ||
public Builder setTypes(Set<Type> types) { | ||
this.types = Collections.unmodifiableSet(new HashSet<>(types)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collections.unmodifiableSet
will create a new object from the provided argument, so why creating a new HashSet
and not simply Collections.unmodifiableSet(types)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so why creating a new HashSet and not simply Collections.unmodifiableSet(types)?
We are trying to make ClusterConfig
immutable. Without copy, users is able to changes the ClusterConfig
's types
by modifying the input types
. We can simplify the code by Set.copy
after removing the support of JDK8
@@ -33,7 +33,7 @@ | |||
@Retention(RUNTIME) | |||
@TestTemplate | |||
public @interface ClusterTest { | |||
Type clusterType() default Type.DEFAULT; | |||
Type[] clusterTypes() default {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this bit is the one I'm still going around. I totally like the direction of the PR, removing the type ALL and DEFAULT , but then it brings the need to specify the full list of cluster types on every test that needs them all, so wonder if having the full list as default here would be a good complementary change?
It would mean that we have well defined ClusterTypes
as introduced by this PR, but every test running on ClusterTest
would run for all types, unless specified. That removes lots of clusterTypes = {Type.ZK, Type.KRAFT, Type.CO_KRAFT}
, it's probably the default behaviour we want for a test so that no ones accidentally forgets to run on any specific cluster type, and makes it easier to maintain (keeping the full list only in this single place, not on every test). Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so wonder if having the full list as default here would be a good complementary change?
It would mean that we have well defined ClusterTypes as introduced by this PR, but every test running on ClusterTest would run for all types, unless specified. That removes lots of clusterTypes = {Type.ZK, Type.KRAFT, Type.CO_KRAFT}, it's probably the default behaviour we want for a test so that no ones accidentally forgets to run on any specific cluster type, and makes it easier to maintain (keeping the full list only in this single place, not on every test). Thoughts?
I love this idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I assumed we are talking about default value of ClusterTestDefaults
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lianetm, thanks for your review and suggestion. I agree we should use all types by default, but it should be in ClusterTestDefaults
. The reason is that we will use whether ClusterTest#clusterTypes
is empty to determine using ClusterTest
or ClusterTestDefaults
. If ClusterTest#clusterTypes
is not empty by default, users may need to specify clusterTypes={}
to use ClusterTestDefaults
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClusterTestDefaults
makes sense to me. Honestly I wasn't thinking of it when suggesting having a default with all the types, simply because I didn't remember we had it. My point was more about having a default with all types, agree with you that the right place for that default should be ClusterTestDefaults
Thanks for the patch @FrankYang0529, nice twist. Left some comments. Also there are examples for the |
4009c0d
to
bb63b99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FrankYang0529 thanks for updated PR. I leave many comments to decorate this PR. PTAL
@@ -44,7 +43,7 @@ | |||
|
|||
@SuppressWarnings("dontUseSystemExit") | |||
@ExtendWith(value = ClusterTestExtensions.class) | |||
@ClusterTestDefaults(clusterType = Type.ALL) | |||
@ClusterTestDefaults() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant if you don't define any values
@@ -34,7 +34,7 @@ import org.junit.jupiter.api.extension.ExtendWith | |||
class ApiVersionsRequestTest(cluster: ClusterInstance) extends AbstractApiVersionsRequestTest(cluster) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test has redundant ClusterTestDefaults
as the changed value is equal to default value.
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith | |||
|
|||
import scala.jdk.CollectionConverters._ | |||
|
|||
@ClusterTestDefaults(clusterType = Type.ALL) | |||
@ClusterTestDefaults() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -164,7 +166,7 @@ public Map<String, String> nameTags() { | |||
|
|||
public static Builder defaultBuilder() { | |||
return new Builder() | |||
.setType(Type.ZK) | |||
.setTypes(Collections.singleton(Type.ZK)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to align the default value with ClusterTestDefaults
, right?
@@ -35,7 +35,7 @@ | |||
@Target({TYPE}) | |||
@Retention(RUNTIME) | |||
public @interface ClusterTestDefaults { | |||
Type clusterType() default Type.ZK; | |||
Type[] clusterTypes() default {Type.ZK, Type.KRAFT, Type.CO_KRAFT}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should be renamed to types
instead of clusterTypes
. We do have a ClusterType
in testing :)
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.extension.ExtendWith | |||
|
|||
@Timeout(120) | |||
@ExtendWith(value = Array(classOf[ClusterTestExtensions])) | |||
@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) | |||
@ClusterTestDefaults(clusterTypes = Array(Type.KRAFT), brokers = 1) | |||
@Tag("integration") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove brokers = 1
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.extension.ExtendWith | |||
|
|||
@Timeout(120) | |||
@ExtendWith(value = Array(classOf[ClusterTestExtensions])) | |||
@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) | |||
@ClusterTestDefaults(clusterTypes = Array(Type.KRAFT), brokers = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove brokers = 1
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.extension.ExtendWith | |||
|
|||
@Timeout(120) | |||
@ExtendWith(value = Array(classOf[ClusterTestExtensions])) | |||
@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) | |||
@ClusterTestDefaults(clusterTypes = Array(Type.KRAFT), brokers = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove brokers = 1
@@ -34,7 +34,7 @@ import scala.jdk.CollectionConverters._ | |||
|
|||
@Timeout(120) | |||
@ExtendWith(value = Array(classOf[ClusterTestExtensions])) | |||
@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) | |||
@ClusterTestDefaults(clusterTypes = Array(Type.KRAFT), brokers = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove brokers = 1
@@ -36,7 +36,7 @@ import org.junit.jupiter.api.extension.ExtendWith | |||
|
|||
import scala.jdk.CollectionConverters._ | |||
|
|||
@ClusterTestDefaults(clusterType = Type.ALL) | |||
@ClusterTestDefaults() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove it
bb63b99
to
6ee0084
Compare
@FrankYang0529 Could you please rebase code to trigger QA again? |
Signed-off-by: PoAn Yang <payang@apache.org>
6ee0084
to
1f24464
Compare
Yes, rebased it. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Both ClusterType#ALL and ClusterType#DEFAULT are a kind of "tag" instead of true "type". It seems to me they can be removed by using Array. For example:
ClusterType#ALL -> {Type.ZK, Type.KRAFT, Type.CO_KRAFT}
ClusterType#DEFAULT -> {}
There are two benefits
Committer Checklist (excluded from commit message)