Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrsmith committed Nov 8, 2024
1 parent 1d71f9f commit bcf302b
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
17 changes: 17 additions & 0 deletions clock-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,21 @@ dependencies {
implementation project(':clock')
compileOnly libs.autoservice
annotationProcessor libs.autoservice.compiler

testImplementation libs.assertj
testImplementation platform(libs.junit.bom)
testImplementation libs.junit.jupiter
testRuntimeOnly libs.junit.platform.launcher
}

test {
useJUnitPlatform()
}

// TODO(deephaven-core#6345): Improve build process for jars that depend on JVM internals
// In the meantime, we can be relatively confident this JAR works for the multiple versions of java since we do nightly
// tests with a range of testRuntimeVersions.

tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ['--add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED']
// Explicitly unset release so gradle will invoke javac with `-source <languageLevel> -target <languageLevel>`
Expand All @@ -21,3 +34,7 @@ tasks.withType(JavaCompile).configureEach {
tasks.withType(Javadoc).configureEach {
options.addStringOption('-add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED')
}

tasks.withType(Test).configureEach {
jvmArgs += ['--add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED']
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.base.clock;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.Instant;

import static org.assertj.core.api.Assertions.assertThat;

class SystemClockJdkInternalMiscVmTest {

private SystemClockJdkInternalMiscVm SUT;

@BeforeEach
void setUp() {
SUT = new SystemClockJdkInternalMiscVm();
}

@Test
void currentTimeMillis() {
assertThat(SUT.currentTimeMillis()).isPositive();
}

@Test
void currentTimeMicros() {
assertThat(SUT.currentTimeMicros()).isPositive();
}

@Test
void currentTimeNanos() {
assertThat(SUT.currentTimeNanos()).isPositive();
}

@Test
void instantMillis() {
assertThat(SUT.instantMillis()).isAfter(Instant.EPOCH);
}

@Test
void instantNanos() {
assertThat(SUT.instantNanos()).isAfter(Instant.EPOCH);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.base.clock;

import org.junit.jupiter.api.Test;

import java.lang.reflect.InvocationTargetException;

import static org.assertj.core.api.Assertions.assertThat;

class SystemClockTest {
@Test
void of() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException,
InstantiationException, IllegalAccessException {
assertThat(SystemClock.of()).isExactlyInstanceOf(SystemClockJdkInternalMiscVm.class);
}

@Test
void serviceLoader() {
assertThat(SystemClock.serviceLoader()).get().isExactlyInstanceOf(SystemClockJdkInternalMiscVm.class);
}
}
18 changes: 18 additions & 0 deletions hotspot-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@ dependencies {
implementation project(':hotspot')
compileOnly libs.autoservice
annotationProcessor libs.autoservice.compiler

testImplementation libs.assertj
testImplementation platform(libs.junit.bom)
testImplementation libs.junit.jupiter
testRuntimeOnly libs.junit.platform.launcher
}

test {
useJUnitPlatform()
}

// TODO(deephaven-core#6345): Improve build process for jars that depend on JVM internals
// In the meantime, we can be relatively confident this JAR works for the multiple versions of java since we do nightly
// tests with a range of testRuntimeVersions.

tasks.withType(JavaCompile).configureEach {
// TODO(deephaven-core#6345): Improve build process for jars that depend on JVM internals
options.compilerArgs += ['--add-exports', 'java.management/sun.management=ALL-UNNAMED']
// Explicitly unset release so gradle will invoke javac with `-source <languageLevel> -target <languageLevel>`
// instead of `--release <languageLevel>`, which would otherwise produce
Expand All @@ -21,3 +35,7 @@ tasks.withType(JavaCompile).configureEach {
tasks.withType(Javadoc).configureEach {
options.addStringOption('-add-exports', 'java.management/sun.management=ALL-UNNAMED')
}

tasks.withType(Test).configureEach {
jvmArgs += ['--add-exports', 'java.management/sun.management=ALL-UNNAMED']
}
17 changes: 17 additions & 0 deletions hotspot-impl/src/test/java/io/deephaven/hotspot/HotSpotTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.hotspot;

import io.deephaven.hotspot.impl.HotSpotImpl;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class HotSpotTest {

@Test
void loadImpl() {
assertThat(HotSpot.loadImpl()).get().isExactlyInstanceOf(HotSpotImpl.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.hotspot.impl;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class HotSpotImplTest {

private HotSpotImpl SUT;

@BeforeEach
void setUp() {
SUT = new HotSpotImpl();
}

@Test
void getSafepointCount() {
assertThat(SUT.getSafepointCount()).isNotNegative();
}

@Test
void getTotalSafepointTimeMillis() {
assertThat(SUT.getTotalSafepointTimeMillis()).isNotNegative();
}

@Test
void getSafepointSyncTimeMillis() {
assertThat(SUT.getSafepointSyncTimeMillis()).isNotNegative();
}
}

0 comments on commit bcf302b

Please sign in to comment.