Re: [PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-05-02 Thread via GitHub


soarez merged PR #15832:
URL: https://github.com/apache/kafka/pull/15832


-- 
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-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-05-02 Thread via GitHub


soarez commented on PR #15832:
URL: https://github.com/apache/kafka/pull/15832#issuecomment-2090021412

   Thanks for the PR @nizhikov.
   Thanks for reviewing @chia7712.


-- 
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-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-05-02 Thread via GitHub


soarez commented on code in PR #15832:
URL: https://github.com/apache/kafka/pull/15832#discussion_r1587320225


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,184 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {
+private static final String USER1 = "user1";
+private static final String USER2 = "user2";
+
+@Override
+public int brokerCount() {
+return 1;
+}
+
+static class ConfigCommandResult {
+public final String stdout;
+public final OptionalInt exitStatus;
+
+public ConfigCommandResult(String stdout) {
+this(stdout, OptionalInt.empty());
+}
+
+public ConfigCommandResult(String stdout, OptionalInt exitStatus) {
+this.stdout = stdout;
+this.exitStatus = exitStatus;
+}
+}
+
+private ConfigCommandResult runConfigCommandViaBroker(String...args) {
+ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+String utf8 = StandardCharsets.UTF_8.name();
+PrintStream printStream;
+try {
+printStream = new PrintStream(byteArrayOutputStream, true, utf8);
+} catch (UnsupportedEncodingException e) {
+throw new RuntimeException(e);
+}
+AtomicReference exitStatus = new 
AtomicReference<>(OptionalInt.empty());
+Exit.setExitProcedure((status, __) -> {
+exitStatus.set(OptionalInt.of((Integer) status));
+throw new RuntimeException();
+});
+
+List commandArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName(;
+commandArgs.addAll(Arrays.asList(args));
+try {
+Console.withOut(printStream, () -> {
+ConfigCommand.main(commandArgs.toArray(new String[0]));
+return null;
+});
+return new 
ConfigCommandResult(byteArrayOutputStream.toString(utf8));
+} catch (Exception e) {
+return new ConfigCommandResult("", exitStatus.get());
+} finally {
+printStream.close();
+Exit.resetExitProcedure();
+}
+}
+
+@ParameterizedTest
+@ValueSource(strings = {"kraft", "zk"})
+public void testUserScramCredentialsRequests(String quorum) throws 
Exception {
+createAndAlterUser(USER1);
+// now do the same thing for user2
+createAndAlterUser(USER2);
+
+// describe both
+// we don't know the order that quota or scram users come out, so we 
have 2 possibilities for each, 4 total
+String quotaPossibilityAOut = quotaMessage(USER1) + 
quotaMessage(USER2);
+String quotaPossibilityBOut = quotaMessage(USER2) + 
quotaMessage(USER1);
+String scramPossibilityAOut = describeUserMessage(USER1) + 
describeUserMessage(USER2);
+String scramPossibilityBOut = describeUserMessage(USER2) + 
describeUserMessage(USER1);
+describeUsers(
+quotaPossibilityAOut + scramPossibilityAOut,
+quotaPossibilityAOut + scramPossibilityBOut,
+quotaPossibilityBOut + scramPossibilityAOut,
+quotaPossibilityBOut + scramPossibilityBOut);
+
+// now delete configs, in opposite order, for user1 and user2, 

Re: [PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-05-02 Thread via GitHub


nizhikov commented on code in PR #15832:
URL: https://github.com/apache/kafka/pull/15832#discussion_r1587315800


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,184 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {
+private static final String USER1 = "user1";
+private static final String USER2 = "user2";
+
+@Override
+public int brokerCount() {
+return 1;
+}
+
+static class ConfigCommandResult {
+public final String stdout;
+public final OptionalInt exitStatus;
+
+public ConfigCommandResult(String stdout) {
+this(stdout, OptionalInt.empty());
+}
+
+public ConfigCommandResult(String stdout, OptionalInt exitStatus) {
+this.stdout = stdout;
+this.exitStatus = exitStatus;
+}
+}
+
+private ConfigCommandResult runConfigCommandViaBroker(String...args) {
+ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+String utf8 = StandardCharsets.UTF_8.name();
+PrintStream printStream;
+try {
+printStream = new PrintStream(byteArrayOutputStream, true, utf8);
+} catch (UnsupportedEncodingException e) {
+throw new RuntimeException(e);
+}
+AtomicReference exitStatus = new 
AtomicReference<>(OptionalInt.empty());
+Exit.setExitProcedure((status, __) -> {
+exitStatus.set(OptionalInt.of((Integer) status));
+throw new RuntimeException();
+});
+
+List commandArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName(;
+commandArgs.addAll(Arrays.asList(args));
+try {
+Console.withOut(printStream, () -> {
+ConfigCommand.main(commandArgs.toArray(new String[0]));
+return null;
+});
+return new 
ConfigCommandResult(byteArrayOutputStream.toString(utf8));
+} catch (Exception e) {
+return new ConfigCommandResult("", exitStatus.get());
+} finally {
+printStream.close();
+Exit.resetExitProcedure();
+}
+}
+
+@ParameterizedTest
+@ValueSource(strings = {"kraft", "zk"})
+public void testUserScramCredentialsRequests(String quorum) throws 
Exception {
+createAndAlterUser(USER1);
+// now do the same thing for user2
+createAndAlterUser(USER2);
+
+// describe both
+// we don't know the order that quota or scram users come out, so we 
have 2 possibilities for each, 4 total
+String quotaPossibilityAOut = quotaMessage(USER1) + 
quotaMessage(USER2);
+String quotaPossibilityBOut = quotaMessage(USER2) + 
quotaMessage(USER1);
+String scramPossibilityAOut = describeUserMessage(USER1) + 
describeUserMessage(USER2);
+String scramPossibilityBOut = describeUserMessage(USER2) + 
describeUserMessage(USER1);
+describeUsers(
+quotaPossibilityAOut + scramPossibilityAOut,
+quotaPossibilityAOut + scramPossibilityBOut,
+quotaPossibilityBOut + scramPossibilityAOut,
+quotaPossibilityBOut + scramPossibilityBOut);
+
+// now delete configs, in opposite order, for user1 and 

Re: [PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-05-02 Thread via GitHub


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


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,184 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {
+private static final String USER1 = "user1";
+private static final String USER2 = "user2";
+
+@Override
+public int brokerCount() {
+return 1;
+}
+
+static class ConfigCommandResult {
+public final String stdout;
+public final OptionalInt exitStatus;
+
+public ConfigCommandResult(String stdout) {
+this(stdout, OptionalInt.empty());
+}
+
+public ConfigCommandResult(String stdout, OptionalInt exitStatus) {
+this.stdout = stdout;
+this.exitStatus = exitStatus;
+}
+}
+
+private ConfigCommandResult runConfigCommandViaBroker(String...args) {
+ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+String utf8 = StandardCharsets.UTF_8.name();
+PrintStream printStream;
+try {
+printStream = new PrintStream(byteArrayOutputStream, true, utf8);
+} catch (UnsupportedEncodingException e) {
+throw new RuntimeException(e);
+}
+AtomicReference exitStatus = new 
AtomicReference<>(OptionalInt.empty());
+Exit.setExitProcedure((status, __) -> {
+exitStatus.set(OptionalInt.of((Integer) status));
+throw new RuntimeException();
+});
+
+List commandArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName(;
+commandArgs.addAll(Arrays.asList(args));
+try {
+Console.withOut(printStream, () -> {
+ConfigCommand.main(commandArgs.toArray(new String[0]));
+return null;
+});
+return new 
ConfigCommandResult(byteArrayOutputStream.toString(utf8));
+} catch (Exception e) {
+return new ConfigCommandResult("", exitStatus.get());
+} finally {
+printStream.close();
+Exit.resetExitProcedure();
+}
+}
+
+@ParameterizedTest
+@ValueSource(strings = {"kraft", "zk"})
+public void testUserScramCredentialsRequests(String quorum) throws 
Exception {
+createAndAlterUser(USER1);
+// now do the same thing for user2
+createAndAlterUser(USER2);
+
+// describe both
+// we don't know the order that quota or scram users come out, so we 
have 2 possibilities for each, 4 total
+String quotaPossibilityAOut = quotaMessage(USER1) + 
quotaMessage(USER2);
+String quotaPossibilityBOut = quotaMessage(USER2) + 
quotaMessage(USER1);
+String scramPossibilityAOut = describeUserMessage(USER1) + 
describeUserMessage(USER2);
+String scramPossibilityBOut = describeUserMessage(USER2) + 
describeUserMessage(USER1);
+describeUsers(
+quotaPossibilityAOut + scramPossibilityAOut,
+quotaPossibilityAOut + scramPossibilityBOut,
+quotaPossibilityBOut + scramPossibilityAOut,
+quotaPossibilityBOut + scramPossibilityBOut);
+
+// now delete configs, in opposite order, for user1 and 

Re: [PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-05-02 Thread via GitHub


soarez commented on code in PR #15832:
URL: https://github.com/apache/kafka/pull/15832#discussion_r1587242657


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,184 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {
+private static final String USER1 = "user1";
+private static final String USER2 = "user2";
+
+@Override
+public int brokerCount() {
+return 1;
+}
+
+static class ConfigCommandResult {
+public final String stdout;
+public final OptionalInt exitStatus;
+
+public ConfigCommandResult(String stdout) {
+this(stdout, OptionalInt.empty());
+}
+
+public ConfigCommandResult(String stdout, OptionalInt exitStatus) {
+this.stdout = stdout;
+this.exitStatus = exitStatus;
+}
+}
+
+private ConfigCommandResult runConfigCommandViaBroker(String...args) {
+ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+String utf8 = StandardCharsets.UTF_8.name();
+PrintStream printStream;
+try {
+printStream = new PrintStream(byteArrayOutputStream, true, utf8);
+} catch (UnsupportedEncodingException e) {
+throw new RuntimeException(e);
+}
+AtomicReference exitStatus = new 
AtomicReference<>(OptionalInt.empty());
+Exit.setExitProcedure((status, __) -> {
+exitStatus.set(OptionalInt.of((Integer) status));
+throw new RuntimeException();
+});
+
+List commandArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName(;
+commandArgs.addAll(Arrays.asList(args));
+try {
+Console.withOut(printStream, () -> {
+ConfigCommand.main(commandArgs.toArray(new String[0]));
+return null;
+});
+return new 
ConfigCommandResult(byteArrayOutputStream.toString(utf8));
+} catch (Exception e) {
+return new ConfigCommandResult("", exitStatus.get());
+} finally {
+printStream.close();
+Exit.resetExitProcedure();
+}
+}
+
+@ParameterizedTest
+@ValueSource(strings = {"kraft", "zk"})
+public void testUserScramCredentialsRequests(String quorum) throws 
Exception {
+createAndAlterUser(USER1);
+// now do the same thing for user2
+createAndAlterUser(USER2);
+
+// describe both
+// we don't know the order that quota or scram users come out, so we 
have 2 possibilities for each, 4 total
+String quotaPossibilityAOut = quotaMessage(USER1) + 
quotaMessage(USER2);
+String quotaPossibilityBOut = quotaMessage(USER2) + 
quotaMessage(USER1);
+String scramPossibilityAOut = describeUserMessage(USER1) + 
describeUserMessage(USER2);
+String scramPossibilityBOut = describeUserMessage(USER2) + 
describeUserMessage(USER1);
+describeUsers(
+quotaPossibilityAOut + scramPossibilityAOut,
+quotaPossibilityAOut + scramPossibilityBOut,
+quotaPossibilityBOut + scramPossibilityAOut,
+quotaPossibilityBOut + scramPossibilityBOut);
+
+// now delete configs, in opposite order, for user1 and user2, 

Re: [PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-05-02 Thread via GitHub


nizhikov commented on code in PR #15832:
URL: https://github.com/apache/kafka/pull/15832#discussion_r1587157698


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,203 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.test.annotation.ClusterTest;
+import kafka.test.annotation.ClusterTestDefaults;
+import kafka.test.annotation.Type;
+import kafka.test.junit.ClusterTestExtensions;
+import kafka.utils.Exit;
+import org.apache.kafka.test.NoRetryException;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.api.extension.ExtendWith;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+@ExtendWith(value = ClusterTestExtensions.class)
+@ClusterTestDefaults(clusterType = Type.ALL)
+public class UserScramCredentialsCommandTest extends BaseRequestTest {

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-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-05-02 Thread via GitHub


nizhikov commented on PR #15832:
URL: https://github.com/apache/kafka/pull/15832#issuecomment-2089753995

   @chia7712 CI looks OK for me. Do you have any other comments?


-- 
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-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-05-01 Thread via GitHub


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


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,203 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.test.annotation.ClusterTest;
+import kafka.test.annotation.ClusterTestDefaults;
+import kafka.test.annotation.Type;
+import kafka.test.junit.ClusterTestExtensions;
+import kafka.utils.Exit;
+import org.apache.kafka.test.NoRetryException;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.api.extension.ExtendWith;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+@ExtendWith(value = ClusterTestExtensions.class)
+@ClusterTestDefaults(clusterType = Type.ALL)
+public class UserScramCredentialsCommandTest extends BaseRequestTest {

Review Comment:
   please remove `extends BaseRequestTest`



-- 
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-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-05-01 Thread via GitHub


nizhikov commented on code in PR #15832:
URL: https://github.com/apache/kafka/pull/15832#discussion_r1586122285


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,213 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.test.annotation.ClusterTest;
+import kafka.test.annotation.ClusterTestDefaults;
+import kafka.test.annotation.ClusterTests;
+import kafka.test.annotation.Type;
+import kafka.test.junit.ClusterTestExtensions;
+import kafka.utils.Exit;
+import org.apache.kafka.test.NoRetryException;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.api.extension.ExtendWith;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+@ExtendWith(value = ClusterTestExtensions.class)
+@ClusterTestDefaults

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-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


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


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,213 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.test.annotation.ClusterTest;
+import kafka.test.annotation.ClusterTestDefaults;
+import kafka.test.annotation.ClusterTests;
+import kafka.test.annotation.Type;
+import kafka.test.junit.ClusterTestExtensions;
+import kafka.utils.Exit;
+import org.apache.kafka.test.NoRetryException;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.api.extension.ExtendWith;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+@ExtendWith(value = ClusterTestExtensions.class)
+@ClusterTestDefaults

Review Comment:
   `@ClusterTestDefaults(clusterType = Type.ALL)` Let's test all types



##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,213 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.test.annotation.ClusterTest;
+import kafka.test.annotation.ClusterTestDefaults;
+import kafka.test.annotation.ClusterTests;
+import kafka.test.annotation.Type;
+import kafka.test.junit.ClusterTestExtensions;
+import kafka.utils.Exit;
+import org.apache.kafka.test.NoRetryException;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.api.extension.ExtendWith;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+@ExtendWith(value = ClusterTestExtensions.class)
+@ClusterTestDefaults
+public class UserScramCredentialsCommandTest extends BaseRequestTest {
+private static final String USER1 = "user1";
+private static final String USER2 = "user2";
+
+@Override
+public int brokerCount() {
+return 1;
+}
+
+static class ConfigCommandResult {
+public final String stdout;
+public final OptionalInt exitStatus;
+
+public ConfigCommandResult(String stdout) {
+this(stdout, OptionalInt.empty());
+}
+
+public ConfigCommandResult(String stdout, OptionalInt exitStatus) {
+this.stdout = stdout;
+this.exitStatus = exitStatus;
+}
+}
+
+private ConfigCommandResult 

Re: [PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


nizhikov commented on code in PR #15832:
URL: https://github.com/apache/kafka/pull/15832#discussion_r1584953273


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,178 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {

Review Comment:
   Test reworked to use ClusterTestExtensions.



-- 
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-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


nizhikov commented on PR #15832:
URL: https://github.com/apache/kafka/pull/15832#issuecomment-2085538452

   @chia7712 All your comments resolved. Please, take a look.


-- 
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-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


nizhikov commented on code in PR #15832:
URL: https://github.com/apache/kafka/pull/15832#discussion_r1584946619


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,184 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {
+private static final String USER1 = "user1";
+private static final String USER2 = "user2";
+
+@Override
+public int brokerCount() {
+return 1;
+}
+
+static class ConfigCommandResult {
+public final String stdout;
+public final OptionalInt exitStatus;
+
+public ConfigCommandResult(String stdout) {
+this(stdout, OptionalInt.empty());
+}
+
+public ConfigCommandResult(String stdout, OptionalInt exitStatus) {
+this.stdout = stdout;
+this.exitStatus = exitStatus;
+}
+}
+
+private ConfigCommandResult runConfigCommandViaBroker(String...args) {
+ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+String utf8 = StandardCharsets.UTF_8.name();
+PrintStream printStream;
+try {
+printStream = new PrintStream(byteArrayOutputStream, true, utf8);
+} catch (UnsupportedEncodingException e) {
+throw new RuntimeException(e);
+}
+AtomicReference exitStatus = new 
AtomicReference<>(OptionalInt.empty());
+Exit.setExitProcedure((status, __) -> {
+exitStatus.set(OptionalInt.of((Integer) status));
+throw new RuntimeException();
+});
+
+List commandArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName(;
+commandArgs.addAll(Arrays.asList(args));
+try {
+Console.withOut(printStream, () -> {
+ConfigCommand.main(commandArgs.toArray(new String[0]));
+return null;
+});
+return new 
ConfigCommandResult(byteArrayOutputStream.toString(utf8));
+} catch (Exception e) {
+return new ConfigCommandResult("", exitStatus.get());
+} finally {
+printStream.close();
+Exit.resetExitProcedure();
+}
+}
+
+@ParameterizedTest
+@ValueSource(strings = {"kraft", "zk"})
+public void testUserScramCredentialsRequests(String quorum) throws 
Exception {
+createAndAlterUser(USER1);
+// now do the same thing for user2
+createAndAlterUser(USER2);
+
+// describe both
+// we don't know the order that quota or scram users come out, so we 
have 2 possibilities for each, 4 total
+String quotaPossibilityAOut = quotaMessage(USER1) + 
quotaMessage(USER2);
+String quotaPossibilityBOut = quotaMessage(USER2) + 
quotaMessage(USER1);
+String scramPossibilityAOut = describeUserMessage(USER1) + 
describeUserMessage(USER2);
+String scramPossibilityBOut = describeUserMessage(USER2) + 
describeUserMessage(USER1);
+describeUsers(
+quotaPossibilityAOut + scramPossibilityAOut,
+quotaPossibilityAOut + scramPossibilityBOut,
+quotaPossibilityBOut + scramPossibilityAOut,
+quotaPossibilityBOut + scramPossibilityBOut);
+
+// now delete configs, in opposite order, for user1 and 

Re: [PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


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


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,184 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {
+private static final String USER1 = "user1";
+private static final String USER2 = "user2";
+
+@Override
+public int brokerCount() {
+return 1;
+}
+
+static class ConfigCommandResult {
+public final String stdout;
+public final OptionalInt exitStatus;
+
+public ConfigCommandResult(String stdout) {
+this(stdout, OptionalInt.empty());
+}
+
+public ConfigCommandResult(String stdout, OptionalInt exitStatus) {
+this.stdout = stdout;
+this.exitStatus = exitStatus;
+}
+}
+
+private ConfigCommandResult runConfigCommandViaBroker(String...args) {
+ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+String utf8 = StandardCharsets.UTF_8.name();
+PrintStream printStream;
+try {
+printStream = new PrintStream(byteArrayOutputStream, true, utf8);
+} catch (UnsupportedEncodingException e) {
+throw new RuntimeException(e);
+}
+AtomicReference exitStatus = new 
AtomicReference<>(OptionalInt.empty());
+Exit.setExitProcedure((status, __) -> {
+exitStatus.set(OptionalInt.of((Integer) status));
+throw new RuntimeException();
+});
+
+List commandArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName(;
+commandArgs.addAll(Arrays.asList(args));
+try {
+Console.withOut(printStream, () -> {
+ConfigCommand.main(commandArgs.toArray(new String[0]));
+return null;
+});
+return new 
ConfigCommandResult(byteArrayOutputStream.toString(utf8));
+} catch (Exception e) {
+return new ConfigCommandResult("", exitStatus.get());
+} finally {
+printStream.close();
+Exit.resetExitProcedure();
+}
+}
+
+@ParameterizedTest
+@ValueSource(strings = {"kraft", "zk"})
+public void testUserScramCredentialsRequests(String quorum) throws 
Exception {
+createAndAlterUser(USER1);
+// now do the same thing for user2
+createAndAlterUser(USER2);
+
+// describe both
+// we don't know the order that quota or scram users come out, so we 
have 2 possibilities for each, 4 total
+String quotaPossibilityAOut = quotaMessage(USER1) + 
quotaMessage(USER2);
+String quotaPossibilityBOut = quotaMessage(USER2) + 
quotaMessage(USER1);
+String scramPossibilityAOut = describeUserMessage(USER1) + 
describeUserMessage(USER2);
+String scramPossibilityBOut = describeUserMessage(USER2) + 
describeUserMessage(USER1);
+describeUsers(
+quotaPossibilityAOut + scramPossibilityAOut,
+quotaPossibilityAOut + scramPossibilityBOut,
+quotaPossibilityBOut + scramPossibilityAOut,
+quotaPossibilityBOut + scramPossibilityBOut);
+
+// now delete configs, in opposite order, for user1 and 

Re: [PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


nizhikov commented on PR #15832:
URL: https://github.com/apache/kafka/pull/15832#issuecomment-2085194654

   @soarez Thanks for the valuable feedback. I create java version of 
waitUntilTrue method and used it in test. Please, take a look.


-- 
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-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


nizhikov commented on code in PR #15832:
URL: https://github.com/apache/kafka/pull/15832#discussion_r1584714610


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,178 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {
+private static final Logger log = 
LoggerFactory.getLogger(UserScramCredentialsCommandTest.class);
+
+@Override
+public int brokerCount() {
+return 1;
+}
+
+static class ConfigCommandResult {
+public final String stdout;
+public final OptionalInt exitStatus;
+
+public ConfigCommandResult(String stdout) {
+this(stdout, OptionalInt.empty());
+}
+
+public ConfigCommandResult(String stdout, OptionalInt exitStatus) {
+this.stdout = stdout;
+this.exitStatus = exitStatus;
+}
+}
+
+private ConfigCommandResult runConfigCommandViaBroker(String...args) 
throws UnsupportedEncodingException {
+ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+String utf8 = StandardCharsets.UTF_8.name();
+PrintStream printStream = new PrintStream(byteArrayOutputStream, true, 
utf8);
+AtomicReference exitStatus = new 
AtomicReference<>(OptionalInt.empty());
+Exit.setExitProcedure((status, __) -> {
+exitStatus.set(OptionalInt.of((Integer) status));
+throw new RuntimeException();
+});
+
+List commandArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName(;
+commandArgs.addAll(Arrays.asList(args));
+try {
+Console.withOut(printStream, () -> {
+ConfigCommand.main(commandArgs.toArray(new String[0]));
+return null;
+});
+return new 
ConfigCommandResult(byteArrayOutputStream.toString(utf8));
+} catch (Exception e) {
+log.debug("Exception running ConfigCommand " + String.join(" ", 
commandArgs), e);
+return new ConfigCommandResult("", exitStatus.get());
+} finally {
+printStream.close();
+Exit.resetExitProcedure();
+}
+}
+
+@ParameterizedTest
+@ValueSource(strings = {"kraft", "zk"})
+public void testUserScramCredentialsRequests(String quorum) throws 
Exception {
+String user1 = "user1";
+// create and describe a credential
+ConfigCommandResult result = runConfigCommandViaBroker("--user", 
user1, "--alter", "--add-config", 
"SCRAM-SHA-256=[iterations=4096,password=foo-secret]");
+String alterConfigsUser1Out = "Completed updating config for user " + 
user1 + ".\n";
+assertEquals(alterConfigsUser1Out, result.stdout);
+String scramCredentialConfigsUser1Out = "SCRAM credential configs for 
user-principal '" + user1 + "' are SCRAM-SHA-256=iterations=4096\n";
+TestUtils.waitForCondition(
+() -> Objects.equals(runConfigCommandViaBroker("--user", user1, 
"--describe").stdout, scramCredentialConfigsUser1Out),
+() -> "Failed to describe SCRAM credential change '" + user1 + 
"'");
+// create a user quota and describe the user again
+result = 

Re: [PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


nizhikov commented on code in PR #15832:
URL: https://github.com/apache/kafka/pull/15832#discussion_r1584629877


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,178 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {
+private static final Logger log = 
LoggerFactory.getLogger(UserScramCredentialsCommandTest.class);
+
+@Override
+public int brokerCount() {
+return 1;
+}
+
+static class ConfigCommandResult {
+public final String stdout;
+public final OptionalInt exitStatus;
+
+public ConfigCommandResult(String stdout) {
+this(stdout, OptionalInt.empty());
+}
+
+public ConfigCommandResult(String stdout, OptionalInt exitStatus) {
+this.stdout = stdout;
+this.exitStatus = exitStatus;
+}
+}
+
+private ConfigCommandResult runConfigCommandViaBroker(String...args) 
throws UnsupportedEncodingException {
+ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+String utf8 = StandardCharsets.UTF_8.name();
+PrintStream printStream = new PrintStream(byteArrayOutputStream, true, 
utf8);
+AtomicReference exitStatus = new 
AtomicReference<>(OptionalInt.empty());
+Exit.setExitProcedure((status, __) -> {
+exitStatus.set(OptionalInt.of((Integer) status));
+throw new RuntimeException();
+});
+
+List commandArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName(;
+commandArgs.addAll(Arrays.asList(args));
+try {
+Console.withOut(printStream, () -> {
+ConfigCommand.main(commandArgs.toArray(new String[0]));
+return null;
+});
+return new 
ConfigCommandResult(byteArrayOutputStream.toString(utf8));
+} catch (Exception e) {
+log.debug("Exception running ConfigCommand " + String.join(" ", 
commandArgs), e);

Review Comment:
   yes. removed



-- 
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-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


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


##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,178 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {

Review Comment:
   please try to use `ClusterTestExtensions`



##
core/src/test/java/kafka/admin/UserScramCredentialsCommandTest.java:
##
@@ -0,0 +1,178 @@
+/*
+ * 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.admin;
+
+import kafka.server.BaseRequestTest;
+import kafka.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import scala.Console;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalInt;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("dontUseSystemExit")
+public class UserScramCredentialsCommandTest extends BaseRequestTest {
+private static final Logger log = 
LoggerFactory.getLogger(UserScramCredentialsCommandTest.class);
+
+@Override
+public int brokerCount() {
+return 1;
+}
+
+static class ConfigCommandResult {
+public final String stdout;
+public final OptionalInt exitStatus;
+
+public ConfigCommandResult(String stdout) {
+this(stdout, OptionalInt.empty());
+}
+
+public ConfigCommandResult(String stdout, OptionalInt exitStatus) {
+this.stdout = stdout;
+this.exitStatus = exitStatus;
+}
+}
+
+private ConfigCommandResult runConfigCommandViaBroker(String...args) 
throws UnsupportedEncodingException {
+ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+String utf8 = StandardCharsets.UTF_8.name();
+PrintStream printStream = new PrintStream(byteArrayOutputStream, true, 
utf8);
+AtomicReference exitStatus = new 
AtomicReference<>(OptionalInt.empty());
+

Re: [PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


nizhikov commented on PR #15832:
URL: https://github.com/apache/kafka/pull/15832#issuecomment-2084909110

   Hello @chia7712 
   Can you, please, take a look?


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



[PR] KAFKA-14588 UserScramCredentialsCommandTest rewritten in java [kafka]

2024-04-30 Thread via GitHub


nizhikov opened a new pull request, #15832:
URL: https://github.com/apache/kafka/pull/15832

   This is second part of https://github.com/apache/kafka/pull/15417 
refactoring.
   PR intention - split big PR in parts to simplify review.
   PR contains UserScramCredentialsCommandTest rewritten in java
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


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