From 17f06c62c6aafe755539f686817b2b3afb2f08a5 Mon Sep 17 00:00:00 2001 From: Okada Haruki Date: Thu, 7 Mar 2024 17:34:25 +0900 Subject: [PATCH] Ensure decaton works with older jdk (#225) * Ensure decaton works with older jdk * fix * fix * fix * enable only for >= jdk21 * fix * fix * fix * fix * fix --- .github/workflows/ci.yml | 17 +++++-- build.gradle | 7 +++ .../decaton/client/DecatonClientTest.java | 8 +-- processor/build.gradle | 1 - .../VThreadCoreFunctionalityTest.java | 3 ++ .../internal/ProcessingContextImplTest.java | 50 ++++++++----------- testing/build.gradle | 3 +- 7 files changed, 50 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e4a2bd9..128bd702 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,14 +12,23 @@ jobs: strategy: fail-fast: false matrix: - java: [21] + java: [8, 11, 17, 21] steps: - uses: actions/checkout@v2 - name: Setup java - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: - java-version: ${{ matrix.java }} + distribution: temurin + java-version: | + ${{ matrix.java }} + 21 + - name: Execute test uses: eskatos/gradle-command-action@v1 with: - arguments: build jmhJar integrationTest + # Java is installed on JAVA_HOME_{java major version}_X64 + # refs: https://github.com/actions/setup-java/tree/v4.1.0?tab=readme-ov-file#install-multiple-jdks + arguments: | + -Ptest.java.major.version=${{ matrix.java }} + -Porg.gradle.java.installations.fromEnv=JAVA_HOME_${{ matrix.java }}_X64 + build jmhJar integrationTest diff --git a/build.gradle b/build.gradle index 91741dc9..1d32769f 100644 --- a/build.gradle +++ b/build.gradle @@ -105,6 +105,13 @@ subprojects { showStackTraces true showStandardStreams false } + def testJavaVersion = findProperty("test.java.major.version") + if (testJavaVersion != null) { + // https://docs.gradle.org/8.5/userguide/toolchains.html#toolchains_for_tasks + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(testJavaVersion) + } + } } afterEvaluate { diff --git a/client/src/test/java/com/linecorp/decaton/client/DecatonClientTest.java b/client/src/test/java/com/linecorp/decaton/client/DecatonClientTest.java index f1da8458..3c368948 100644 --- a/client/src/test/java/com/linecorp/decaton/client/DecatonClientTest.java +++ b/client/src/test/java/com/linecorp/decaton/client/DecatonClientTest.java @@ -39,8 +39,7 @@ @ExtendWith(MockitoExtension.class) public class DecatonClientTest { - @Spy - private final DecatonClient decaton = new DecatonClient() { + private static class NoopClient implements DecatonClient { @Override public CompletableFuture put(String key, HelloTask task) { return null; @@ -73,7 +72,10 @@ public CompletableFuture put(String key, HelloTask task, public void close() throws Exception { // noop } - }; + } + + @Spy + private final DecatonClient decaton = new NoopClient(); @Test public void testPutAsyncHelperOnSuccess() throws Exception { diff --git a/processor/build.gradle b/processor/build.gradle index ae16101e..764cde3e 100644 --- a/processor/build.gradle +++ b/processor/build.gradle @@ -19,7 +19,6 @@ dependencies { itImplementation project(":protobuf") itImplementation project(":testing") - itImplementation project(":benchmark") itImplementation "io.micrometer:micrometer-registry-prometheus:$micrometerVersion" itImplementation "org.hamcrest:hamcrest:$hamcrestVersion" } diff --git a/processor/src/it/java/com/linecorp/decaton/processor/VThreadCoreFunctionalityTest.java b/processor/src/it/java/com/linecorp/decaton/processor/VThreadCoreFunctionalityTest.java index 2546ecdb..f6e09008 100644 --- a/processor/src/it/java/com/linecorp/decaton/processor/VThreadCoreFunctionalityTest.java +++ b/processor/src/it/java/com/linecorp/decaton/processor/VThreadCoreFunctionalityTest.java @@ -22,6 +22,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.extension.RegisterExtension; import com.linecorp.decaton.processor.runtime.ProcessorProperties; @@ -33,6 +35,7 @@ import com.linecorp.decaton.testing.RandomExtension; import com.linecorp.decaton.testing.processor.ProcessorTestSuite; +@EnabledForJreRange(min = JRE.JAVA_21) public class VThreadCoreFunctionalityTest { @RegisterExtension public static KafkaClusterExtension rule = new KafkaClusterExtension(); diff --git a/processor/src/test/java/com/linecorp/decaton/processor/runtime/internal/ProcessingContextImplTest.java b/processor/src/test/java/com/linecorp/decaton/processor/runtime/internal/ProcessingContextImplTest.java index 7c451d9e..0333952d 100644 --- a/processor/src/test/java/com/linecorp/decaton/processor/runtime/internal/ProcessingContextImplTest.java +++ b/processor/src/test/java/com/linecorp/decaton/processor/runtime/internal/ProcessingContextImplTest.java @@ -67,6 +67,8 @@ import com.linecorp.decaton.protocol.Decaton.TaskMetadataProto; import com.linecorp.decaton.protocol.Sample.HelloTask; +import lombok.RequiredArgsConstructor; + @ExtendWith(MockitoExtension.class) public class ProcessingContextImplTest { private static class NamedProcessor implements DecatonProcessor { @@ -90,6 +92,22 @@ public void process(ProcessingContext ctx, HelloTask task) } } + @RequiredArgsConstructor + private static class AsyncCompleteProcessor implements DecatonProcessor { + private final CountDownLatch latch; + + @Override + public void process(ProcessingContext context, byte[] task) throws InterruptedException { + Completion comp = context.deferCompletion(); + new Thread(() -> { + try { + latch.await(); + } catch (InterruptedException ignored) {} + comp.complete(); + }).start(); + } + } + private static final HelloTask TASK = HelloTask.getDefaultInstance(); private static final DecatonTaskRequest REQUEST = @@ -354,21 +372,7 @@ public void testPush_Level2_MultiPush_SyncAndAsync() throws InterruptedException @Timeout(5) public void testRetry() throws InterruptedException { CountDownLatch retryLatch = new CountDownLatch(1); - DecatonProcessor retryProcessor = spy( - // This can't be a lambda for mockito - new DecatonProcessor() { - @Override - public void process(ProcessingContext context, byte[] task) - throws InterruptedException { - Completion comp = context.deferCompletion(); - new Thread(() -> { - try { - retryLatch.await(); - } catch (InterruptedException ignored) {} - comp.complete(); - }).start(); - } - }); + DecatonProcessor retryProcessor = spy(new AsyncCompleteProcessor(retryLatch)); TaskRequest request = new TaskRequest( new TopicPartition("topic", 1), 1, null, "TEST".getBytes(StandardCharsets.UTF_8), null, null, REQUEST.toByteArray(), null); DecatonTask task = new DecatonTask<>( @@ -399,21 +403,7 @@ public void testRetry_NOT_CONFIGURED() throws InterruptedException { @Timeout(5) public void testRetryAtCompletionTimeout() throws InterruptedException { CountDownLatch retryLatch = new CountDownLatch(1); - DecatonProcessor retryProcessor = spy( - // This can't be a lambda for mockito - new DecatonProcessor() { - @Override - public void process(ProcessingContext context, byte[] task) - throws InterruptedException { - Completion comp = context.deferCompletion(); - new Thread(() -> { - try { - retryLatch.await(); - } catch (InterruptedException ignored) {} - comp.complete(); - }).start(); - } - }); + DecatonProcessor retryProcessor = spy(new AsyncCompleteProcessor(retryLatch)); TaskRequest request = new TaskRequest( new TopicPartition("topic", 1), 1, null, "TEST".getBytes(StandardCharsets.UTF_8), null, null, REQUEST.toByteArray(), null); DecatonTask task = new DecatonTask<>( diff --git a/testing/build.gradle b/testing/build.gradle index 52a89abd..ccae003b 100644 --- a/testing/build.gradle +++ b/testing/build.gradle @@ -39,5 +39,6 @@ dependencies { implementation "org.junit.jupiter:junit-jupiter:$junitVersion" implementation "org.hamcrest:hamcrest:$hamcrestVersion" - testRuntimeOnly "ch.qos.logback:logback-classic:1.4.11" + // We keep using 1.3.x for a while until we drop Java 8 support. + runtimeOnly "ch.qos.logback:logback-classic:1.3.14" }