chia7712 commented on code in PR #22247:
URL: https://github.com/apache/kafka/pull/22247#discussion_r3222505060


##########
metadata/src/testFixtures/java/org/apache/kafka/image/AclsImageFixtures.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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.Uuid;
+import org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord;
+import org.apache.kafka.metadata.RecordTestUtils;
+import org.apache.kafka.metadata.authorizer.StandardAcl;
+import org.apache.kafka.metadata.authorizer.StandardAclWithId;
+import org.apache.kafka.metadata.authorizer.StandardAclWithIdFixtures;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public final class AclsImageFixtures {
+    public static final AclsImage IMAGE1;
+    public static final List<ApiMessageAndVersion> DELTA1_RECORDS;
+    public static final AclsDelta DELTA1;
+    public static final AclsImage IMAGE2;
+
+    static {

Review Comment:
   ```java
   public final class AclsImageFixtures {
   
       public static final AclsImage IMAGE1 = new AclsImage(createAclMap(0, 4));
   
       public static final List<ApiMessageAndVersion> DELTA1_RECORDS = List.of(
               new ApiMessageAndVersion(new RemoveAccessControlEntryRecord().
                       setId(Uuid.fromString("QZDDv-R7SyaPgetDPGd0Mw")), 
(short) 0),
               new 
ApiMessageAndVersion(StandardAclWithIdFixtures.TEST_ACLS.get(4).toRecord(), 
(short) 0)
       );
   
       public static final AclsDelta DELTA1 = RecordTestUtils.replayAll(new 
AclsDelta(IMAGE1), DELTA1_RECORDS);
   
       public static final AclsImage IMAGE2 = new AclsImage(createAclMap(1, 5));
   
       private static Map<Uuid, StandardAcl> createAclMap(int startInclusive, 
int endExclusive) {
           return IntStream.range(startInclusive, endExclusive)
                   .mapToObj(StandardAclWithIdFixtures.TEST_ACLS::get)
                   .collect(Collectors.toUnmodifiableMap(StandardAclWithId::id, 
StandardAclWithId::acl));
       }
   
       private AclsImageFixtures() {
       }
   }
   ```



##########
metadata/src/testFixtures/java/org/apache/kafka/image/ClientQuotasImageFixtures.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.ClientQuotaRecord;
+import org.apache.kafka.common.metadata.ClientQuotaRecord.EntityData;
+import org.apache.kafka.common.quota.ClientQuotaEntity;
+import org.apache.kafka.metadata.RecordTestUtils;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+import org.apache.kafka.server.config.QuotaConfig;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.kafka.common.metadata.MetadataRecordType.CLIENT_QUOTA_RECORD;
+
+public final class ClientQuotasImageFixtures {
+    public static final ClientQuotasImage IMAGE1;
+    public static final List<ApiMessageAndVersion> DELTA1_RECORDS;
+    public static final ClientQuotasDelta DELTA1;
+    public static final ClientQuotasImage IMAGE2;
+
+    static {

Review Comment:
   ```java
   public final class ClientQuotasImageFixtures {
   
       public static final ClientQuotasImage IMAGE1 = new 
ClientQuotasImage(Map.of(
               new ClientQuotaEntity(Map.of(ClientQuotaEntity.USER, "foo")),
               new 
ClientQuotaImage(Map.of(QuotaConfig.PRODUCER_BYTE_RATE_OVERRIDE_CONFIG, 123.0)),
               new ClientQuotaEntity(Map.of(ClientQuotaEntity.USER, "bar", 
ClientQuotaEntity.IP, "127.0.0.1")),
               new 
ClientQuotaImage(Map.of(QuotaConfig.CONSUMER_BYTE_RATE_OVERRIDE_CONFIG, 456.0))
       ));
   
       public static final List<ApiMessageAndVersion> DELTA1_RECORDS = List.of(
               // remove quota
               new ApiMessageAndVersion(new ClientQuotaRecord().
                       setEntity(List.of(
                               new 
EntityData().setEntityType(ClientQuotaEntity.USER).setEntityName("bar"),
                               new 
EntityData().setEntityType(ClientQuotaEntity.IP).setEntityName("127.0.0.1"))).
                       setKey(QuotaConfig.CONSUMER_BYTE_RATE_OVERRIDE_CONFIG).
                       setRemove(true), 
CLIENT_QUOTA_RECORD.highestSupportedVersion()),
               // alter quota
               new ApiMessageAndVersion(new ClientQuotaRecord().
                       setEntity(List.of(
                               new 
EntityData().setEntityType(ClientQuotaEntity.USER).setEntityName("foo"))).
                       setKey(QuotaConfig.PRODUCER_BYTE_RATE_OVERRIDE_CONFIG).
                       setValue(234.0), 
CLIENT_QUOTA_RECORD.highestSupportedVersion()),
               // add quota to entity with existing quota
               new ApiMessageAndVersion(new ClientQuotaRecord().
                       setEntity(List.of(
                               new 
EntityData().setEntityType(ClientQuotaEntity.USER).setEntityName("foo"))).
                       setKey(QuotaConfig.CONSUMER_BYTE_RATE_OVERRIDE_CONFIG).
                       setValue(999.0), 
CLIENT_QUOTA_RECORD.highestSupportedVersion())
       );
   
       public static final ClientQuotasDelta DELTA1 = RecordTestUtils.replayAll(
               new ClientQuotasDelta(IMAGE1),
               DELTA1_RECORDS
       );
   
       public static final ClientQuotasImage IMAGE2 = new 
ClientQuotasImage(Map.of(
               new ClientQuotaEntity(Map.of(ClientQuotaEntity.USER, "foo")),
               new ClientQuotaImage(Map.of(
                       QuotaConfig.PRODUCER_BYTE_RATE_OVERRIDE_CONFIG, 234.0,
                       QuotaConfig.CONSUMER_BYTE_RATE_OVERRIDE_CONFIG, 999.0
               ))
       ));
   
       private ClientQuotasImageFixtures() {
       }
   }
   ```



##########
core/src/test/scala/unit/kafka/security/authorizer/AuthorizerTest.scala:
##########
@@ -34,8 +34,7 @@ import org.apache.kafka.common.resource.{PatternType, 
ResourcePattern, ResourceP
 import org.apache.kafka.common.security.auth.{KafkaPrincipal, SecurityProtocol}
 import org.apache.kafka.common.utils.internals.{SecurityUtils => 
JSecurityUtils}
 import org.apache.kafka.controller.MockAclMutator

Review Comment:
   It seems `AuthorizerTest` is the only class using `MockAclMutator`. Would 
you mind opening a ticket to move `MockAclMutator` alongside `AuthorizerTest` 
when the latter is moved out of the core module?



##########
metadata/src/testFixtures/java/org/apache/kafka/image/DelegationTokenImageFixtures.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.DelegationTokenRecord;
+import org.apache.kafka.common.metadata.RemoveDelegationTokenRecord;
+import org.apache.kafka.common.security.auth.KafkaPrincipal;
+import org.apache.kafka.common.security.token.delegation.TokenInformation;
+import org.apache.kafka.common.utils.internals.SecurityUtils;
+import org.apache.kafka.metadata.DelegationTokenData;
+import org.apache.kafka.metadata.RecordTestUtils;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public final class DelegationTokenImageFixtures {

Review Comment:
   ```java
   public final class DelegationTokenImageFixtures {
   
       private static DelegationTokenData randomDelegationTokenData(String 
tokenId, long expireTimestamp) {
           TokenInformation ti = new TokenInformation(
                   tokenId,
                   SecurityUtils.parseKafkaPrincipal(KafkaPrincipal.USER_TYPE + 
":" + "fred"),
                   SecurityUtils.parseKafkaPrincipal(KafkaPrincipal.USER_TYPE + 
":" + "fred"),
                   List.of(),
                   0,
                   1000,
                   expireTimestamp);
           return new DelegationTokenData(ti);
       }
   
       public static final DelegationTokenImage IMAGE1 = new 
DelegationTokenImage(Map.of(
               "somerandomuuid1", randomDelegationTokenData("somerandomuuid1", 
100),
               "somerandomuuid2", randomDelegationTokenData("somerandomuuid2", 
100),
               "somerandomuuid3", randomDelegationTokenData("somerandomuuid3", 
100)
       ));
   
       public static final List<ApiMessageAndVersion> DELTA1_RECORDS = List.of(
               new ApiMessageAndVersion(new DelegationTokenRecord().
                       setOwner(KafkaPrincipal.USER_TYPE + ":" + "fred").
                       setRequester(KafkaPrincipal.USER_TYPE + ":" + "fred").
                       setIssueTimestamp(0).
                       setMaxTimestamp(1000).
                       setExpirationTimestamp(200).
                       setTokenId("somerandomuuid1"), (short) 0),
               new ApiMessageAndVersion(new RemoveDelegationTokenRecord().
                       setTokenId("somerandomuuid3"), (short) 0)
       );
   
       public static final DelegationTokenDelta DELTA1 = 
RecordTestUtils.replayAll(
               new DelegationTokenDelta(IMAGE1),
               DELTA1_RECORDS
       );
   
       public static final DelegationTokenImage IMAGE2 = new 
DelegationTokenImage(Map.of(
               "somerandomuuid1", randomDelegationTokenData("somerandomuuid1", 
200),
               "somerandomuuid2", randomDelegationTokenData("somerandomuuid2", 
100)
       ));
   
       private DelegationTokenImageFixtures() {
       }
   }
   ```



-- 
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]

Reply via email to