Skip to content

Instantly share code, notes, and snippets.

@kiview
Created August 15, 2023 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiview/d7380bdf05a17bc1faa454278b79a80b to your computer and use it in GitHub Desktop.
Save kiview/d7380bdf05a17bc1faa454278b79a80b to your computer and use it in GitHub Desktop.
package org.testcontainers;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy;
public class JavaGCTest {
@Test
public void shouldUseG1GC() {
try (GenericContainer<?> java = new GenericContainer<>("eclipse-temurin:17-jdk-focal")
.withStartupCheckStrategy(new OneShotStartupCheckStrategy())
.withCommand("java", "-XX:+PrintFlagsFinal", "-version")
.withCreateContainerCmdModifier(cmd -> cmd.getHostConfig().withMemory(1024L * 1024L * 2000))) {
java.start();
String logs = java.getLogs();
Assertions.assertThat(logs).containsPattern(".*G1GC.*true.*");
}
}
@Test
public void shouldUseSerialGc() {
try (GenericContainer<?> java = new GenericContainer<>("eclipse-temurin:17-jdk-focal")
.withStartupCheckStrategy(new OneShotStartupCheckStrategy())
.withCommand("java", "-XX:+PrintFlagsFinal", "-version")
.withCreateContainerCmdModifier(cmd -> cmd.getHostConfig().withMemory(1024L * 1024L * 1000))) {
java.start();
String logs = java.getLogs();
Assertions.assertThat(logs).containsPattern(".*SerialGC.*true.*");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment