heesung-sn commented on code in PR #17820:
URL: https://github.com/apache/pulsar/pull/17820#discussion_r985116183
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LinuxInfoUtilsTest.java:
##########
@@ -0,0 +1,31 @@
+package org.apache.pulsar.broker.loadbalance;
+
+import static org.testng.Assert.assertEquals;
+import lombok.extern.slf4j.Slf4j;
+import org.testng.annotations.Test;
+
+@Slf4j
+@Test(groups = "broker")
+public class LinuxInfoUtilsTest {
+
+ /**
+ * simulate reading contents in /sys/fs/cgroup/cpuset/cpuset.cpus to get
the number of Cpus.
+ */
+ @Test
+ public void testGetTotalCpuCount() {
+ int totalCpuCount=0;
+ String CPU_CPUSET_CPUS = "0-2,16,20-30";
+ String[] ranges = CPU_CPUSET_CPUS.split(",");
+ for (String range : ranges) {
Review Comment:
Can you try Mockito.mockStatic like the below to mock the file read part? I
don't think we should copy the logic in the unit test.(when the logic changes
in the code, this unit test cannot catch it)
```
MockedStatic<[LinuxInfoUtils> linuxInfoUtils =
Mockito.mockStatic(LinuxInfoUtils.class))
linuxInfoUtils.when(() ->
LinuxInfoUtils.readTrimStringFromFile(any())
.thenReturn("0-2,16,20-30");
LinuxInfoUtilsTest.getTotalCpuCount();
```
--
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]