|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -68,6 +68,10 @@ public static void main(String[] args) throws Exception {
|
68 | 68 | testMemory("500m", "" + 500*MB);
|
69 | 69 | testMemory("1g", "" + 1024*MB);
|
70 | 70 |
|
| 71 | + // see https://docs.docker.com/config/containers/resource_constraints/ |
| 72 | + testSwapMemory("200m", "200m", "" + 0*MB, "" + 0*MB); |
| 73 | + testSwapMemory("200m", "300m", "" + 100*MB, "" + 100*MB); |
| 74 | + |
71 | 75 | testProcessInfo();
|
72 | 76 |
|
73 | 77 | testEnvironmentVariables();
|
@@ -211,6 +215,37 @@ private static void testMemory(String valueToSet, String expectedValue) throws E
|
211 | 215 | }
|
212 | 216 |
|
213 | 217 |
|
| 218 | + private static void testSwapMemory(String memValueToSet, String swapValueToSet, String expectedTotalValue, String expectedFreeValue) throws Exception { |
| 219 | + Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet); |
| 220 | + OutputAnalyzer out = DockerTestUtils.dockerRunJava( |
| 221 | + commonDockerOpts() |
| 222 | + .addDockerOpts("--memory=" + memValueToSet) |
| 223 | + .addDockerOpts("--memory-swap=" + swapValueToSet) |
| 224 | + .addClassOptions("jdk.SwapSpace")); |
| 225 | + out.shouldHaveExitValue(0) |
| 226 | + .shouldContain("totalSize = " + expectedTotalValue) |
| 227 | + .shouldContain("freeSize = "); |
| 228 | + List<String> ls = out.asLinesWithoutVMWarnings(); |
| 229 | + for (String cur : ls) { |
| 230 | + int idx = cur.indexOf("freeSize = "); |
| 231 | + if (idx != -1) { |
| 232 | + int startNbr = idx+11; |
| 233 | + int endNbr = cur.indexOf(' ', startNbr); |
| 234 | + if (endNbr == -1) endNbr = cur.length(); |
| 235 | + String freeSizeStr = cur.substring(startNbr, endNbr); |
| 236 | + long freeval = Long.parseLong(freeSizeStr); |
| 237 | + long totalval = Long.parseLong(expectedTotalValue); |
| 238 | + if (0 <= freeval && freeval <= totalval) { |
| 239 | + System.out.println("Found freeSize value " + freeval + " is fine"); |
| 240 | + } else { |
| 241 | + System.out.println("Found freeSize value " + freeval + " is bad"); |
| 242 | + throw new Exception("Found free size value is bad"); |
| 243 | + } |
| 244 | + } |
| 245 | + } |
| 246 | + } |
| 247 | + |
| 248 | + |
214 | 249 | private static void testProcessInfo() throws Exception {
|
215 | 250 | Common.logNewTestCase("ProcessInfo");
|
216 | 251 | DockerTestUtils.dockerRunJava(
|
|
0 commit comments