Skip to content

Commit

Permalink
Review issues
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kec <[email protected]>
  • Loading branch information
danielkec committed Dec 19, 2024
1 parent 2ff7100 commit 6d84b58
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 49 deletions.
29 changes: 0 additions & 29 deletions common/testing/virtual-threads/etc/spotbugs/exclude.xml

This file was deleted.

1 change: 1 addition & 0 deletions common/testing/virtual-threads/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<groupId>io.helidon.common.testing</groupId>
<artifactId>helidon-common-testing-project</artifactId>
<version>4.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>helidon-common-testing-virtual-threads</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import jdk.jfr.consumer.RecordedEvent;

/**
* Exception used for reporting of Virtual Thread pinning detected during test.
* Assertion error used for reporting of Virtual Thread pinning detected during test.
*/
public class PinningException extends AssertionError {
public class PinningAssertionError extends AssertionError {

/**
* Pinning JFR event.
Expand All @@ -33,7 +33,7 @@ public class PinningException extends AssertionError {
*
* @param recordedEvent pinning JFR event
*/
PinningException(RecordedEvent recordedEvent) {
PinningAssertionError(RecordedEvent recordedEvent) {
this.recordedEvent = recordedEvent;
if (recordedEvent.getStackTrace() != null) {
StackTraceElement[] stackTraceElements = recordedEvent.getStackTrace().getFrames().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class PinningRecorder implements AutoCloseable {
public static final long DEFAULT_THRESHOLD = 20;
private static final String JFR_EVENT_VIRTUAL_THREAD_PINNED = "jdk.VirtualThreadPinned";
private final RecordingStream recordingStream = new RecordingStream();
private volatile PinningException pinningException;
private volatile PinningAssertionError pinningAssertionError;

private PinningRecorder() {
//noop
Expand Down Expand Up @@ -72,17 +72,17 @@ public void close() {
}

void checkAndThrow() {
if (pinningException != null) {
throw pinningException;
if (pinningAssertionError != null) {
throw pinningAssertionError;
}
}

private void record(RecordedEvent event) {
PinningException e = new PinningException(event);
if (pinningException == null) {
pinningException = e;
PinningAssertionError e = new PinningAssertionError(event);
if (pinningAssertionError == null) {
pinningAssertionError = e;
} else {
pinningException.addSuppressed(e);
pinningAssertionError.addSuppressed(e);
}
}
}
4 changes: 2 additions & 2 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<version.lib.jersey>3.1.9</version.lib.jersey>
<version.lib.jgit>6.7.0.202309050840-r</version.lib.jgit>
<version.lib.junit>5.9.3</version.lib.junit>
<version.lib.junit-platform-teskit>1.11.3</version.lib.junit-platform-teskit>
<version.lib.junit-platform-testkit>1.11.3</version.lib.junit-platform-testkit>
<version.lib.kafka>3.8.1</version.lib.kafka>
<version.lib.log4j>2.21.1</version.lib.log4j>
<version.lib.logback>1.4.14</version.lib.logback>
Expand Down Expand Up @@ -1288,7 +1288,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-testkit</artifactId>
<version>${version.lib.junit-platform-teskit}</version>
<version>${version.lib.junit-platform-testkit}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.Arrays;

import io.helidon.common.testing.virtualthreads.PinningException;
import io.helidon.common.testing.virtualthreads.PinningAssertionError;
import io.helidon.microprofile.testing.junit5.AddBean;
import io.helidon.microprofile.testing.junit5.HelidonTest;

Expand Down Expand Up @@ -66,7 +66,7 @@ void engineTest() {

private Condition<org.junit.platform.testkit.engine.Event> failedWithPinningException(String expectedPinningMethodName) {
return finishedWithFailure(
instanceOf(PinningException.class),
instanceOf(PinningAssertionError.class),
message(m -> m.startsWith("Pinned virtual threads were detected"))
, new Condition<>(where(
t -> Arrays.stream(t.getStackTrace()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.Arrays;

import io.helidon.common.testing.virtualthreads.PinningException;
import io.helidon.common.testing.virtualthreads.PinningAssertionError;
import io.helidon.microprofile.tests.testing.testng.programmatic.PinningExtraThreadTest;

import org.hamcrest.BaseMatcher;
Expand All @@ -42,9 +42,9 @@ void testListener() {
testng.setTestClasses(new Class[] {PinningExtraThreadTest.class});
TestListenerAdapter tla = new TestListenerAdapter();
testng.addListener(tla);
PinningException pinningException = Assert.expectThrows(PinningException.class, testng::run);
assertThat(pinningException.getMessage(), startsWith("Pinned virtual threads were detected:"));
assertThat("Method with pinning is missing from stack strace.", Arrays.asList(pinningException.getStackTrace()),
PinningAssertionError pinningAssertionError = Assert.expectThrows(PinningAssertionError.class, testng::run);
assertThat(pinningAssertionError.getMessage(), startsWith("Pinned virtual threads were detected:"));
assertThat("Method with pinning is missing from stack strace.", Arrays.asList(pinningAssertionError.getStackTrace()),
hasItem(new StackTraceElementMatcher(EXPECTED_PINNING_METHOD_NAME)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.Arrays;

import io.helidon.common.testing.virtualthreads.PinningException;
import io.helidon.common.testing.virtualthreads.PinningAssertionError;
import io.helidon.webclient.api.WebClient;
import io.helidon.webserver.http.HttpRouting;

Expand Down Expand Up @@ -62,7 +62,7 @@ void engineTest() {

private Condition<org.junit.platform.testkit.engine.Event> failedWithPinningException(String expectedPinningMethodName) {
return finishedWithFailure(
instanceOf(PinningException.class),
instanceOf(PinningAssertionError.class),
message(m -> m.startsWith("Pinned virtual threads were detected"))
, new Condition<>(
t -> Arrays.stream(t.getStackTrace())
Expand Down

0 comments on commit 6d84b58

Please sign in to comment.