|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2017, 2019, 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
|
@@ -133,15 +133,26 @@ private static void testMemorySoftLimit(String valueToSet, String expectedTraceV
|
133 | 133 | private static void testOOM(String dockerMemLimit, int sizeToAllocInMb) throws Exception {
|
134 | 134 | Common.logNewTestCase("OOM");
|
135 | 135 |
|
| 136 | + // add "--memory-swappiness 0" so as to disable anonymous page swapping. |
136 | 137 | DockerRunOptions opts = Common.newOpts(imageName, "AttemptOOM")
|
137 |
| - .addDockerOpts("--memory", dockerMemLimit, "--memory-swap", dockerMemLimit); |
| 138 | + .addDockerOpts("--memory", dockerMemLimit, "--memory-swappiness", "0", "--memory-swap", dockerMemLimit); |
138 | 139 | opts.classParams.add("" + sizeToAllocInMb);
|
139 | 140 |
|
140 |
| - DockerTestUtils.dockerRunJava(opts) |
141 |
| - .shouldHaveExitValue(1) |
142 |
| - .shouldContain("Entering AttemptOOM main") |
143 |
| - .shouldNotContain("AttemptOOM allocation successful") |
144 |
| - .shouldContain("java.lang.OutOfMemoryError"); |
| 141 | + // make sure we avoid inherited Xmx settings from the jtreg vmoptions |
| 142 | + // set Xmx ourselves instead |
| 143 | + System.out.println("sizeToAllocInMb is:" + sizeToAllocInMb + " sizeToAllocInMb/2 is:" + sizeToAllocInMb/2); |
| 144 | + String javaHeapSize = sizeToAllocInMb/2 + "m"; |
| 145 | + opts.addJavaOptsAppended("-Xmx" + javaHeapSize); |
| 146 | + |
| 147 | + OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts); |
| 148 | + |
| 149 | + if (out.getExitValue() == 0) { |
| 150 | + throw new RuntimeException("We exited successfully, but we wanted to provoke an OOM inside the container"); |
| 151 | + } |
| 152 | + |
| 153 | + out.shouldContain("Entering AttemptOOM main") |
| 154 | + .shouldNotContain("AttemptOOM allocation successful") |
| 155 | + .shouldContain("java.lang.OutOfMemoryError"); |
145 | 156 | }
|
146 | 157 |
|
147 | 158 | private static void testOperatingSystemMXBeanAwareness(String memoryAllocation, String expectedMemory,
|
|
0 commit comments