Skip to content
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

Merged
merged 1 commit into from May 13, 2024

Conversation

FrankYang0529
Copy link
Member

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

  1. That is more readable for "ALL type".
  2. We don't throw the awkward "exception" when seeing "DEFAULT".

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

Copy link
Contributor

@chia7712 chia7712 left a 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() {
Copy link
Contributor

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) {
Copy link
Contributor

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)))
Copy link
Contributor

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)))
Copy link
Contributor

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),
Copy link
Contributor

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),
    })

Copy link
Contributor

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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@FrankYang0529
Copy link
Member Author

Hi @chia7712, I change List<Type> to Set<Type>.

For merging ClusterTest in MetadataQuorumCommandTest.java. I think it can't work, because cluster.config().clusterTypes().contains(Type.CO_KRAFT) will be true for all cases. We may need a new attribute in ClusterInstance, so we can know whether the cluster is CO_KRAFT or KRAFT.

@chia7712
Copy link
Contributor

chia7712 commented May 9, 2024

We may need a new attribute in ClusterInstance, so we can know whether the cluster is CO_KRAFT or KRAFT.

you are right.

public Builder setType(Type type) {
this.type = type;
public Builder setTypes(Set<Type> types) {
this.types = Collections.unmodifiableSet(new HashSet<>(types));
Copy link
Contributor

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)?

Copy link
Contributor

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 {};
Copy link
Contributor

@lianetm lianetm May 9, 2024

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?

Copy link
Contributor

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!

Copy link
Contributor

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 :)

Copy link
Member Author

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.

Copy link
Contributor

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

@lianetm
Copy link
Contributor

lianetm commented May 9, 2024

Thanks for the patch @FrankYang0529, nice twist. Left some comments. Also there are examples for the ClusterTest annotation in the core README file so it should be updated too to reflect the changes.

Copy link
Contributor

@chia7712 chia7712 left a 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()
Copy link
Contributor

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) {
Copy link
Contributor

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()
Copy link
Contributor

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))
Copy link
Contributor

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};
Copy link
Contributor

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")
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove it

@chia7712
Copy link
Contributor

@FrankYang0529 Could you please rebase code to trigger QA again?

@FrankYang0529
Copy link
Member Author

@FrankYang0529 Could you please rebase code to trigger QA again?

Yes, rebased it. Thanks.

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chia7712 chia7712 merged commit 334d5d5 into apache:trunk May 13, 2024
1 check failed
@FrankYang0529 FrankYang0529 deleted the KAFKA-16677 branch May 13, 2024 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants