Skip to content

add test for Mac OS and Windows #1934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,46 @@ jobs:
run: ./gradlew build -x test

test:
name: test (${{ matrix.test-java-version }})
runs-on: ubuntu-latest
name: Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- macos-13
- ubuntu-latest
- windows-latest
test-java-version:
- 8
- 11
- 17
- 21
- 23
fail-fast: false
# macos-latest drops support for java 8 temurin. Run java 8 on macos-13. Run java 11, 17, 21 on macos-latest.
exclude:
- os: macos-latest
test-java-version: 8
- os: macos-13
test-java-version: 11
- os: macos-13
test-java-version: 17
- os: macos-13
test-java-version: 21
- os: macos-13
test-java-version: 23
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- id: setup-test-java
name: Set up JDK ${{ matrix.test-java-version }} for running tests
- id: setup-java-test
name: Set up Java ${{ matrix.test-java-version }} for tests
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
# using zulu because new releases get published quickly
distribution: zulu
distribution: temurin
java-version: ${{ matrix.test-java-version }}

- name: Set up JDK for running Gradle
- id: setup-java
name: Set up Java for build
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
distribution: temurin
Expand All @@ -69,11 +86,13 @@ jobs:
with:
cache-read-only: ${{ github.event_name == 'pull_request' }}
- name: Gradle test
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
./gradlew test
-PtestJavaVersion=${{ matrix.test-java-version }}
-Porg.gradle.java.installations.paths=${{ steps.setup-test-java.outputs.path }}
-Porg.gradle.java.installations.auto-download=false
"-PtestJavaVersion=${{ matrix.test-java-version }}"
"-Porg.gradle.java.installations.paths=${{ steps.setup-java-test.outputs.path }}"
"-Porg.gradle.java.installations.auto-download=false"

integration-test:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
# --no-build-cache is required for codeql to analyze all modules
# --no-daemon is required for codeql to observe the compilation
# (see https://docs.github.com/en/code-security/codeql-cli/getting-started-with-the-codeql-cli/preparing-your-code-for-codeql-analysis#specifying-build-commands)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew assemble --no-build-cache --no-daemon

- name: Perform CodeQL analysis
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ jobs:
- name: Build and publish artifacts
run: ./gradlew assemble publishToSonatype closeAndReleaseSonatypeStagingRepository
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import io.opentelemetry.contrib.disk.buffering.internal.storage.files.ReadableFile;
import io.opentelemetry.contrib.disk.buffering.internal.storage.files.WritableFile;
import io.opentelemetry.sdk.common.Clock;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
import javax.annotation.Nullable;
import org.jetbrains.annotations.NotNull;

public final class FolderManager {
public final class FolderManager implements Closeable {
private final File folder;
private final Clock clock;
private final StorageConfiguration configuration;
Expand All @@ -30,6 +31,16 @@ public FolderManager(File folder, StorageConfiguration configuration, Clock cloc
this.clock = clock;
}

@Override
public void close() throws IOException {
if (currentReadableFile != null) {
currentReadableFile.close();
}
if (currentWritableFile != null) {
currentWritableFile.close();
}
}

@Nullable
public synchronized ReadableFile getReadableFile() throws IOException {
currentReadableFile = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.function.Function;
import java.util.function.Supplier;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -103,6 +104,11 @@ void setUp() throws IOException {
logger = createLoggerProvider(logToDiskExporter).get("LogInstrumentationScope");
}

@AfterEach
void tearDown() throws IOException {
spanStorage.close();
}

@NotNull
private <T> ToDiskExporter<T> buildToDiskExporter(
SignalSerializer<T> serializer, Function<Collection<T>, CompletableResultCode> exporter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -40,6 +41,11 @@ void setUp() {
folderManager = new FolderManager(rootDir, TestData.getDefaultConfiguration(rootDir), clock);
}

@AfterEach
void tearDown() throws Exception {
folderManager.close();
}

@Test
void createWritableFile_withTimeMillisAsName() throws IOException {
when(clock.now()).thenReturn(MILLISECONDS.toNanos(1000L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.File;
import java.io.IOException;
import java.util.function.Function;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

@AfterEach
void tearDown() throws IOException {
storage.close();
}

@Test
void whenReadingAndProcessingSuccessfully_returnSuccess() throws IOException {
when(folderManager.getReadableFile()).thenReturn(readableFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -104,6 +105,11 @@ void setUp() throws IOException {
source, CREATED_TIME_MILLIS, clock, getConfiguration(temporaryFileProvider, dir));
}

@AfterEach
void tearDown() throws IOException {
readableFile.close();
}

private static void addFileContents(File source) throws IOException {
List<byte[]> items = new ArrayList<>();
items.add(SERIALIZER.serialize(Collections.singleton(FIRST_LOG_RECORD)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -47,6 +48,11 @@ void setUp() throws IOException {
clock);
}

@AfterEach
void tearDown() throws IOException {
writableFile.close();
}

@Test
void hasNotExpired_whenWriteAgeHasNotExpired() {
when(clock.now()).thenReturn(MILLISECONDS.toNanos(1500L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
Expand All @@ -31,9 +32,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

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

@BeforeEach
Expand Down Expand Up @@ -107,7 +108,6 @@ public void checkDisabledbyDefault() {
}

@DisabledOnOpenJ9
@DisabledOnOs(OS.WINDOWS)
@Test
public void checkProfilerWorking() {
try (AutoConfigTestProperties props =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.List;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junitpioneer.jupiter.ClearSystemProperty;

class JmxScraperTest {
Expand Down Expand Up @@ -46,8 +48,10 @@ private static void testInvalidArguments(String... args) {
}

@Test
@DisabledOnOs(OS.WINDOWS)
void shouldCreateConfig_propertiesLoadedFromFile() throws InvalidArgumentException {
// Given
// Windows returns /C:/path/to/file, which is not a valid path for Path.get() in Java.
String filePath =
ClassLoader.getSystemClassLoader().getResource("validConfig.properties").getPath();
List<String> args = Arrays.asList("-config", filePath);
Expand Down
7 changes: 7 additions & 0 deletions opamp-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ dependencies {
val opampReleaseInfo = tasks.register<Download>("opampLastReleaseInfo") {
group = "opamp"
src("https://api.github.com/repos/open-telemetry/opamp-spec/releases/latest")
val token = System.getenv("GH_TOKEN")
if (token.isNullOrBlank()) {
logger.warn("No GitHub token found in environment variable GH_TOKEN. Rate limits may apply.")
} else {
header("Authorization", "Bearer $token")
header("X-GitHub-Api-Version", "2022-11-28")
}
dest(project.layout.buildDirectory.file("opamp/release.json"))
}

Expand Down
Loading