chia7712 commented on code in PR #22247: URL: https://github.com/apache/kafka/pull/22247#discussion_r3215258117
########## metadata/src/testFixtures/java/org/apache/kafka/image/MetadataImageTestFixtures.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.kafka.image; + +import org.apache.kafka.metadata.RecordTestUtils; + +public final class MetadataImageTestFixtures { Review Comment: this name `MetadataCacheTestFixtures` is a sort of verbose. how about "MetadataCacheFixtures"? ########## metadata/src/testFixtures/java/org/apache/kafka/metadata/authorizer/StandardAclTestFixtures.java: ########## @@ -0,0 +1,79 @@ +/* + * 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.kafka.metadata.authorizer; + +import org.apache.kafka.common.acl.AclOperation; +import org.apache.kafka.common.acl.AclPermissionType; +import org.apache.kafka.common.resource.PatternType; +import org.apache.kafka.common.resource.Resource; +import org.apache.kafka.common.resource.ResourceType; + +import java.util.ArrayList; +import java.util.List; + +import static org.apache.kafka.metadata.authorizer.StandardAuthorizerData.WILDCARD; +import static org.apache.kafka.metadata.authorizer.StandardAuthorizerData.WILDCARD_PRINCIPAL; + +public final class StandardAclTestFixtures { + public static final List<StandardAcl> TEST_ACLS = new ArrayList<>(); Review Comment: ```java public static final List<StandardAcl> TEST_ACLS = List.of( new StandardAcl( ResourceType.CLUSTER, Resource.CLUSTER_NAME, PatternType.LITERAL, WILDCARD_PRINCIPAL, WILDCARD, AclOperation.ALTER, AclPermissionType.ALLOW ), new StandardAcl( ResourceType.TOPIC, "foo_", PatternType.PREFIXED, WILDCARD_PRINCIPAL, WILDCARD, AclOperation.READ, AclPermissionType.ALLOW ), new StandardAcl( ResourceType.GROUP, "mygroup", PatternType.LITERAL, "User:foo", WILDCARD, AclOperation.READ, AclPermissionType.DENY ), new StandardAcl( ResourceType.GROUP, "mygroup", PatternType.PREFIXED, "User:foo", WILDCARD, AclOperation.READ, AclPermissionType.DENY ), new StandardAcl( ResourceType.GROUP, "foo", PatternType.PREFIXED, "User:foo", WILDCARD, AclOperation.READ, AclPermissionType.DENY ) ); ``` ########## metadata/src/testFixtures/java/org/apache/kafka/image/FeaturesImageTestFixtures.java: ########## @@ -0,0 +1,88 @@ +/* + * 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.kafka.image; + +import org.apache.kafka.common.metadata.FeatureLevelRecord; +import org.apache.kafka.metadata.RecordTestUtils; +import org.apache.kafka.server.common.ApiMessageAndVersion; +import org.apache.kafka.server.common.MetadataVersion; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public final class FeaturesImageTestFixtures { Review Comment: ```java public final class FeaturesImageTestFixtures { public static final FeaturesImage IMAGE1 = new FeaturesImage( Map.of("foo", (short) 2, "bar", (short) 1), MetadataVersion.latestTesting() ); public static final List<ApiMessageAndVersion> DELTA1_RECORDS = List.of( new ApiMessageAndVersion(new FeatureLevelRecord().setName("foo").setFeatureLevel((short) 3), (short) 0), new ApiMessageAndVersion(new FeatureLevelRecord().setName("bar").setFeatureLevel((short) 0), (short) 0), new ApiMessageAndVersion(new FeatureLevelRecord().setName("baz").setFeatureLevel((short) 8), (short) 0) ); public static final FeaturesDelta DELTA1 = RecordTestUtils.replayAll( new FeaturesDelta(IMAGE1), DELTA1_RECORDS ); public static final FeaturesImage IMAGE2 = new FeaturesImage( Map.of("foo", (short) 3, "baz", (short) 8), MetadataVersion.latestTesting() ); public static final List<ApiMessageAndVersion> DELTA2_RECORDS = List.of( new ApiMessageAndVersion(new FeatureLevelRecord().setName("foo").setFeatureLevel((short) 0), (short) 0), new ApiMessageAndVersion(new FeatureLevelRecord().setName("baz").setFeatureLevel((short) 0), (short) 0), new ApiMessageAndVersion(new FeatureLevelRecord().setName("bar").setFeatureLevel((short) 1), (short) 0) ); public static final FeaturesDelta DELTA2 = RecordTestUtils.replayAll( new FeaturesDelta(IMAGE2), DELTA2_RECORDS ); public static final FeaturesImage IMAGE3 = new FeaturesImage( Map.of("bar", (short) 1), MetadataVersion.latestTesting() ); private FeaturesImageTestFixtures() { } } ``` ########## core/src/test/scala/unit/kafka/server/KafkaApisTest.scala: ########## @@ -86,7 +86,7 @@ import org.apache.kafka.coordinator.group.streams.StreamsGroupHeartbeatResult import org.apache.kafka.coordinator.share.{ShareCoordinator, ShareCoordinatorTestConfig} import org.apache.kafka.coordinator.transaction.TransactionLogConfig import org.apache.kafka.image.{MetadataDelta, MetadataImage, MetadataProvenance} -import org.apache.kafka.metadata.{ConfigRepository, KRaftMetadataCache, MetadataCache, MetadataCacheTest, MockConfigRepository} +import org.apache.kafka.metadata.{ConfigRepository, KRaftMetadataCache, MetadataCache, MetadataCacheTestFixtures, MockConfigRepository} Review Comment: `SimpleConfigRepository` in the storage module could be replaced by `MockConfigRepository` ########## metadata/src/testFixtures/java/org/apache/kafka/image/ProducerIdsImageTestFixtures.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.kafka.image; + +import org.apache.kafka.common.metadata.ProducerIdsRecord; +import org.apache.kafka.metadata.RecordTestUtils; +import org.apache.kafka.server.common.ApiMessageAndVersion; + +import java.util.ArrayList; +import java.util.List; + +public final class ProducerIdsImageTestFixtures { Review Comment: ```java public final class ProducerIdsImageTestFixtures { public static final ProducerIdsImage IMAGE1 = new ProducerIdsImage(123); public static final List<ApiMessageAndVersion> DELTA1_RECORDS = List.of( new ApiMessageAndVersion(new ProducerIdsRecord().setBrokerId(2).setBrokerEpoch(100).setNextProducerId(456), (short) 0), new ApiMessageAndVersion(new ProducerIdsRecord().setBrokerId(3).setBrokerEpoch(100).setNextProducerId(780), (short) 0), new ApiMessageAndVersion(new ProducerIdsRecord().setBrokerId(3).setBrokerEpoch(100).setNextProducerId(785), (short) 0), new ApiMessageAndVersion(new ProducerIdsRecord().setBrokerId(2).setBrokerEpoch(100).setNextProducerId(800), (short) 0) ); public static final ProducerIdsDelta DELTA1 = RecordTestUtils.replayAll( new ProducerIdsDelta(IMAGE1), DELTA1_RECORDS ); public static final ProducerIdsImage IMAGE2 = new ProducerIdsImage(800); private ProducerIdsImageTestFixtures() { } } ``` ########## metadata/src/testFixtures/java/org/apache/kafka/image/ConfigurationsImageTestFixtures.java: ########## @@ -0,0 +1,86 @@ +/* + * 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.kafka.image; + +import org.apache.kafka.common.config.ConfigResource; +import org.apache.kafka.common.metadata.ConfigRecord; +import org.apache.kafka.metadata.RecordTestUtils; +import org.apache.kafka.metadata.SupportedConfigChecker; +import org.apache.kafka.server.common.ApiMessageAndVersion; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.apache.kafka.common.config.ConfigResource.Type.BROKER; +import static org.apache.kafka.common.metadata.MetadataRecordType.CONFIG_RECORD; + +public final class ConfigurationsImageTestFixtures { Review Comment: ```java public final class ConfigurationsImageTestFixtures { public static final ConfigurationsImage IMAGE1 = new ConfigurationsImage(Map.of( new ConfigResource(BROKER, "0"), new ConfigurationImage(new ConfigResource(BROKER, "0"), Map.of("foo", "bar", "baz", "quux")), new ConfigResource(BROKER, "1"), new ConfigurationImage(new ConfigResource(BROKER, "1"), Map.of("foobar", "foobaz")) )); public static final List<ApiMessageAndVersion> DELTA1_RECORDS = List.of( new ApiMessageAndVersion(new ConfigRecord().setResourceType(BROKER.id()) .setResourceName("0").setName("foo").setValue(null), CONFIG_RECORD.highestSupportedVersion()), new ApiMessageAndVersion(new ConfigRecord().setResourceType(BROKER.id()) .setResourceName("0").setName("baz").setValue(null), CONFIG_RECORD.highestSupportedVersion()), new ApiMessageAndVersion(new ConfigRecord().setResourceType(BROKER.id()) .setResourceName("1").setName("foobar").setValue(null), CONFIG_RECORD.highestSupportedVersion()), new ApiMessageAndVersion(new ConfigRecord().setResourceType(BROKER.id()) .setResourceName("1").setName("barfoo").setValue("bazfoo"), CONFIG_RECORD.highestSupportedVersion()), new ApiMessageAndVersion(new ConfigRecord().setResourceType(BROKER.id()) .setResourceName("2").setName("foo").setValue("bar"), CONFIG_RECORD.highestSupportedVersion()) ); public static final ConfigurationsDelta DELTA1 = RecordTestUtils.replayAll(new ConfigurationsDelta(IMAGE1, SupportedConfigChecker.TRUE), DELTA1_RECORDS); public static final ConfigurationsImage IMAGE2 = new ConfigurationsImage(Map.of( new ConfigResource(BROKER, "1"), new ConfigurationImage(new ConfigResource(BROKER, "1"), Map.of("barfoo", "bazfoo")), new ConfigResource(BROKER, "2"), new ConfigurationImage(new ConfigResource(BROKER, "2"), Map.of("foo", "bar")) )); private ConfigurationsImageTestFixtures() { } } ``` ########## metadata/src/testFixtures/java/org/apache/kafka/metadata/authorizer/StandardAclWithIdTestFixtures.java: ########## @@ -0,0 +1,42 @@ +/* + * 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.kafka.metadata.authorizer; + +import org.apache.kafka.common.Uuid; + +import java.util.ArrayList; +import java.util.List; + +public final class StandardAclWithIdTestFixtures { Review Comment: ```java public final class StandardAclWithIdTestFixtures { public static final List<StandardAclWithId> TEST_ACLS = List.of( new StandardAclWithId(Uuid.fromString("QZDDv-R7SyaPgetDPGd0Mw"), StandardAclTestFixtures.TEST_ACLS.get(0)), new StandardAclWithId(Uuid.fromString("SdDjEdlbRmy2__WFKe3RMg"), StandardAclTestFixtures.TEST_ACLS.get(1)), new StandardAclWithId(Uuid.fromString("wQzt5gkSTwuQNXZF5gIw7A"), StandardAclTestFixtures.TEST_ACLS.get(2)), new StandardAclWithId(Uuid.fromString("ab_5xjJXSbS1o5jGfhgQXg"), StandardAclTestFixtures.TEST_ACLS.get(3)), new StandardAclWithId(Uuid.fromString("wP_cCK0LTEGSX9oDRInJHQ"), StandardAclTestFixtures.TEST_ACLS.get(4)) ); private StandardAclWithIdTestFixtures() { } } ``` ########## metadata/src/testFixtures/java/org/apache/kafka/image/ConfigurationsImageTestFixtures.java: ########## @@ -0,0 +1,86 @@ +/* + * 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.kafka.image; + +import org.apache.kafka.common.config.ConfigResource; +import org.apache.kafka.common.metadata.ConfigRecord; +import org.apache.kafka.metadata.RecordTestUtils; +import org.apache.kafka.metadata.SupportedConfigChecker; +import org.apache.kafka.server.common.ApiMessageAndVersion; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.apache.kafka.common.config.ConfigResource.Type.BROKER; +import static org.apache.kafka.common.metadata.MetadataRecordType.CONFIG_RECORD; + +public final class ConfigurationsImageTestFixtures { Review Comment: We need to make `RecordTestUtils.replayAll` return the input target to make the above code work -- 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]
