Skip to content

Commit 7ec1d5f

Browse files
committed
8377991: TestLimitsUpdating.java fails with runtime exception even after JDK-8370492 is fixed
Reviewed-by: sgehwolf Backport-of: e6582b2e80e31103bcda08d27fded72604f687d3
1 parent 3b47a4e commit 7ec1d5f

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

test/hotspot/jtreg/containers/docker/TestLimitsUpdating.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2023, Red Hat, Inc.
3-
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
44
*
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66
*
@@ -49,8 +49,12 @@
4949
import jdk.test.lib.containers.docker.DockerRunOptions;
5050
import jdk.test.lib.containers.docker.DockerTestUtils;
5151
import jdk.test.lib.process.OutputAnalyzer;
52+
import jtreg.SkippedException;
5253

5354
public class TestLimitsUpdating {
55+
private static final int CPU_PERIOD = 100_000;
56+
private static final int INITIAL_CPU_COUNT = 1;
57+
private static final int UPDATED_CPU_COUNT = 2;
5458
private static final String TARGET_CONTAINER = "limitsUpdatingHS_" + Runtime.getRuntime().version().major();
5559
private static final String imageName = Common.imageName("limitsUpdating");
5660

@@ -68,6 +72,10 @@ public static void main(String[] args) throws Exception {
6872
}
6973

7074
private static void testLimitUpdates() throws Exception {
75+
if (Runtime.getRuntime().availableProcessors() < UPDATED_CPU_COUNT) {
76+
throw new SkippedException("Need at least " + UPDATED_CPU_COUNT
77+
+ " available CPUs to test CPU limit updates");
78+
}
7179
File sharedtmpdir = new File("test-sharedtmp");
7280
File flag = new File(sharedtmpdir, "limitsUpdated"); // shared with LimitUpdateChecker
7381
File started = new File(sharedtmpdir, "started"); // shared with LimitUpdateChecker
@@ -77,8 +85,8 @@ private static void testLimitUpdates() throws Exception {
7785
DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "LimitUpdateChecker");
7886
opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
7987
opts.addDockerOpts("--volume", sharedtmpdir.getAbsolutePath() + ":/tmp");
80-
opts.addDockerOpts("--cpu-period", "100000");
81-
opts.addDockerOpts("--cpu-quota", "200000");
88+
opts.addDockerOpts("--cpu-period", Integer.toString(CPU_PERIOD));
89+
opts.addDockerOpts("--cpu-quota", Integer.toString(INITIAL_CPU_COUNT * CPU_PERIOD));
8290
opts.addDockerOpts("--memory", "500m");
8391
opts.addDockerOpts("--memory-swap", "500m");
8492
opts.addDockerOpts("--name", TARGET_CONTAINER);
@@ -103,7 +111,7 @@ public void run() {
103111
Thread.sleep(100);
104112
}
105113

106-
final List<String> containerCommand = getContainerUpdate(300_000, 100_000, "300m");
114+
final List<String> containerCommand = getContainerUpdate(UPDATED_CPU_COUNT * CPU_PERIOD, CPU_PERIOD, "300m");
107115
// Run the update command so as to increase resources once the container signaled it has started.
108116
Thread t2 = new Thread() {
109117
public void run() {
@@ -126,8 +134,8 @@ public void run() {
126134

127135
// Do assertions based on the output in target container
128136
OutputAnalyzer targetOut = out[0];
129-
targetOut.shouldContain("active_processor_count: 2"); // initial value
130-
targetOut.shouldContain("active_processor_count: 3"); // updated value
137+
targetOut.shouldContain("active_processor_count: 1"); // initial value
138+
targetOut.shouldContain("active_processor_count: 2"); // updated value
131139
targetOut.shouldContain("memory_limit_in_bytes: 512000 k"); // initial value
132140
targetOut.shouldContain("memory_and_swap_limit_in_bytes: 512000 k"); // initial value
133141
targetOut.shouldContain("memory_limit_in_bytes: 307200 k"); // updated value

test/jdk/jdk/internal/platform/docker/TestLimitsUpdating.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2023, Red Hat, Inc.
3-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
44
*
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66
*
@@ -48,9 +48,13 @@
4848
import jdk.test.lib.containers.docker.DockerRunOptions;
4949
import jdk.test.lib.containers.docker.DockerTestUtils;
5050
import jdk.test.lib.process.OutputAnalyzer;
51+
import jtreg.SkippedException;
5152

5253
public class TestLimitsUpdating {
5354
private static final long M = 1024 * 1024;
55+
private static final int CPU_PERIOD = 100_000;
56+
private static final int INITIAL_CPU_COUNT = 1;
57+
private static final int UPDATED_CPU_COUNT = 2;
5458
private static final String TARGET_CONTAINER = "limitsUpdatingJDK_" + Runtime.getRuntime().version().major();
5559
private static final String imageName = Common.imageName("limitsUpdatingJDK");
5660

@@ -67,6 +71,10 @@ public static void main(String[] args) throws Exception {
6771
}
6872

6973
private static void testLimitUpdates() throws Exception {
74+
if (Runtime.getRuntime().availableProcessors() < UPDATED_CPU_COUNT) {
75+
throw new SkippedException("Need at least " + UPDATED_CPU_COUNT
76+
+ " available CPUs to test CPU limit updates");
77+
}
7078
File sharedtmpdir = new File("jdk-sharedtmp");
7179
File flag = new File(sharedtmpdir, "limitsUpdated"); // shared with LimitUpdateChecker
7280
File started = new File(sharedtmpdir, "started"); // shared with LimitUpdateChecker
@@ -76,8 +84,8 @@ private static void testLimitUpdates() throws Exception {
7684
DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "LimitUpdateChecker");
7785
opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
7886
opts.addDockerOpts("--volume", sharedtmpdir.getAbsolutePath() + ":/tmp");
79-
opts.addDockerOpts("--cpu-period", "100000");
80-
opts.addDockerOpts("--cpu-quota", "200000");
87+
opts.addDockerOpts("--cpu-period", Integer.toString(CPU_PERIOD));
88+
opts.addDockerOpts("--cpu-quota", Integer.toString(INITIAL_CPU_COUNT * CPU_PERIOD));
8189
opts.addDockerOpts("--memory", "500m");
8290
opts.addDockerOpts("--memory-swap", "500m");
8391
opts.addDockerOpts("--name", TARGET_CONTAINER);
@@ -106,7 +114,7 @@ public void run() {
106114
Thread.sleep(100);
107115
}
108116

109-
final List<String> containerCommand = getContainerUpdate(300_000, 100_000, "300m");
117+
final List<String> containerCommand = getContainerUpdate(UPDATED_CPU_COUNT * CPU_PERIOD, CPU_PERIOD, "300m");
110118
// Run the update command so as to increase resources once the container signaled it has started.
111119
Thread t2 = new Thread() {
112120
public void run() {
@@ -129,10 +137,10 @@ public void run() {
129137

130138
// Do assertions based on the output in target container
131139
OutputAnalyzer targetOut = out[0];
132-
targetOut.shouldContain("Runtime.availableProcessors: 2"); // initial value
133-
targetOut.shouldContain("OperatingSystemMXBean.getAvailableProcessors: 2"); // initial value
134-
targetOut.shouldContain("Runtime.availableProcessors: 3"); // updated value
135-
targetOut.shouldContain("OperatingSystemMXBean.getAvailableProcessors: 3"); // updated value
140+
targetOut.shouldContain("Runtime.availableProcessors: 1"); // initial value
141+
targetOut.shouldContain("OperatingSystemMXBean.getAvailableProcessors: 1"); // initial value
142+
targetOut.shouldContain("Runtime.availableProcessors: 2"); // updated value
143+
targetOut.shouldContain("OperatingSystemMXBean.getAvailableProcessors: 2"); // updated value
136144
long memoryInBytes = 500 * M;
137145
targetOut.shouldContain("Metrics.getMemoryLimit() == " + memoryInBytes); // initial value
138146
targetOut.shouldContain("OperatingSystemMXBean.getTotalMemorySize: " + memoryInBytes); // initial value

0 commit comments

Comments
 (0)