diff --git a/src/test/java/io/floci/aws/services/emr/EmrDockerRunnerDockerIntegrationTest.java b/src/test/java/io/floci/aws/services/emr/EmrDockerRunnerDockerIntegrationTest.java index 026de27df8..fce6f6ab89 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrDockerRunnerDockerIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrDockerRunnerDockerIntegrationTest.java @@ -50,6 +50,7 @@ import static io.floci.aws.testing.EmrServerlessRequests.deleteApplication; import static io.floci.aws.testing.EmrServerlessRequests.startJobRun; import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue; /** @@ -188,18 +189,25 @@ class EmrDockerRunnerDockerIntegrationTest { executors = sc.parallelize(range(4), 4).map(lambda _: socket.gethostname()).distinct().collect() where = " ".join([sc.master, sc.getConf().get("spark.submit.deployMode"), str(socket.gethostname() in executors)]) + print("driver: " + where, flush=True) spark.createDataFrame([(where,)], ["value"]).coalesce(1).write.text(sys.argv[1]) """); - startCluster("[]"); + startCluster("[]", s3Uri("logs/")); // Its driver in the step's container, its executors on the primary node. assertEquals("COMPLETED", runStep("command-runner.jar", "spark-submit", s3Uri("side/where.py"), s3Uri("client/"))); assertEquals("yarn client False\n", partFiles("client/")); - // Its driver on the primary node too. + // Its driver on the primary node too, whose output is in its application's container logs, where a user + // reads it, the step's own holding only the client's. assertEquals("COMPLETED", runStep("command-runner.jar", "spark-submit", "--deploy-mode", "cluster", s3Uri("side/where.py"), s3Uri("cluster/"))); assertEquals("yarn cluster True\n", partFiles("cluster/")); + List driverLogs = containerStdoutsHolding("driver: yarn cluster True"); + assertEquals(1, driverLogs.size(), () -> "container stdouts with the driver's line: " + driverLogs); + String containers = "logs/" + clusterId + "/containers/"; + assertTrue(driverLogs.get(0).matches(containers + "application_\\d+_\\d+/container_\\w+/stdout\\.gz"), + driverLogs.get(0)); } @Test @@ -331,7 +339,13 @@ class EmrDockerRunnerDockerIntegrationTest { /** A one-primary cluster of the cached release, with {@code configurations} as its Configurations. */ private void startCluster(String configurations) { + startCluster(configurations, null); + } + + /** The same, its logs under {@code logUri} when that is not null, as the cluster's {@code LogUri}. */ + private void startCluster(String configurations, String logUri) { clusterId = emr("RunJobFlow", "{\"Name\":\"docker-runner\",\"ReleaseLabel\":\"emr-7.5.0\"," + + (logUri == null ? "" : "\"LogUri\":\"" + logUri + "\",") + "\"Applications\":[{\"Name\":\"Hadoop\"},{\"Name\":\"Spark\"}]," + "\"Configurations\":" + configurations + "," + "\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,\"InstanceGroups\":[{\"Name\":\"primary\"," @@ -375,6 +389,16 @@ class EmrDockerRunnerDockerIntegrationTest { return counts; } + /** The keys of the cluster's container {@code stdout} logs under {@code logs/} that hold {@code line}. */ + private List containerStdoutsHolding(String line) { + String prefix = "logs/" + clusterId + "/containers/"; + return s3.listObjectsV2Paginator(request -> request.bucket(bucket).prefix(prefix)).contents().stream() + .map(S3Object::key) + .filter(key -> key.endsWith("/stdout.gz")) + .filter(key -> S3TestClients.gunzipped(s3, bucket, key).contains(line)) + .toList(); + } + /** What a job wrote under {@code prefix}: its part files, in key order, one after the other. */ private String partFiles(String prefix) { StringBuilder text = new StringBuilder(); diff --git a/src/test/java/io/floci/aws/services/emr/EmrHiveStepsDockerIntegrationTest.java b/src/test/java/io/floci/aws/services/emr/EmrHiveStepsDockerIntegrationTest.java index b2aaf098ed..544ec9a80a 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrHiveStepsDockerIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrHiveStepsDockerIntegrationTest.java @@ -26,11 +26,9 @@ import software.amazon.awssdk.services.s3.model.S3Object; import java.io.IOException; import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import java.util.zip.GZIPInputStream; import static io.floci.aws.testing.EmrRequests.awaitStep; import static io.floci.aws.testing.EmrRequests.emr; @@ -248,12 +246,7 @@ class EmrHiveStepsDockerIntegrationTest { /** A log of the step's, in the step log folder of the Management Guide's "Log locations". */ private String stepLog(String stepId, String name) { - String key = "logs/" + clusterId + "/steps/" + stepId + "/" + name; - try (GZIPInputStream in = new GZIPInputStream(s3.getObject(request -> request.bucket(bucket).key(key)))) { - return new String(in.readAllBytes(), StandardCharsets.UTF_8); - } catch (IOException e) { - throw new UncheckedIOException(e); - } + return S3TestClients.gunzipped(s3, bucket, "logs/" + clusterId + "/steps/" + stepId + "/" + name); } private void put(String key, String text) { diff --git a/src/test/java/io/floci/aws/services/emrserverless/EmrServerlessHiveDockerIntegrationTest.java b/src/test/java/io/floci/aws/services/emrserverless/EmrServerlessHiveDockerIntegrationTest.java index b15a70eee2..5b1d77cc9c 100644 --- a/src/test/java/io/floci/aws/services/emrserverless/EmrServerlessHiveDockerIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/emrserverless/EmrServerlessHiveDockerIntegrationTest.java @@ -20,12 +20,8 @@ import software.amazon.awssdk.services.glue.model.Table; import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.model.S3Object; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.UUID; -import java.util.zip.GZIPInputStream; import static io.floci.aws.testing.EmrServerlessRequests.awaitJobRun; import static io.floci.aws.testing.EmrServerlessRequests.createApplication; @@ -171,10 +167,6 @@ class EmrServerlessHiveDockerIntegrationTest { } private String gunzipped(String key) { - try (GZIPInputStream in = new GZIPInputStream(s3.getObject(request -> request.bucket(bucket).key(key)))) { - return new String(in.readAllBytes(), StandardCharsets.UTF_8); - } catch (IOException e) { - throw new UncheckedIOException(e); - } + return S3TestClients.gunzipped(s3, bucket, key); } } diff --git a/src/test/java/io/floci/aws/testing/S3TestClients.java b/src/test/java/io/floci/aws/testing/S3TestClients.java index b9c78c3c1d..a6b260850b 100644 --- a/src/test/java/io/floci/aws/testing/S3TestClients.java +++ b/src/test/java/io/floci/aws/testing/S3TestClients.java @@ -7,7 +7,11 @@ import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.s3.S3Client; +import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.zip.GZIPInputStream; /** AWS SDK S3 clients pointed at the Floci instance a {@code @QuarkusTest} runs, and what a test does with them. */ public final class S3TestClients { @@ -32,4 +36,13 @@ public final class S3TestClients { .forEach(object -> s3.deleteObject(request -> request.bucket(bucket).key(object.key()))); s3.deleteBucket(request -> request.bucket(bucket)); } + + /** The object at {@code key} in {@code bucket}, gunzipped, as a test reads back a log Floci wrote there. */ + public static String gunzipped(S3Client s3, String bucket, String key) { + try (GZIPInputStream in = new GZIPInputStream(s3.getObject(request -> request.bucket(bucket).key(key)))) { + return new String(in.readAllBytes(), StandardCharsets.UTF_8); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } }