Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
chia7712 merged PR #15800: URL: https://github.com/apache/kafka/pull/15800 -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
TaiJuWu commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1586484285 ## core/src/test/java/kafka/test/junit/ClusterTestExtensionsUnitTest.java: ## @@ -0,0 +1,45 @@ +/* + * 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 kafka.test.junit; + +import kafka.test.annotation.ClusterTemplate; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import java.util.function.Consumer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ClusterTestExtensionsUnitTest { +@Test +@SuppressWarnings("unchecked") +void testProcessClusterTemplate() { +ClusterTestExtensions ext = new ClusterTestExtensions(); +ExtensionContext context = mock(ExtensionContext.class); +Consumer testInvocations = mock(Consumer.class); +ClusterTemplate annot = mock(ClusterTemplate.class); +when(annot.value()).thenReturn(""); Review Comment: Done. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
chia7712 commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1586043209 ## core/src/test/java/kafka/test/junit/ClusterTestExtensionsUnitTest.java: ## @@ -0,0 +1,45 @@ +/* + * 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 kafka.test.junit; + +import kafka.test.annotation.ClusterTemplate; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import java.util.function.Consumer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ClusterTestExtensionsUnitTest { +@Test +@SuppressWarnings("unchecked") +void testProcessClusterTemplate() { +ClusterTestExtensions ext = new ClusterTestExtensions(); +ExtensionContext context = mock(ExtensionContext.class); +Consumer testInvocations = mock(Consumer.class); +ClusterTemplate annot = mock(ClusterTemplate.class); +when(annot.value()).thenReturn(""); + +Assertions.assertThrows(IllegalStateException.class, () -> { Review Comment: how about `Assertions.assertThrows(IllegalStateException.class, () -> ext.processClusterTemplate(context, annot, testInvocations));`? ## core/src/test/java/kafka/test/junit/ClusterTestExtensionsUnitTest.java: ## @@ -0,0 +1,45 @@ +/* + * 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 kafka.test.junit; + +import kafka.test.annotation.ClusterTemplate; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import java.util.function.Consumer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ClusterTestExtensionsUnitTest { +@Test +@SuppressWarnings("unchecked") +void testProcessClusterTemplate() { +ClusterTestExtensions ext = new ClusterTestExtensions(); +ExtensionContext context = mock(ExtensionContext.class); +Consumer testInvocations = mock(Consumer.class); +ClusterTemplate annot = mock(ClusterTemplate.class); +when(annot.value()).thenReturn(""); Review Comment: please add test for value " " -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
chia7712 commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1586042610 ## core/src/test/java/kafka/test/junit/ClusterTestExtensions.java: ## @@ -118,16 +118,15 @@ public Stream provideTestTemplateInvocationContex return generatedContexts.stream(); } -private void processClusterTemplate(ExtensionContext context, ClusterTemplate annot, +void processClusterTemplate(ExtensionContext context, ClusterTemplate annot, Consumer testInvocations) { // If specified, call cluster config generated method (must be static) List generatedClusterConfigs = new ArrayList<>(); -if (!annot.value().isEmpty()) { -generateClusterConfigurations(context, annot.value(), generatedClusterConfigs::add); -} else { -// Ensure we have at least one cluster config - generatedClusterConfigs.add(ClusterConfig.defaultBuilder().build()); + +if (annot.value().isEmpty()) { Review Comment: How about `if (annot.value().trim().isEmpty()) throw new IllegalStateException("ClusterTemplate value can't be empty string");` -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
chia7712 commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1586041747 ## core/src/test/java/kafka/test/junit/ClusterTestExtensions.java: ## @@ -91,9 +91,6 @@ public Stream provideTestTemplateInvocationContex ClusterTemplate clusterTemplateAnnot = context.getRequiredTestMethod().getDeclaredAnnotation(ClusterTemplate.class); if (clusterTemplateAnnot != null) { processClusterTemplate(context, clusterTemplateAnnot, generatedContexts::add); -if (generatedContexts.isEmpty()) { -throw new IllegalStateException("ClusterConfig generator method should provide at least one config"); Review Comment: https://issues.apache.org/jira/browse/KAFKA-16652 @TaiJuWu Please feel free to take over it -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
chia7712 commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1585492894 ## core/src/test/java/kafka/test/junit/ClusterTestExtensions.java: ## @@ -91,9 +91,6 @@ public Stream provideTestTemplateInvocationContex ClusterTemplate clusterTemplateAnnot = context.getRequiredTestMethod().getDeclaredAnnotation(ClusterTemplate.class); if (clusterTemplateAnnot != null) { processClusterTemplate(context, clusterTemplateAnnot, generatedContexts::add); -if (generatedContexts.isEmpty()) { -throw new IllegalStateException("ClusterConfig generator method should provide at least one config"); Review Comment: > try to add unit test for it. nice. It is ok to file a jira to log it and we can merge this PR first. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
TaiJuWu commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1585486875 ## core/src/test/java/kafka/test/junit/ClusterTestExtensions.java: ## @@ -91,9 +91,6 @@ public Stream provideTestTemplateInvocationContex ClusterTemplate clusterTemplateAnnot = context.getRequiredTestMethod().getDeclaredAnnotation(ClusterTemplate.class); if (clusterTemplateAnnot != null) { processClusterTemplate(context, clusterTemplateAnnot, generatedContexts::add); -if (generatedContexts.isEmpty()) { -throw new IllegalStateException("ClusterConfig generator method should provide at least one config"); Review Comment: If we move the check to `processClusterTemplate`, `generatedContexts` also need to expose to `processClusterTemplate`, so I prefer keep this version and revert the change and try to add unit test for it. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
TaiJuWu commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1585486875 ## core/src/test/java/kafka/test/junit/ClusterTestExtensions.java: ## @@ -91,9 +91,6 @@ public Stream provideTestTemplateInvocationContex ClusterTemplate clusterTemplateAnnot = context.getRequiredTestMethod().getDeclaredAnnotation(ClusterTemplate.class); if (clusterTemplateAnnot != null) { processClusterTemplate(context, clusterTemplateAnnot, generatedContexts::add); -if (generatedContexts.isEmpty()) { -throw new IllegalStateException("ClusterConfig generator method should provide at least one config"); Review Comment: If we move the check to `processClusterTemplate`, `generatedContexts` also need to expose to `processClusterTemplate`, so I prefer keep this version and revert the change. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
chia7712 commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1582294569 ## core/src/test/java/kafka/test/junit/ClusterTestExtensions.java: ## @@ -91,9 +91,6 @@ public Stream provideTestTemplateInvocationContex ClusterTemplate clusterTemplateAnnot = context.getRequiredTestMethod().getDeclaredAnnotation(ClusterTemplate.class); if (clusterTemplateAnnot != null) { processClusterTemplate(context, clusterTemplateAnnot, generatedContexts::add); -if (generatedContexts.isEmpty()) { -throw new IllegalStateException("ClusterConfig generator method should provide at least one config"); Review Comment: My previous comment is wrong. This check is used to make sure there is at least one `ClusterConfig`, so we should not remove it. However, It seems to me this check should be moved to `processClusterTemplate` and we should add unit test for it. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
TaiJuWu commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1581882839 ## core/src/test/java/kafka/test/junit/ClusterTestExtensionsUnitTest.java: ## @@ -0,0 +1,45 @@ +/* + * 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 kafka.test.junit; + +import kafka.test.annotation.ClusterTemplate; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import java.lang.reflect.Method; +import java.util.function.Consumer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ClusterTestExtensionsUnitTest { +@Test Review Comment: Done. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
chia7712 commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1581877562 ## core/src/test/java/kafka/test/junit/ClusterTestExtensions.java: ## @@ -118,16 +115,15 @@ public Stream provideTestTemplateInvocationContex return generatedContexts.stream(); } -private void processClusterTemplate(ExtensionContext context, ClusterTemplate annot, +protected void processClusterTemplate(ExtensionContext context, ClusterTemplate annot, Review Comment: please remove `protected` to make it be package-private ## core/src/test/java/kafka/test/junit/ClusterTestExtensionsUnitTest.java: ## @@ -0,0 +1,45 @@ +/* + * 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 kafka.test.junit; + +import kafka.test.annotation.ClusterTemplate; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import java.lang.reflect.Method; +import java.util.function.Consumer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ClusterTestExtensionsUnitTest { +@Test Review Comment: please add `@SuppressWarnings("unchecked")` -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
TaiJuWu commented on PR #15800: URL: https://github.com/apache/kafka/pull/15800#issuecomment-2081119063 > @TaiJuWu please fix the conflicts Done. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
chia7712 commented on PR #15800: URL: https://github.com/apache/kafka/pull/15800#issuecomment-2081116576 @TaiJuWu please fix the conflicts -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
TaiJuWu commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1581842957 ## core/src/test/java/kafka/test/ClusterTestExtensionsUnitTest.java: ## @@ -0,0 +1,46 @@ +/* + * 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 kafka.test; + +import kafka.test.junit.ClusterTestExtensions; +import kafka.test.annotation.ClusterTemplate; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import java.lang.reflect.Method; +import java.util.function.Consumer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ClusterTestExtensionsUnitTest { +@Test +void testProcessClusterTemplate() throws Exception { +ClusterTestExtensions ext = mock(ClusterTestExtensions.class); +ExtensionContext context = mock(ExtensionContext.class); +Consumer testInvocations = mock(Consumer.class); +ClusterTemplate annot = mock(ClusterTemplate.class); +when(annot.value()).thenReturn(""); + +Method method = ClusterTestExtensions.class.getDeclaredMethod("processClusterTemplate", Review Comment: Done. Please review. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
chia7712 commented on PR #15800: URL: https://github.com/apache/kafka/pull/15800#issuecomment-2078284518 @TaiJuWu Could you add a new test file (`ClusterTestExtensionsUnitTest`) to verify the function `processClusterTemplate`? -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
TaiJuWu commented on PR #15800: URL: https://github.com/apache/kafka/pull/15800#issuecomment-2076019523 > @TaiJuWu thanks for this contribution. btw, is this check ( > > https://github.com/apache/kafka/blob/81c222e9779c3339aa139ab930a74aba2c7c8685/core/src/test/java/kafka/test/junit/ClusterTestExtensions.java#L92 > > ) unnecessary? Yes, I believe it’s unnecessary. If we give default value (code on truncated branch), the size must be greater zero, we just need to select one. Here we have two solutions, one is current version, the other is you look last time. I don’t take any position, both are great for me. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] KAFKA-16614:Disallow @ClusterTemplate("") [kafka]
chia7712 commented on code in PR #15800: URL: https://github.com/apache/kafka/pull/15800#discussion_r1578597252 ## core/src/test/java/kafka/test/junit/ClusterTestExtensions.java: ## @@ -123,8 +123,7 @@ private void processClusterTemplate(ExtensionContext context, ClusterTemplate an if (!annot.value().isEmpty()) { generateClusterConfigurations(context, annot.value(), generatedClusterConfigs::add); } else { -// Ensure we have at least one cluster config - generatedClusterConfigs.add(ClusterConfig.defaultClusterBuilder().build()); +throw new IllegalStateException("Annotation value can't be empty string."); Review Comment: Could we check `annot.value().isEmpty()` first? for example: ```java if (annot.value().isEmpty()) throw exception; ``` With above change, we can simplify the if-else -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org