Skip to content

Commit 9221fd5

Browse files
authored
Merge pull request #70 from DataSQRL/coverage
Precarious test coverage
2 parents 6784e68 + 1fb429b commit 9221fd5

File tree

5 files changed

+94
-2
lines changed

5 files changed

+94
-2
lines changed

flink-sql-runner/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@
188188
<version>1.0.0-SNAPSHOT</version>
189189
<scope>test</scope>
190190
</dependency>
191+
192+
<dependency>
193+
<groupId>org.jacoco</groupId>
194+
<artifactId>org.jacoco.core</artifactId>
195+
<version>0.8.13</version>
196+
<scope>test</scope>
197+
</dependency>
198+
<dependency>
199+
<groupId>org.jacoco</groupId>
200+
<artifactId>org.jacoco.agent</artifactId>
201+
<version>0.8.13</version>
202+
<classifier>runtime</classifier>
203+
<scope>test</scope>
204+
</dependency>
191205
</dependencies>
192206

193207
<build>
@@ -283,6 +297,7 @@
283297
</execution>
284298
</executions>
285299
</plugin>
300+
286301
<plugin>
287302
<groupId>com.marvinformatics</groupId>
288303
<artifactId>docker-compose-maven-plugin</artifactId>
@@ -367,6 +382,17 @@
367382
<outputDirectory>${project.build.directory}</outputDirectory>
368383
</configuration>
369384
</execution>
385+
<execution>
386+
<id>copy-jacoco-cli</id>
387+
<goals>
388+
<goal>copy-dependencies</goal>
389+
</goals>
390+
<phase>process-resources</phase>
391+
<configuration>
392+
<includeArtifactIds>org.jacoco.agent</includeArtifactIds>
393+
<outputDirectory>${project.build.directory}</outputDirectory>
394+
</configuration>
395+
</execution>
370396
</executions>
371397
</plugin>
372398
</plugins>

flink-sql-runner/src/main/docker/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ services:
6565
- ./test-classes/datasources/:/datasources/
6666
- /tmp:/tmp
6767
- ./test-classes/systemfunction/system-functions-sample-${project.version}.jar:/opt/flink/lib/systemfunction.jar
68+
- ./org.jacoco.agent-0.8.13-runtime.jar:/opt/flink/lib/jacoco.agent.jar
69+
- ./jacoco.job.exec:/opt/flink/jacoco.exec
6870
healthcheck:
6971
test: ["CMD-SHELL", "curl -f http://localhost:8081/ || exit 1"]
7072
interval: 1s
@@ -100,6 +102,7 @@ services:
100102
- ./test-classes/datasources/:/datasources/
101103
- /tmp:/tmp
102104
- ./test-classes/systemfunction/system-functions-sample-${project.version}.jar:/opt/flink/lib/systemfunction.jar
105+
- ./org.jacoco.agent-0.8.13-runtime.jar:/opt/flink/lib/jacoco.agent.jar
103106
restart: always
104107
deploy:
105108
resources:

flink-sql-runner/src/test/java/com/datasqrl/FlinkMainIT.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
import com.nextbreakpoint.flink.client.model.TerminationMode;
3030
import com.nextbreakpoint.flink.client.model.UploadStatus;
3131
import java.io.File;
32+
import java.io.FileInputStream;
33+
import java.io.FileOutputStream;
34+
import java.io.IOException;
35+
import java.io.InputStream;
36+
import java.io.OutputStream;
3237
import java.nio.file.Files;
3338
import java.nio.file.Path;
3439
import java.sql.SQLException;
@@ -45,6 +50,8 @@
4550
import org.apache.flink.shaded.curator5.com.google.common.base.Objects;
4651
import org.apache.flink.shaded.curator5.com.google.common.collect.Lists;
4752
import org.awaitility.core.ThrowingRunnable;
53+
import org.jacoco.core.instr.Instrumenter;
54+
import org.jacoco.core.runtime.OfflineInstrumentationAccessGenerator;
4855
import org.jdbi.v3.core.Jdbi;
4956
import org.jdbi.v3.core.statement.SqlLogger;
5057
import org.jdbi.v3.core.statement.StatementContext;
@@ -243,11 +250,29 @@ JarRunResponseBody execute(String... arguments) {
243250
return restoreAndExecute(null, arguments);
244251
}
245252

253+
private int instrument(final File src, final File dest) throws IOException {
254+
if (dest.exists()) {
255+
return 0;
256+
}
257+
var instrumenter = new Instrumenter(new OfflineInstrumentationAccessGenerator());
258+
259+
dest.getParentFile().mkdirs();
260+
try (final InputStream input = new FileInputStream(src);
261+
final OutputStream output = new FileOutputStream(dest)) {
262+
return instrumenter.instrumentAll(input, output, src.getAbsolutePath());
263+
} catch (final IOException e) {
264+
dest.delete();
265+
throw e;
266+
}
267+
}
268+
246269
@SneakyThrows
247270
JarRunResponseBody restoreAndExecute(String savepointPath, String... arguments) {
248-
var jarFile = new File("target/flink-sql-runner.uber.jar");
271+
var originalFile = new File("target/flink-sql-runner.uber.jar");
272+
var instrumentedJarFile = new File("target/flink-sql-runner.jacoco.jar");
273+
instrument(originalFile, instrumentedJarFile);
249274

250-
var uploadResponse = client.uploadJar(jarFile);
275+
var uploadResponse = client.uploadJar(instrumentedJarFile);
251276

252277
assertThat(uploadResponse.getStatus()).isEqualTo(UploadStatus.SUCCESS);
253278

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright © 2024 DataSQRL (contact@datasqrl.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.datasqrl;
17+
18+
import java.nio.file.Files;
19+
import java.nio.file.Path;
20+
import java.nio.file.attribute.PosixFilePermission;
21+
import java.util.EnumSet;
22+
import org.junit.jupiter.api.BeforeAll;
23+
import org.junit.jupiter.api.Test;
24+
25+
public class TouchTest {
26+
27+
@BeforeAll
28+
static void copyJacocoReports() throws Exception {
29+
Files.createFile(Path.of("target/jacoco.job.exec"));
30+
Files.setPosixFilePermissions(
31+
Path.of("target/jacoco.job.exec"), EnumSet.allOf(PosixFilePermission.class));
32+
}
33+
34+
@Test
35+
void doNothing() {}
36+
}

testing/coverage/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
<dataFileIncludes>
5959
<dataFileInclude>**/jacoco.exec</dataFileInclude>
6060
<dataFileInclude>**/jacoco-it.exec</dataFileInclude>
61+
<dataFileInclude>**/jacoco.task.exec</dataFileInclude>
62+
<dataFileInclude>**/jacoco.job.exec</dataFileInclude>
6163
</dataFileIncludes>
6264
</configuration>
6365
</execution>

0 commit comments

Comments
 (0)