Skip to content

Commit

Permalink
8229182: runtime/containers/docker/TestMemoryAwareness.java test fail…
Browse files Browse the repository at this point in the history
…s on SLES12

Reviewed-by: clanger, mseledtsov
  • Loading branch information
MBaesken committed Sep 3, 2019
1 parent 7cb2819 commit a41b9a7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
27 changes: 19 additions & 8 deletions test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -37,7 +37,7 @@
import jdk.test.lib.containers.docker.Common;
import jdk.test.lib.containers.docker.DockerRunOptions;
import jdk.test.lib.containers.docker.DockerTestUtils;

import jdk.test.lib.process.OutputAnalyzer;

public class TestMemoryAwareness {
private static final String imageName = Common.imageName("memory");
Expand Down Expand Up @@ -98,15 +98,26 @@ private static void testMemorySoftLimit(String valueToSet, String expectedTraceV
private static void testOOM(String dockerMemLimit, int sizeToAllocInMb) throws Exception {
Common.logNewTestCase("OOM");

// add "--memory-swappiness 0" so as to disable anonymous page swapping.
DockerRunOptions opts = Common.newOpts(imageName, "AttemptOOM")
.addDockerOpts("--memory", dockerMemLimit, "--memory-swap", dockerMemLimit);
.addDockerOpts("--memory", dockerMemLimit, "--memory-swappiness", "0", "--memory-swap", dockerMemLimit);
opts.classParams.add("" + sizeToAllocInMb);

DockerTestUtils.dockerRunJava(opts)
.shouldHaveExitValue(1)
.shouldContain("Entering AttemptOOM main")
.shouldNotContain("AttemptOOM allocation successful")
.shouldContain("java.lang.OutOfMemoryError");
// make sure we avoid inherited Xmx settings from the jtreg vmoptions
// set Xmx ourselves instead
System.out.println("sizeToAllocInMb is:" + sizeToAllocInMb + " sizeToAllocInMb/2 is:" + sizeToAllocInMb/2);
String javaHeapSize = sizeToAllocInMb/2 + "m";
opts.addJavaOptsAppended("-Xmx" + javaHeapSize);

OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts);

if (out.getExitValue() == 0) {
throw new RuntimeException("We exited successfully, but we wanted to provoke an OOM inside the container");
}

out.shouldContain("Entering AttemptOOM main")
.shouldNotContain("AttemptOOM allocation successful")
.shouldContain("java.lang.OutOfMemoryError");
}

}
15 changes: 11 additions & 4 deletions test/lib/jdk/test/lib/containers/docker/DockerRunOptions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,11 +31,13 @@
// in test environment.
public class DockerRunOptions {
public String imageNameAndTag;
public ArrayList<String> dockerOpts = new ArrayList<String>();
public ArrayList<String> dockerOpts = new ArrayList<>();
public String command; // normally a full path to java
public ArrayList<String> javaOpts = new ArrayList<String>();
public ArrayList<String> javaOpts = new ArrayList<>();
// more java options, but to be set AFTER the test Java options
public ArrayList<String> javaOptsAppended = new ArrayList<>();
public String classToRun; // class or "-version"
public ArrayList<String> classParams = new ArrayList<String>();
public ArrayList<String> classParams = new ArrayList<>();

public boolean tty = true;
public boolean removeContainerAfterUse = true;
Expand Down Expand Up @@ -70,6 +72,11 @@ public DockerRunOptions addJavaOpts(String... opts) {
return this;
}

public DockerRunOptions addJavaOptsAppended(String... opts) {
Collections.addAll(javaOptsAppended, opts);
return this;
}

public DockerRunOptions addClassOptions(String... opts) {
Collections.addAll(classParams,opts);
return this;
Expand Down
3 changes: 1 addition & 2 deletions test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@
import jdk.test.lib.Container;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jtreg.SkippedException;


public class DockerTestUtils {
private static final String FS = File.separator;
private static boolean isDockerEngineAvailable = false;
private static boolean wasDockerEngineChecked = false;

Expand Down Expand Up @@ -212,6 +210,7 @@ public static List<String> buildJavaCommand(DockerRunOptions opts) throws Except
if (opts.appendTestJavaOptions) {
Collections.addAll(cmd, Utils.getTestJavaOpts());
}
cmd.addAll(opts.javaOptsAppended);

cmd.add(opts.classToRun);
cmd.addAll(opts.classParams);
Expand Down

0 comments on commit a41b9a7

Please sign in to comment.