8000 Don't apply Checker Framework to tests by andrewaylett · Pull Request #112 · andrewaylett/arc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't apply Checker Framework to tests #112

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

Merged
merged 1 commit into from
May 31, 2025
Merged
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
2 changes: 2 additions & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ java {
testing {
suites {
// Configure the built-in test suite
@Suppress("unused")
val test by
getting(JvmTestSuite::class) {
// Use JUnit Jupiter test framework
Expand All @@ -81,6 +82,7 @@ configure<CheckerFrameworkExtension> {
"org.checkerframework.common.initializedfields.InitializedFieldsChecker",
"org.checkerframework.checker.lock.LockChecker",
)
excludeTests = true
Copy link
Preview
Copilot AI May 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a brief comment explaining that tests are being excluded from Checker Framework processing, to clarify the reasoning for future maintainers.

Copilot uses AI. Check for mistakes.

}

spotless {
Expand Down
38 changes: 12 additions & 26 deletions lib/src/test/java/eu/aylett/arc/ArcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@

package eu.aylett.arc;

import org.checkerframework.checker.initialization.qual.Initialized;
import org.checkerframework.checker.lock.qual.GuardedBy;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.PolyNull;
import org.hamcrest.Matcher;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.jspecify.annotations.NonNull;
import org.junit.jupiter.api.Test;

import java.time.Duration;
Expand All @@ -46,7 +40,9 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
Expand All @@ -56,17 +52,7 @@
import static java.util.Collections.synchronizedList;
import static java.util.concurrent.TimeUnit.SECONDS;

@SuppressWarnings({"argument", "type.argument", "method.guarantee.violated", "type.arguments.not.inferred", "argument",
"methodref.receiver", "dereference.of.nullable"})
class ArcTest {
public static <T> org.hamcrest.Matcher<@GuardedBy @PolyNull @Initialized T> equalTo(@GuardedBy @PolyNull T operand) {
return org.hamcrest.core.IsEqual.equalTo(operand);
}

public static <T> void assertThat(@GuardedBy @PolyNull T actual, Matcher<? super @GuardedBy @PolyNull T> matcher) {
MatcherAssert.assertThat("", actual, matcher);
}

@Test
void test() {
var arc = new Arc<>(1, i -> "" + i, ForkJoinPool.commonPool());
Expand All @@ -92,14 +78,14 @@ void testEviction() {
assertThat(arc.get(1), equalTo("1")); // This should reload "1" as it was evicted

// Check that the loader function was called with the expected values
assertThat(recordedValues, equalTo(List.<@GuardedBy Integer>of(1, 2, 1)));
assertThat(recordedValues, equalTo(List.of(1, 2, 1)));

arc.checkSafety();
}

@Test
void testMultipleElements() {
var recordedValues = new ArrayList<@NonNull Integer>();
var recordedValues = new ArrayList<Integer>();
var arc = new Arc<Integer, String>(4, i -> {
recordedValues.add(i);
return i.toString();
Expand All @@ -111,26 +97,26 @@ void testMultipleElements() {
assertThat(arc.get(2), equalTo("2"));

// Check that the loader function was called with the expected values
assertThat(recordedValues, equalTo(List.<@GuardedBy Integer>of(1, 2)));
assertThat(recordedValues, equalTo(List.of(1, 2)));
}

@Test
void testLFUElements() {
var recordedValues = synchronizedList(new ArrayList<@NonNull Integer>());
var recordedValues = synchronizedList(new ArrayList<Integer>());
var arc = new Arc<Integer, String>(5, i -> {
recordedValues.add(i);
return i.toString();
}, ForkJoinPool.commonPool());

var expectedValues = new ArrayList<@NonNull Integer>();
var expectedValues = new ArrayList<Integer>();
arc.get(1);

for (var i = 1; i <= 50; i++) {
arc.get(i);
expectedValues.add(i);
}

// Should not have been eviced, so we won't record it again.
// Should not have been evicted, so we won't record it again.
arc.get(1);

synchronized (recordedValues) {
Expand Down Expand Up @@ -254,7 +240,7 @@ void repeatedElementsAreRefreshed() {
arc.get(-1);
}
clock.value.addAndGet(1);
if (i % 1000 == 0) {
if (i % 100 == 0) {
arc.checkSafety();
}
}
Expand Down Expand Up @@ -371,14 +357,14 @@ void testLoaderRetriesAfterException() {

var ex = assertThrowsExactly(CompletionException.class, () -> arc.get(1));
var cause = ex.getCause();
assertThat(cause.getMessage(), Matchers.equalTo("Loader failed"));
assertThat(cause.getMessage(), equalTo("Loader failed"));

assertThat(arc.get(2), equalTo("2"));
assertThat(arc.get(1), equalTo("1"));
}

@Test
void testConcurrentAccessWithSameKey() throws InterruptedException {
void testConcurrentAccessWithSameKey() {
var pool = ForkJoinPool.commonPool();
var arc = new Arc<Integer, String>(10, i -> {
try {
Expand Down
Loading
0