feat(emr): have the JVMs in EMR containers trust Floci's CA (#6926)

With TLS on, every container Floci launches gets the CA bundle and the
SSL_CERT_FILE family of variables, but the JVM reads none of them. So
in the docker runner mode a Spark job's own SDK clients that ignore
AWS_ENDPOINT_URL, the AWS SDK for Java 1.x's or an older 2.x's,
failed with "PKIX path building failed" against Floci's HTTPS, even
with FLOCI_DNS_SPOOF_AWS_ENDPOINTS sending AWS's endpoint names to
Floci. A job could only reach Floci over its HTTP endpoint.

Floci now also writes the bundle's certificates as a PKCS12 trust
store at boot, floci-ca-bundle.p12 beside the bundle. A launcher whose
workload is Java can copy it into a container before the container
starts (ContainerLifecycleManager.copyJavaTrustStore) and point the
container's JVMs at it through JAVA_TOOL_OPTIONS, with a shell line
that does so only when the file is there. The store has no password
and the line gives only its path, so a trust store a job or an image
names itself replaces Floci's, with that store's own type and
password. EMR Serverless job runs and EMR steps copy it into the
driver's container ahead of spark-submit or the step's command, and
the bootstrap actions' container gets it for its actions, then drops
it before the image is kept. Other services' containers are unchanged.

JAVA_TOOL_OPTIONS rather than spark.driver.extraJavaOptions, since
setting that key would replace what the image's spark-defaults.conf
gives it, and a job's own value would drop Floci's. Each JVM prints
"Picked up JAVA_TOOL_OPTIONS: ..." on its standard error, as the docs
now say.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-29 07:50:46 -05:00
1 parent c4ae11c414
commit c9bc1e7cb8
13 files changed
+472 -47

No files matched your search

@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.config;
import io.github.hectorvent.floci.core.common.Pem;
import io.github.hectorvent.floci.services.acm.CertificateGenerator;
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
import io.github.hectorvent.floci.services.lambda.launcher.BootstrapProcess;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -12,6 +13,8 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.GeneralSecurityException;
@@ -21,8 +24,12 @@ import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -260,6 +267,137 @@ class ContainerCaBundleTest {
assertEquals(ContainerCaBundle.env(), ContainerCaBundle.appendEnv(List.of()));
}
@Test
void theJavaTrustStoreHoldsEveryCertificateOfTheBundleAsATrustedEntry() throws Exception {
Path tlsDir = tempDir.resolve("tls");
FlociCertificateAuthority ca = FlociCertificateAuthority.loadOrCreate(tlsDir);
Path bundle = ContainerCaBundle.write(tlsDir, ca.certificatePath());
Path trustStore = ContainerCaBundle.writeJavaTrustStore(bundle);
assertEquals(tlsDir.resolve("floci-ca-bundle.p12"), trustStore);
// Loaded as a JVM given only its path loads it: the default store type, and no password.
assertEquals("-Djavax.net.ssl.trustStore=/etc/floci-ca-bundle.p12", ContainerCaBundle.JAVA_TRUST_OPTIONS);
KeyStore loaded = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream in = Files.newInputStream(trustStore)) {
loaded.load(in, null);
}
List<X509Certificate> held = new ArrayList<>();
for (String alias : Collections.list(loaded.aliases())) {
assertTrue(loaded.isCertificateEntry(alias), alias + " is a trusted certificate");
held.add((X509Certificate) loaded.getCertificate(alias));
}
assertEquals(Set.copyOf(parseAll(Files.readAllBytes(bundle))), Set.copyOf(held));
assertTrue(held.contains(ca.certificate()), "Floci's anchor");
try (Stream<Path> files = Files.list(tlsDir)) {
assertTrue(files.noneMatch(file -> file.getFileName().toString().endsWith(".tmp")),
"no temp file left behind");
}
}
@Test
void javaTrustStoreHostPathIsEmptyUntilTheBootWritesIt() throws Exception {
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.tls().enabled()).thenReturn(true);
when(config.storage().persistentPath()).thenReturn(tempDir.toString());
Path tlsDir = tempDir.resolve("tls");
FlociCertificateAuthority ca = FlociCertificateAuthority.loadOrCreate(tlsDir);
Path bundle = ContainerCaBundle.write(tlsDir, ca.certificatePath());
assertEquals(Optional.empty(), ContainerCaBundle.javaTrustStoreHostPath(config));
Path trustStore = ContainerCaBundle.writeJavaTrustStore(bundle);
assertEquals(Optional.of(trustStore), ContainerCaBundle.javaTrustStoreHostPath(config));
when(config.tls().enabled()).thenReturn(false);
assertEquals(Optional.empty(), ContainerCaBundle.javaTrustStoreHostPath(config));
}
@Test
void theShellLinePointsTheJvmsAtTheTrustStoreOnlyWhenItIsThere() throws Exception {
Path trustStore = Files.writeString(tempDir.resolve("floci-ca-bundle.p12"), "trust store");
String line = ContainerCaBundle.JAVA_TRUST_SHELL_LINE
.replace(ContainerCaBundle.JAVA_TRUST_STORE_PATH, trustStore.toString());
String options = ContainerCaBundle.JAVA_TRUST_OPTIONS
.replace(ContainerCaBundle.JAVA_TRUST_STORE_PATH, trustStore.toString());
assertEquals(options, javaToolOptionsAfter(line, null));
// Options already there come after Floci's, so a trust store of their own wins.
assertEquals(options + " -Djavax.net.ssl.trustStore=/own.p12",
javaToolOptionsAfter(line, "-Djavax.net.ssl.trustStore=/own.p12"));
Files.delete(trustStore);
assertEquals("unset", javaToolOptionsAfter(line, null));
assertEquals("-Xss2m", javaToolOptionsAfter(line, "-Xss2m"));
}
@Test
void aJvmTrustsTheStoreByItsPathAloneAndAStoreAJobNamesReplacesItWhole() throws Exception {
Path tlsDir = tempDir.resolve("tls");
FlociCertificateAuthority ca = FlociCertificateAuthority.loadOrCreate(tlsDir);
Path bundle = ContainerCaBundle.write(tlsDir, ca.certificatePath());
String line = ContainerCaBundle.JAVA_TRUST_SHELL_LINE.replace(ContainerCaBundle.JAVA_TRUST_STORE_PATH,
ContainerCaBundle.writeJavaTrustStore(bundle).toString());
int bundled = Set.copyOf(parseAll(Files.readAllBytes(bundle))).size();
// A job's own store, under a password of its own, which it names by its path alone.
Path own = tempDir.resolve("own.jks");
KeyStore ownStore = KeyStore.getInstance("JKS");
ownStore.load(null, null);
ownStore.setCertificateEntry("own", ca.certificate());
try (OutputStream out = Files.newOutputStream(own)) {
ownStore.store(out, "s3cret".toCharArray());
}
assertEquals(bundled, anchorsTrustedAfter(line, null));
assertEquals(1, anchorsTrustedAfter(line, "-Djavax.net.ssl.trustStore=" + own));
// A password or a type a job gives for the JDK's own store still reads Floci's.
assertEquals(bundled, anchorsTrustedAfter(line, "-Djavax.net.ssl.trustStorePassword=changeit"));
assertEquals(bundled, anchorsTrustedAfter(line, "-Djavax.net.ssl.trustStoreType=JKS"));
}
/** Run in a JVM of its own: prints how many anchors that JVM trusts by default, as its options say. */
public static final class TrustedAnchors {
public static void main(String[] args) throws GeneralSecurityException {
TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
factory.init((KeyStore) null);
int anchors = 0;
for (TrustManager manager : factory.getTrustManagers()) {
if (manager instanceof X509TrustManager x509) {
anchors += x509.getAcceptedIssuers().length;
}
}
System.out.println("trusted anchors " + anchors);
}
}
// JAVA_TOOL_OPTIONS as a shell that ran line leaves it, starting from existing, or from none when null.
private static String javaToolOptionsAfter(String line, String existing) throws Exception {
return runAfter(line, existing, "printf %s \"${JAVA_TOOL_OPTIONS-unset}\"");
}
// How many anchors a JVM a shell starts after line trusts, JAVA_TOOL_OPTIONS starting as javaToolOptionsAfter's.
private static int anchorsTrustedAfter(String line, String existing) throws Exception {
String java = Path.of(System.getProperty("java.home"), "bin", "java").toString();
String classes = Path.of(TrustedAnchors.class.getProtectionDomain().getCodeSource().getLocation().toURI())
.toString();
String output = runAfter(line, existing, "exec \"$@\"", java, "-cp", classes, TrustedAnchors.class.getName());
Matcher anchors = Pattern.compile("trusted anchors (\\d+)").matcher(output);
assertTrue(anchors.find(), output);
return Integer.parseInt(anchors.group(1));
}
// What script, run by a shell after line with arguments as "$@", prints, JAVA_TOOL_OPTIONS starting from
// existing, or from none when null.
private static String runAfter(String line, String existing, String script, String... arguments) throws Exception {
List<String> command = new ArrayList<>(List.of("bash", "-c", line + "\n" + script, "floci"));
command.addAll(List.of(arguments));
ProcessBuilder shell = new ProcessBuilder(command);
shell.environment().remove("JAVA_TOOL_OPTIONS");
if (existing != null) {
shell.environment().put("JAVA_TOOL_OPTIONS", existing);
}
BootstrapProcess.Result ended = BootstrapProcess.run(shell);
assertEquals(0, ended.exit(), ended.output());
return ended.output();
}
private static List<X509Certificate> parseAll(byte[] pem) throws Exception {
List<X509Certificate> certificates = new ArrayList<>();
for (Certificate certificate : CertificateFactory.getInstance("X.509").generateCertificates(new ByteArrayInputStream(pem))) {
@@ -47,6 +47,21 @@ class TlsConfigSourceContainerCaBundleTest {
assertTrue(pem.endsWith(caPem), "the local CA is the last entry");
assertTrue(pem.indexOf("-----BEGIN CERTIFICATE-----") < pem.lastIndexOf("-----BEGIN CERTIFICATE-----"),
"public roots precede the CA");
assertTrue(Files.isRegularFile(tempDir.resolve("tls/floci-ca-bundle.p12")), "Java trust store written at boot");
}
@Test
void aJavaTrustStoreThatCannotBeWrittenLeavesTheBundleAndTheBoot() throws Exception {
// A directory where the trust store goes, with something in it, so it cannot be replaced.
Files.writeString(Files.createDirectories(tempDir.resolve("tls/floci-ca-bundle.p12")).resolve("x"), "x");
System.setProperty("floci.tls.enabled", "true");
System.setProperty("floci.tls.self-signed", "true");
System.setProperty("floci.storage.persistent-path", tempDir.toString());
new TlsConfigSource();
assertTrue(Files.isRegularFile(tempDir.resolve("tls/floci-ca-bundle.pem")), "bundle written at boot");
assertTrue(Files.isDirectory(tempDir.resolve("tls/floci-ca-bundle.p12")), "the boot left the obstacle alone");
}
@Test
@@ -36,6 +36,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -270,20 +271,70 @@ class ContainerLifecycleManagerCaBundleTest {
verify(dockerClient, times(1)).copyArchiveToContainerCmd(anyString());
}
@Test
void theJavaTrustStoreIsCopiedBesideTheBundleWhenALauncherAsks() throws Exception {
when(tlsConfig.enabled()).thenReturn(true);
byte[] trustStore = {0x30, (byte) 0x82, 0x01, 0x02};
Files.write(Files.createDirectories(tempDir.resolve("tls")).resolve("floci-ca-bundle.p12"), trustStore);
CopyArchiveToContainerCmd copyCmd = mock(CopyArchiveToContainerCmd.class, RETURNS_SELF);
when(dockerClient.copyArchiveToContainerCmd("container-id")).thenReturn(copyCmd);
List<InputStream> streams = new ArrayList<>();
when(copyCmd.withTarInputStream(any(InputStream.class))).thenAnswer(invocation -> {
streams.add(invocation.getArgument(0));
return copyCmd;
});
when(copyCmd.exec()).thenAnswer(invocation -> {
assertSingleFileArchive(streams.getLast(), "floci-ca-bundle.p12", trustStore);
return null;
});
assertTrue(manager().copyJavaTrustStore("container-id"));
verify(copyCmd).withRemotePath("/etc");
verify(copyCmd).exec();
}
@Test
void noJavaTrustStoreIsCopiedWithTlsOffOrWithoutOneFromTheBoot() throws Exception {
when(tlsConfig.enabled()).thenReturn(true);
writeBundle();
assertFalse(manager().copyJavaTrustStore("container-id"), "the boot wrote no trust store");
Files.write(tempDir.resolve("tls").resolve("floci-ca-bundle.p12"), new byte[] {1});
when(tlsConfig.enabled()).thenReturn(false);
assertFalse(manager().copyJavaTrustStore("container-id"), "TLS is off");
verify(dockerClient, never()).copyArchiveToContainerCmd(anyString());
}
@Test
void aJavaTrustStoreThatCannotBeCopiedIsReportedMissing() throws Exception {
when(tlsConfig.enabled()).thenReturn(true);
Files.write(Files.createDirectories(tempDir.resolve("tls")).resolve("floci-ca-bundle.p12"), new byte[] {1});
CopyArchiveToContainerCmd copyCmd = mock(CopyArchiveToContainerCmd.class, RETURNS_SELF);
when(dockerClient.copyArchiveToContainerCmd("container-id")).thenReturn(copyCmd);
when(copyCmd.exec()).thenThrow(new NotFoundException("Could not find the file /etc in container"));
assertFalse(manager().copyJavaTrustStore("container-id"));
}
private Path writeBundle() throws Exception {
Path tlsDir = Files.createDirectories(tempDir.resolve("tls"));
return Files.writeString(tlsDir.resolve("floci-ca-bundle.pem"), BUNDLE_PEM);
}
private static void assertBundleArchive(InputStream stream) throws IOException {
assertSingleFileArchive(stream, "floci-ca-bundle.pem", BUNDLE_PEM.getBytes(StandardCharsets.UTF_8));
}
private static void assertSingleFileArchive(InputStream stream, String name, byte[] content) throws IOException {
byte[] archive = stream.readAllBytes();
try (TarArchiveInputStream in = new TarArchiveInputStream(new ByteArrayInputStream(archive))) {
TarArchiveEntry entry = in.getNextEntry();
assertNotNull(entry, "every attempt must begin with a complete tar header");
assertEquals("floci-ca-bundle.pem", entry.getName());
assertEquals(name, entry.getName());
assertEquals(0644, entry.getMode() & 0777, "world-readable, so a non-root USER can read it");
assertArrayEquals(BUNDLE_PEM.getBytes(StandardCharsets.UTF_8), in.readAllBytes());
assertNull(in.getNextEntry(), "the archive holds only the bundle");
assertArrayEquals(content, in.readAllBytes());
assertNull(in.getNextEntry(), "the archive holds only " + name);
}
}
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.emr;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.ExecCreateCmd;
import com.github.dockerjava.api.model.Image;
import io.github.hectorvent.floci.config.ContainerCaBundle;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
@@ -23,6 +24,7 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -142,6 +144,26 @@ class EmrBootstrapRunnerTest {
verify(lifecycle).stopAndRemove(CONTAINER, null, 0);
}
@Test
void theActionsJvmsTrustFlocisCaWhoseTrustStoreIsNotKeptInTheImage() {
List<List<String>> commands = ContainerExecStubs.completeEveryExec(docker, CONTAINER, 0, "", "");
List<Integer> execsBeforeTheCopy = new ArrayList<>();
when(lifecycle.copyJavaTrustStore(CONTAINER)).thenAnswer(copy -> {
execsBeforeTheCopy.add(commands.size());
return true;
});
runner.run(bootstrap(null, action("s3://bucket/bootstrap/install.sh")), () -> false);
// In once the container is up, before the first action runs, which points its JVMs at it.
assertEquals(List.of(0), execsBeforeTheCopy);
assertTrue(commands.get(0).get(2).startsWith(ContainerCaBundle.JAVA_TRUST_SHELL_LINE + "\n"));
// Each step's container gets its own, so the image goes without it.
assertEquals(2, commands.size());
assertTrue(commands.get(1).get(2).contains("rm -f ") && commands.get(1).get(2).contains(
" " + ContainerCaBundle.JAVA_TRUST_STORE_PATH + ";"), commands.get(1).get(2));
}
@Test
void aFailingActionEndsTheBootstrapThereAndNothingIsKept() {
List<List<String>> commands = ContainerExecStubs.completeEveryExec(docker, CONTAINER, List.of(0L, 3L), "", "");
@@ -202,6 +224,24 @@ class EmrBootstrapRunnerTest {
verify(lifecycle, never()).commit(any(), any(), any(), any(), any());
}
@Test
void aClusterThatEndsWhileTheTrustStoreIsCopiedRunsNoAction() {
List<List<String>> commands = ContainerExecStubs.completeEveryExec(docker, CONTAINER, 0, "", "");
AtomicBoolean ended = new AtomicBoolean();
when(lifecycle.copyJavaTrustStore(CONTAINER)).thenAnswer(copy -> {
ended.set(true);
return true;
});
BootstrapRunner.Outcome outcome = runner.run(bootstrap(null, action("s3://bucket/bootstrap/install.sh")),
ended::get);
assertEquals(BootstrapRunner.Outcome.halted(), outcome);
assertTrue(commands.isEmpty());
verify(lifecycle, never()).commit(any(), any(), any(), any(), any());
verify(lifecycle).stopAndRemove(CONTAINER, null, 0);
}
@Test
void imagesOfClustersThatAreGoneAreRemovedAndTheOthersKept() {
String goneId = "sha256:" + "3".repeat(64);
@@ -6,6 +6,7 @@ import com.github.dockerjava.api.exception.InternalServerErrorException;
import com.github.dockerjava.api.model.Container;
import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.api.model.StreamType;
import io.github.hectorvent.floci.config.ContainerCaBundle;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
@@ -135,7 +136,12 @@ class EmrServerlessSparkRunnerTest {
runner(builder).run(job(Duration.ZERO), progress);
verify(builder).newContainer("public.ecr.aws/emr-serverless/spark/emr-7.5.0:latest");
verify(spec).withEntrypoint(List.of("/usr/lib/spark/bin/spark-submit"));
// bash -c runs Floci's wrapper with "floci" as its $0 and spark-submit and its arguments as "$@".
verify(spec).withEntrypoint(List.of("/bin/bash", "-c",
ContainerCaBundle.JAVA_TRUST_SHELL_LINE + "\nexec \"$@\"", "floci"));
verify(spec).withCmd(argThat((List<String> cmd) -> "/usr/lib/spark/bin/spark-submit".equals(cmd.getFirst())
&& List.of("--master", "local[*]").equals(cmd.subList(1, 3))
&& "s3://bucket/jobs/app.jar".equals(cmd.getLast())));
verify(spec).withName(ContainerStorageHelper.dockerName(config, "emr-serverless-00f0000000000001"));
verify(spec).withDockerNetwork(Optional.of("floci-network"));
verify(spec).withLabels(argThat(labels ->
@@ -154,13 +160,23 @@ class EmrServerlessSparkRunnerTest {
// bash -c runs Floci's wrapper with "floci" as its $0 and the command as "$@".
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.size() == 4
&& entrypoint.subList(0, 2).equals(List.of("/bin/bash", "-c"))
&& entrypoint.get(2).startsWith(ContainerCaBundle.JAVA_TRUST_SHELL_LINE + "\n")
&& entrypoint.get(2).contains("export SPARK_CONF_DIR=") && entrypoint.get(2).endsWith("exec \"$@\"")
&& "floci".equals(entrypoint.get(3))));
verify(spec).withCmd(command);
verify(spec).withEnv(eq("FLOCI_SPARK_DEFAULTS"),
argThat(file -> file.startsWith("spark.master local[*]\n")
&& file.endsWith("\nspark.executor.cores 4")));
verify(spec, never()).withEntrypoint(List.of("/usr/lib/spark/bin/spark-submit"));
}
@Test
void theJavaTrustStoreGoesIntoTheDriversContainerBeforeItStarts() {
runner().run(job(Duration.ZERO), progress);
InOrder order = inOrder(lifecycle);
order.verify(lifecycle).create(any());
order.verify(lifecycle).copyJavaTrustStore("driver");
order.verify(lifecycle).startCreated(eq("driver"), any());
}
@Test
@@ -210,7 +226,7 @@ class EmrServerlessSparkRunnerTest {
assertNull(outcome.exitCode());
assertNotNull(outcome.failure());
verify(lifecycle, never()).createAndStart(any());
verify(lifecycle, never()).create(any());
}
@Test
@@ -243,15 +259,16 @@ class EmrServerlessSparkRunnerTest {
@Test
void aResetWhileTheImageIsPulledStopsTheRunOnceItsContainerIsUp() {
EmrServerlessSparkRunner runner = runner();
when(lifecycle.createAndStart(any())).thenAnswer(pulling -> {
when(lifecycle.create(any())).thenAnswer(pulling -> {
runner.stopManagedContainers();
return new ContainerLifecycleManager.ContainerInfo("driver", Map.of());
return "driver";
});
SparkJobRunner.Outcome outcome = runner.run(job(Duration.ZERO), progress);
assertTrue(outcome.stopped());
verify(progress, never()).started();
verify(lifecycle, never()).startCreated(anyString(), any());
verify(lifecycle).stopAndRemove("driver", null, 0);
}
@@ -265,6 +282,43 @@ class EmrServerlessSparkRunnerTest {
assertTrue(outcome.stopped());
verify(progress, never()).started();
verify(lifecycle, never()).startCreated(anyString(), any());
verify(lifecycle).stopAndRemove("driver", null, 0);
}
@Test
void aRunStoppedWhileTheTrustStoreIsCopiedNeverStartsItsDriver() {
EmrServerlessSparkRunner runner = runner();
SparkJobRunner.Job job = job(Duration.ZERO);
// The copy can wait on Docker, and a stop only marks the run.
when(lifecycle.copyJavaTrustStore("driver")).thenAnswer(copy -> {
runner.stop(job.runId());
return true;
});
SparkJobRunner.Outcome outcome = runner.run(job, progress);
assertTrue(outcome.stopped());
verify(progress, never()).started();
verify(lifecycle, never()).startCreated(anyString(), any());
verify(lifecycle).stopAndRemove("driver", null, 0);
}
@Test
void aRunCancelledWhileTheTrustStoreIsCopiedNeverStartsItsDriver() {
EmrServerlessSparkRunner runner = runner();
AtomicBoolean cancelled = new AtomicBoolean();
when(progress.cancelled()).thenAnswer(look -> cancelled.get());
when(lifecycle.copyJavaTrustStore("driver")).thenAnswer(copy -> {
cancelled.set(true);
return true;
});
SparkJobRunner.Outcome outcome = runner.run(job(Duration.ZERO), progress);
assertTrue(outcome.stopped());
verify(progress, never()).started();
verify(lifecycle, never()).startCreated(anyString(), any());
verify(lifecycle).stopAndRemove("driver", null, 0);
}
@@ -480,7 +534,7 @@ class EmrServerlessSparkRunnerTest {
private EmrServerlessSparkRunner runner(ContainerBuilder builder) {
when(lifecycle.getDockerClient()).thenReturn(docker);
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("driver", Map.of()));
when(lifecycle.create(any())).thenReturn("driver");
when(docker.inspectContainerCmd("driver").exec().getState().getRunning()).thenReturn(false);
when(docker.inspectContainerCmd("driver").exec().getState().getExitCodeLong()).thenReturn(0L);
return new EmrServerlessSparkRunner(builder, lifecycle, logStreamer,