From 831c0104e6e769ae4cb1857d9cf5b99f690765a5 Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Wed, 9 Apr 2025 22:33:00 -0300 Subject: [PATCH 1/3] Precarious test coverage Signed-off-by: Marvin Froeder --- flink-sql-runner/pom.xml | 26 ++++++++++++++ .../src/main/docker/docker-compose.yml | 3 ++ .../test/java/com/datasqrl/FlinkMainIT.java | 36 +++++++++++++++++-- .../src/test/java/com/datasqrl/TouchTest.java | 36 +++++++++++++++++++ testing/coverage/pom.xml | 2 ++ 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 flink-sql-runner/src/test/java/com/datasqrl/TouchTest.java diff --git a/flink-sql-runner/pom.xml b/flink-sql-runner/pom.xml index d5e5bc1..d893f4f 100644 --- a/flink-sql-runner/pom.xml +++ b/flink-sql-runner/pom.xml @@ -188,6 +188,20 @@ 1.0.0-SNAPSHOT test + + + org.jacoco + org.jacoco.core + 0.8.13 + test + + + org.jacoco + org.jacoco.agent + 0.8.13 + runtime + test + @@ -283,6 +297,7 @@ + com.marvinformatics docker-compose-maven-plugin @@ -367,6 +382,17 @@ ${project.build.directory} + + copy-jacoco-cli + + copy-dependencies + + process-resources + + org.jacoco.agent + ${project.build.directory} + + diff --git a/flink-sql-runner/src/main/docker/docker-compose.yml b/flink-sql-runner/src/main/docker/docker-compose.yml index ac8adb5..92e0d81 100644 --- a/flink-sql-runner/src/main/docker/docker-compose.yml +++ b/flink-sql-runner/src/main/docker/docker-compose.yml @@ -65,6 +65,8 @@ services: - ./test-classes/datasources/:/datasources/ - /tmp:/tmp - ./test-classes/systemfunction/system-functions-sample-${project.version}.jar:/opt/flink/lib/systemfunction.jar + - ./org.jacoco.agent-0.8.13-runtime.jar:/opt/flink/lib/jacoco.agent.jar + - ./jacoco.job.exec:/opt/flink/jacoco.exec healthcheck: test: ["CMD-SHELL", "curl -f http://localhost:8081/ || exit 1"] interval: 1s @@ -100,6 +102,7 @@ services: - ./test-classes/datasources/:/datasources/ - /tmp:/tmp - ./test-classes/systemfunction/system-functions-sample-${project.version}.jar:/opt/flink/lib/systemfunction.jar + - ./org.jacoco.agent-0.8.13-runtime.jar:/opt/flink/lib/jacoco.agent.jar restart: always deploy: resources: diff --git a/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java b/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java index e08fc2c..a9fd8c3 100644 --- a/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java +++ b/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java @@ -29,6 +29,11 @@ import com.nextbreakpoint.flink.client.model.TerminationMode; import com.nextbreakpoint.flink.client.model.UploadStatus; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.sql.SQLException; @@ -45,6 +50,8 @@ import org.apache.flink.shaded.curator5.com.google.common.base.Objects; import org.apache.flink.shaded.curator5.com.google.common.collect.Lists; import org.awaitility.core.ThrowingRunnable; +import org.jacoco.core.instr.Instrumenter; +import org.jacoco.core.runtime.OfflineInstrumentationAccessGenerator; import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.core.statement.SqlLogger; import org.jdbi.v3.core.statement.StatementContext; @@ -243,11 +250,36 @@ JarRunResponseBody execute(String... arguments) { return restoreAndExecute(null, arguments); } + private int instrument(final File src, final File dest) throws IOException { + if (dest.exists()) { + return 0; + } + var instrumenter = new Instrumenter(new OfflineInstrumentationAccessGenerator()); + + dest.getParentFile().mkdirs(); + final InputStream input = new FileInputStream(src); + try { + final OutputStream output = new FileOutputStream(dest); + try { + return instrumenter.instrumentAll(input, output, src.getAbsolutePath()); + } finally { + output.close(); + } + } catch (final IOException e) { + dest.delete(); + throw e; + } finally { + input.close(); + } + } + @SneakyThrows JarRunResponseBody restoreAndExecute(String savepointPath, String... arguments) { - var jarFile = new File("target/flink-sql-runner.uber.jar"); + var originalFile = new File("target/flink-sql-runner.uber.jar"); + var instrumentedJarFile = new File("target/flink-sql-runner.jacoco.jar"); + instrument(originalFile, instrumentedJarFile); - var uploadResponse = client.uploadJar(jarFile); + var uploadResponse = client.uploadJar(instrumentedJarFile); assertThat(uploadResponse.getStatus()).isEqualTo(UploadStatus.SUCCESS); diff --git a/flink-sql-runner/src/test/java/com/datasqrl/TouchTest.java b/flink-sql-runner/src/test/java/com/datasqrl/TouchTest.java new file mode 100644 index 0000000..7d9b6c8 --- /dev/null +++ b/flink-sql-runner/src/test/java/com/datasqrl/TouchTest.java @@ -0,0 +1,36 @@ +/* + * Copyright © 2024 DataSQRL (contact@datasqrl.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.datasqrl; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.PosixFilePermission; +import java.util.EnumSet; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class TouchTest { + + @BeforeAll + static void copyJacocoReports() throws Exception { + Files.createFile(Path.of("target/jacoco.job.exec")); + Files.setPosixFilePermissions( + Path.of("target/jacoco.job.exec"), EnumSet.allOf(PosixFilePermission.class)); + } + + @Test + void doNothing() {} +} diff --git a/testing/coverage/pom.xml b/testing/coverage/pom.xml index e52f3dc..a985d5f 100644 --- a/testing/coverage/pom.xml +++ b/testing/coverage/pom.xml @@ -58,6 +58,8 @@ **/jacoco.exec **/jacoco-it.exec + **/jacoco.task.exec + **/jacoco.job.exec From 8fd2526a1f5d4a04f785eecef2edc98ce96453bf Mon Sep 17 00:00:00 2001 From: Marvin Date: Wed, 9 Apr 2025 22:41:58 -0300 Subject: [PATCH 2/3] Update flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../src/test/java/com/datasqrl/FlinkMainIT.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java b/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java index a9fd8c3..c050e3f 100644 --- a/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java +++ b/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java @@ -257,14 +257,9 @@ private int instrument(final File src, final File dest) throws IOException { var instrumenter = new Instrumenter(new OfflineInstrumentationAccessGenerator()); dest.getParentFile().mkdirs(); - final InputStream input = new FileInputStream(src); - try { - final OutputStream output = new FileOutputStream(dest); - try { - return instrumenter.instrumentAll(input, output, src.getAbsolutePath()); - } finally { - output.close(); - } + try (final InputStream input = new FileInputStream(src); + final OutputStream output = new FileOutputStream(dest)) { + return instrumenter.instrumentAll(input, output, src.getAbsolutePath()); } catch (final IOException e) { dest.delete(); throw e; From 1fb429b456d48d1524ddd91454391a913820314c Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Thu, 10 Apr 2025 08:20:45 -0300 Subject: [PATCH 3/3] Fix AI fix Signed-off-by: Marvin Froeder --- flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java b/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java index c050e3f..78b6407 100644 --- a/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java +++ b/flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java @@ -258,13 +258,11 @@ private int instrument(final File src, final File dest) throws IOException { dest.getParentFile().mkdirs(); try (final InputStream input = new FileInputStream(src); - final OutputStream output = new FileOutputStream(dest)) { + final OutputStream output = new FileOutputStream(dest)) { return instrumenter.instrumentAll(input, output, src.getAbsolutePath()); } catch (final IOException e) { dest.delete(); throw e; - } finally { - input.close(); } }