Skip to content

Commit 3c1269e

Browse files
zeitlingertraskotelbot[bot]
authored
add test for Mac OS and Windows (#1934)
Co-authored-by: Trask Stalnaker <[email protected]> Co-authored-by: otelbot <[email protected]>
1 parent 032e0e6 commit 3c1269e

File tree

10 files changed

+92
-32
lines changed

10 files changed

+92
-32
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,46 @@ jobs:
3636
run: ./gradlew build -x test
3737

3838
test:
39-
name: test (${{ matrix.test-java-version }})
40-
runs-on: ubuntu-latest
39+
name: Test
40+
runs-on: ${{ matrix.os }}
4141
strategy:
42+
fail-fast: false
4243
matrix:
44+
os:
45+
- macos-latest
46+
- macos-13
47+
- ubuntu-latest
48+
- windows-latest
4349
test-java-version:
4450
- 8
4551
- 11
4652
- 17
4753
- 21
4854
- 23
49-
fail-fast: false
55+
# macos-latest drops support for java 8 temurin. Run java 8 on macos-13. Run java 11, 17, 21 on macos-latest.
56+
exclude:
57+
- os: macos-latest
58+
test-java-version: 8
59+
- os: macos-13
60+
test-java-version: 11
61+
- os: macos-13
62+
test-java-version: 17
63+
- os: macos-13
64+
test-java-version: 21
65+
- os: macos-13
66+
test-java-version: 23
5067
steps:
5168
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5269

53-
- id: setup-test-java
54-
name: Set up JDK ${{ matrix.test-java-version }} for running tests
70+
- id: setup-java-test
71+
name: Set up Java ${{ matrix.test-java-version }} for tests
5572
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
5673
with:
57-
# using zulu because new releases get published quickly
58-
distribution: zulu
74+
distribution: temurin
5975
java-version: ${{ matrix.test-java-version }}
6076

61-
- name: Set up JDK for running Gradle
77+
- id: setup-java
78+
name: Set up Java for build
6279
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
6380
with:
6481
distribution: temurin
@@ -71,9 +88,9 @@ jobs:
7188
- name: Gradle test
7289
run: >
7390
./gradlew test
74-
-PtestJavaVersion=${{ matrix.test-java-version }}
75-
-Porg.gradle.java.installations.paths=${{ steps.setup-test-java.outputs.path }}
76-
-Porg.gradle.java.installations.auto-download=false
91+
"-PtestJavaVersion=${{ matrix.test-java-version }}"
92+
"-Porg.gradle.java.installations.paths=${{ steps.setup-java-test.outputs.path }}"
93+
"-Porg.gradle.java.installations.auto-download=false"
7794
7895
integration-test:
7996
runs-on: ubuntu-latest

disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/storage/FolderManager.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
import io.opentelemetry.contrib.disk.buffering.internal.storage.files.ReadableFile;
1212
import io.opentelemetry.contrib.disk.buffering.internal.storage.files.WritableFile;
1313
import io.opentelemetry.sdk.common.Clock;
14+
import java.io.Closeable;
1415
import java.io.File;
1516
import java.io.IOException;
1617
import java.util.Objects;
1718
import javax.annotation.Nullable;
1819
import org.jetbrains.annotations.NotNull;
1920

20-
public final class FolderManager {
21+
public final class FolderManager implements Closeable {
2122
private final File folder;
2223
private final Clock clock;
2324
private final StorageConfiguration configuration;
@@ -30,6 +31,16 @@ public FolderManager(File folder, StorageConfiguration configuration, Clock cloc
3031
this.clock = clock;
3132
}
3233

34+
@Override
35+
public void close() throws IOException {
36+
if (currentReadableFile != null) {
37+
currentReadableFile.close();
38+
}
39+
if (currentWritableFile != null) {
40+
currentWritableFile.close();
41+
}
42+
}
43+
3344
@Nullable
3445
public synchronized ReadableFile getReadableFile() throws IOException {
3546
currentReadableFile = null;

disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/IntegrationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.function.Function;
4949
import java.util.function.Supplier;
5050
import org.jetbrains.annotations.NotNull;
51+
import org.junit.jupiter.api.AfterEach;
5152
import org.junit.jupiter.api.BeforeEach;
5253
import org.junit.jupiter.api.Test;
5354
import org.junit.jupiter.api.io.TempDir;
@@ -103,6 +104,11 @@ void setUp() throws IOException {
103104
logger = createLoggerProvider(logToDiskExporter).get("LogInstrumentationScope");
104105
}
105106

107+
@AfterEach
108+
void tearDown() throws IOException {
109+
spanStorage.close();
110+
}
111+
106112
@NotNull
107113
private <T> ToDiskExporter<T> buildToDiskExporter(
108114
SignalSerializer<T> serializer, Function<Collection<T>, CompletableResultCode> exporter) {

disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/storage/FolderManagerTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.File;
2525
import java.io.IOException;
2626
import java.nio.file.Files;
27+
import org.junit.jupiter.api.AfterEach;
2728
import org.junit.jupiter.api.BeforeEach;
2829
import org.junit.jupiter.api.Test;
2930
import org.junit.jupiter.api.io.TempDir;
@@ -40,6 +41,11 @@ void setUp() {
4041
folderManager = new FolderManager(rootDir, TestData.getConfiguration(rootDir), clock);
4142
}
4243

44+
@AfterEach
45+
void tearDown() throws Exception {
46+
folderManager.close();
47+
}
48+
4349
@Test
4450
void createWritableFile_withTimeMillisAsName() throws IOException {
4551
when(clock.now()).thenReturn(MILLISECONDS.toNanos(1000L));

disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/storage/StorageTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.File;
2727
import java.io.IOException;
2828
import java.util.function.Function;
29+
import org.junit.jupiter.api.AfterEach;
2930
import org.junit.jupiter.api.BeforeEach;
3031
import org.junit.jupiter.api.Test;
3132

@@ -47,6 +48,11 @@ void setUp() throws IOException {
4748
storage = new Storage(folderManager, true);
4849
}
4950

51+
@AfterEach
52+
void tearDown() throws IOException {
53+
storage.close();
54+
}
55+
5056
@Test
5157
void whenReadingAndProcessingSuccessfully_returnSuccess() throws IOException {
5258
when(folderManager.getReadableFile()).thenReturn(readableFile);

disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/storage/files/ReadableFileTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.ArrayList;
3333
import java.util.Collections;
3434
import java.util.List;
35+
import org.junit.jupiter.api.AfterEach;
3536
import org.junit.jupiter.api.BeforeEach;
3637
import org.junit.jupiter.api.Test;
3738
import org.junit.jupiter.api.io.TempDir;
@@ -98,6 +99,11 @@ void setUp() throws IOException {
9899
readableFile = new ReadableFile(source, CREATED_TIME_MILLIS, clock, getConfiguration(dir));
99100
}
100101

102+
@AfterEach
103+
void tearDown() throws IOException {
104+
readableFile.close();
105+
}
106+
101107
private static void addFileContents(File source) throws IOException {
102108
List<byte[]> items = new ArrayList<>();
103109
items.add(SERIALIZER.serialize(Collections.singleton(FIRST_LOG_RECORD)));

disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/storage/files/WritableFileTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.nio.charset.StandardCharsets;
2323
import java.nio.file.Files;
2424
import java.util.List;
25+
import org.junit.jupiter.api.AfterEach;
2526
import org.junit.jupiter.api.BeforeEach;
2627
import org.junit.jupiter.api.Test;
2728
import org.junit.jupiter.api.io.TempDir;
@@ -47,6 +48,11 @@ void setUp() throws IOException {
4748
clock);
4849
}
4950

51+
@AfterEach
52+
void tearDown() throws IOException {
53+
writableFile.close();
54+
}
55+
5056
@Test
5157
void hasNotExpired_whenWriteAgeHasNotExpired() {
5258
when(clock.now()).thenReturn(MILLISECONDS.toNanos(1500L));

inferred-spans/src/test/java/io/opentelemetry/contrib/inferredspans/InferredSpansAutoConfigTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
99
import static org.awaitility.Awaitility.await;
10+
import static org.junit.jupiter.api.condition.OS.WINDOWS;
1011

1112
import io.opentelemetry.api.GlobalOpenTelemetry;
1213
import io.opentelemetry.api.OpenTelemetry;
@@ -31,9 +32,9 @@
3132
import org.junit.jupiter.api.BeforeEach;
3233
import org.junit.jupiter.api.Test;
3334
import org.junit.jupiter.api.condition.DisabledOnOs;
34-
import org.junit.jupiter.api.condition.OS;
3535
import org.junit.jupiter.api.io.TempDir;
3636

37+
@DisabledOnOs(WINDOWS) // Uses async-profiler, which is not supported on Windows
3738
public class InferredSpansAutoConfigTest {
3839

3940
@BeforeEach
@@ -107,7 +108,6 @@ public void checkDisabledbyDefault() {
107108
}
108109

109110
@DisabledOnOpenJ9
110-
@DisabledOnOs(OS.WINDOWS)
111111
@Test
112112
public void checkProfilerWorking() {
113113
try (AutoConfigTestProperties props =

jmx-scraper/src/test/java/io/opentelemetry/contrib/jmxscraper/JmxScraperTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.util.List;
1818
import java.util.Properties;
1919
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.condition.DisabledOnOs;
21+
import org.junit.jupiter.api.condition.OS;
2022
import org.junitpioneer.jupiter.ClearSystemProperty;
2123

2224
class JmxScraperTest {
@@ -46,8 +48,10 @@ private static void testInvalidArguments(String... args) {
4648
}
4749

4850
@Test
51+
@DisabledOnOs(OS.WINDOWS)
4952
void shouldCreateConfig_propertiesLoadedFromFile() throws InvalidArgumentException {
5053
// Given
54+
// Windows returns /C:/path/to/file, which is not a valid path for Path.get() in Java.
5155
String filePath =
5256
ClassLoader.getSystemClassLoader().getResource("validConfig.properties").getPath();
5357
List<String> args = Arrays.asList("-config", filePath);

opamp-client/build.gradle.kts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import de.undercouch.gradle.tasks.download.Download
21
import de.undercouch.gradle.tasks.download.DownloadExtension
3-
import groovy.json.JsonSlurper
2+
import java.net.HttpURLConnection
3+
import java.net.URL
44

55
plugins {
66
id("otel.java-conventions")
@@ -18,19 +18,9 @@ dependencies {
1818
testImplementation("org.mockito:mockito-inline")
1919
}
2020

21-
val opampReleaseInfo = tasks.register<Download>("opampLastReleaseInfo") {
22-
group = "opamp"
23-
src("https://api.github.com/repos/open-telemetry/opamp-spec/releases/latest")
24-
dest(project.layout.buildDirectory.file("opamp/release.json"))
25-
}
26-
2721
val opampProtos = tasks.register<DownloadOpampProtos>("opampProtoDownload", download)
2822
opampProtos.configure {
2923
group = "opamp"
30-
dependsOn(opampReleaseInfo)
31-
lastReleaseInfoJson.set {
32-
opampReleaseInfo.get().dest
33-
}
3424
outputProtosDir.set(project.layout.buildDirectory.dir("opamp/protos"))
3525
downloadedZipFile.set(project.layout.buildDirectory.file("intermediate/$name/release.zip"))
3626
}
@@ -48,20 +38,28 @@ abstract class DownloadOpampProtos @Inject constructor(
4838
private val fileOps: FileSystemOperations,
4939
) : DefaultTask() {
5040

51-
@get:InputFile
52-
abstract val lastReleaseInfoJson: RegularFileProperty
53-
5441
@get:OutputDirectory
5542
abstract val outputProtosDir: DirectoryProperty
5643

5744
@get:Internal
5845
abstract val downloadedZipFile: RegularFileProperty
5946

60-
@Suppress("UNCHECKED_CAST")
6147
@TaskAction
6248
fun execute() {
63-
val releaseInfo = JsonSlurper().parse(lastReleaseInfoJson.get().asFile) as Map<String, String>
64-
val zipUrl = releaseInfo["zipball_url"]
49+
// Get the latest release tag by following the redirect from GitHub's latest release URL
50+
val latestReleaseUrl = "https://github.com/open-telemetry/opamp-spec/releases/latest"
51+
val connection = URL(latestReleaseUrl).openConnection() as HttpURLConnection
52+
connection.instanceFollowRedirects = false
53+
connection.requestMethod = "HEAD"
54+
55+
val redirectLocation = connection.getHeaderField("Location")
56+
connection.disconnect()
57+
58+
// Extract tag from URL like: https://github.com/open-telemetry/opamp-spec/releases/tag/v0.12.0
59+
val latestTag = redirectLocation.substringAfterLast("/")
60+
// Download the source code for the latest release
61+
val zipUrl = "https://github.com/open-telemetry/opamp-spec/zipball/$latestTag"
62+
6563
download.run {
6664
src(zipUrl)
6765
dest(downloadedZipFile)

0 commit comments

Comments
 (0)