forked from dragonwell-project/dragonwell8_jdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Add ResourceContainerMXBean, currently only support CPU resource amount. Test Plan: jtreg test/com/alibaba/ Reviewed-by: yuleil, zhengxiaolinX Issue: dragonwell-project/dragonwell8#206
- Loading branch information
joeyleeeeeee97
authored and
joeylee.lz
committed
Feb 8, 2021
1 parent
174b3d7
commit 84a16b9
Showing
5 changed files
with
69 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* @test | ||
* @library /lib/testlibrary | ||
* @summary test RcmMXBeanTest | ||
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseWisp2 -XX:ActiveProcessorCount=4 RcmMXBeanTest | ||
*/ | ||
|
||
import com.alibaba.management.ResourceContainerMXBean; | ||
import com.alibaba.rcm.ResourceContainer; | ||
import com.alibaba.rcm.ResourceType; | ||
|
||
import javax.management.MBeanServer; | ||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.util.Collections; | ||
|
||
import static jdk.testlibrary.Asserts.*; | ||
|
||
public class RcmMXBeanTest { | ||
static ResourceContainerMXBean resourceContainerMXBean; | ||
|
||
public static void main(String[] args) throws Exception { | ||
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); | ||
try { | ||
resourceContainerMXBean = ManagementFactory.newPlatformMXBeanProxy(mbs, | ||
"com.alibaba.management:type=ResourceContainer", ResourceContainerMXBean.class); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
for (int i = 0; i < 3; i++) { | ||
ResourceContainer rc1 = WispResourceContainerFactory.instance() | ||
.createContainer(Collections.singletonList(ResourceType.CPU_PERCENT.newConstraint(80))); | ||
|
||
rc1.run(() -> { | ||
new Thread(() -> { | ||
while (true) { | ||
Thread.yield(); | ||
} | ||
}).start(); | ||
}); | ||
Thread.sleep(1000); | ||
} | ||
|
||
assertTrue(resourceContainerMXBean.getAllContainerIds().size() == 3); | ||
|
||
|
||
for (long id : resourceContainerMXBean.getAllContainerIds()) { | ||
assertEQ(resourceContainerMXBean.getConstraintsById(id).size(), 1L); | ||
assertEQ(resourceContainerMXBean.getConstraintsById(id).get(0), 80L); | ||
assertGreaterThan(resourceContainerMXBean.getCPUResourceConsumedAmount(id), 0L); | ||
} | ||
} | ||
} |