Skip to content

Commit 17f06c6

Browse files
authored
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
1 parent 83be0df commit 17f06c6

File tree

7 files changed

+50
-39
lines changed

7 files changed

+50
-39
lines changed

.github/workflows/ci.yml

+13-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
java: [21]
15+
java: [8, 11, 17, 21]
1616
steps:
1717
- uses: actions/checkout@v2
1818
- name: Setup java
19-
uses: actions/setup-java@v1
19+
uses: actions/setup-java@v4
2020
with:
21-
java-version: ${{ matrix.java }}
21+
distribution: temurin
22+
java-version: |
23+
${{ matrix.java }}
24+
21
25+
2226
- name: Execute test
2327
uses: eskatos/gradle-command-action@v1
2428
with:
25-
arguments: build jmhJar integrationTest
29+
# Java is installed on JAVA_HOME_{java major version}_X64
30+
# refs: https://github.com/actions/setup-java/tree/v4.1.0?tab=readme-ov-file#install-multiple-jdks
31+
arguments: |
32+
-Ptest.java.major.version=${{ matrix.java }}
33+
-Porg.gradle.java.installations.fromEnv=JAVA_HOME_${{ matrix.java }}_X64
34+
build jmhJar integrationTest

build.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ subprojects {
105105
showStackTraces true
106106
showStandardStreams false
107107
}
108+
def testJavaVersion = findProperty("test.java.major.version")
109+
if (testJavaVersion != null) {
110+
// https://docs.gradle.org/8.5/userguide/toolchains.html#toolchains_for_tasks
111+
javaLauncher = javaToolchains.launcherFor {
112+
languageVersion = JavaLanguageVersion.of(testJavaVersion)
113+
}
114+
}
108115
}
109116

110117
afterEvaluate {

client/src/test/java/com/linecorp/decaton/client/DecatonClientTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939

4040
@ExtendWith(MockitoExtension.class)
4141
public class DecatonClientTest {
42-
@Spy
43-
private final DecatonClient<HelloTask> decaton = new DecatonClient<HelloTask>() {
42+
private static class NoopClient implements DecatonClient<HelloTask> {
4443
@Override
4544
public CompletableFuture<PutTaskResult> put(String key, HelloTask task) {
4645
return null;
@@ -73,7 +72,10 @@ public CompletableFuture<PutTaskResult> put(String key, HelloTask task,
7372
public void close() throws Exception {
7473
// noop
7574
}
76-
};
75+
}
76+
77+
@Spy
78+
private final DecatonClient<HelloTask> decaton = new NoopClient();
7779

7880
@Test
7981
public void testPutAsyncHelperOnSuccess() throws Exception {

processor/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dependencies {
1919

2020
itImplementation project(":protobuf")
2121
itImplementation project(":testing")
22-
itImplementation project(":benchmark")
2322
itImplementation "io.micrometer:micrometer-registry-prometheus:$micrometerVersion"
2423
itImplementation "org.hamcrest:hamcrest:$hamcrestVersion"
2524
}

processor/src/it/java/com/linecorp/decaton/processor/VThreadCoreFunctionalityTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import org.junit.jupiter.api.Test;
2424
import org.junit.jupiter.api.Timeout;
25+
import org.junit.jupiter.api.condition.EnabledForJreRange;
26+
import org.junit.jupiter.api.condition.JRE;
2527
import org.junit.jupiter.api.extension.RegisterExtension;
2628

2729
import com.linecorp.decaton.processor.runtime.ProcessorProperties;
@@ -33,6 +35,7 @@
3335
import com.linecorp.decaton.testing.RandomExtension;
3436
import com.linecorp.decaton.testing.processor.ProcessorTestSuite;
3537

38+
@EnabledForJreRange(min = JRE.JAVA_21)
3639
public class VThreadCoreFunctionalityTest {
3740
@RegisterExtension
3841
public static KafkaClusterExtension rule = new KafkaClusterExtension();

processor/src/test/java/com/linecorp/decaton/processor/runtime/internal/ProcessingContextImplTest.java

+20-30
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
import com.linecorp.decaton.protocol.Decaton.TaskMetadataProto;
6868
import com.linecorp.decaton.protocol.Sample.HelloTask;
6969

70+
import lombok.RequiredArgsConstructor;
71+
7072
@ExtendWith(MockitoExtension.class)
7173
public class ProcessingContextImplTest {
7274
private static class NamedProcessor implements DecatonProcessor<HelloTask> {
@@ -90,6 +92,22 @@ public void process(ProcessingContext<HelloTask> ctx, HelloTask task)
9092
}
9193
}
9294

95+
@RequiredArgsConstructor
96+
private static class AsyncCompleteProcessor implements DecatonProcessor<byte[]> {
97+
private final CountDownLatch latch;
98+
99+
@Override
100+
public void process(ProcessingContext<byte[]> context, byte[] task) throws InterruptedException {
101+
Completion comp = context.deferCompletion();
102+
new Thread(() -> {
103+
try {
104+
latch.await();
105+
} catch (InterruptedException ignored) {}
106+
comp.complete();
107+
}).start();
108+
}
109+
}
110+
93111
private static final HelloTask TASK = HelloTask.getDefaultInstance();
94112

95113
private static final DecatonTaskRequest REQUEST =
@@ -354,21 +372,7 @@ public void testPush_Level2_MultiPush_SyncAndAsync() throws InterruptedException
354372
@Timeout(5)
355373
public void testRetry() throws InterruptedException {
356374
CountDownLatch retryLatch = new CountDownLatch(1);
357-
DecatonProcessor<byte[]> retryProcessor = spy(
358-
// This can't be a lambda for mockito
359-
new DecatonProcessor<byte[]>() {
360-
@Override
361-
public void process(ProcessingContext<byte[]> context, byte[] task)
362-
throws InterruptedException {
363-
Completion comp = context.deferCompletion();
364-
new Thread(() -> {
365-
try {
366-
retryLatch.await();
367-
} catch (InterruptedException ignored) {}
368-
comp.complete();
369-
}).start();
370-
}
371-
});
375+
DecatonProcessor<byte[]> retryProcessor = spy(new AsyncCompleteProcessor(retryLatch));
372376
TaskRequest request = new TaskRequest(
373377
new TopicPartition("topic", 1), 1, null, "TEST".getBytes(StandardCharsets.UTF_8), null, null, REQUEST.toByteArray(), null);
374378
DecatonTask<byte[]> task = new DecatonTask<>(
@@ -399,21 +403,7 @@ public void testRetry_NOT_CONFIGURED() throws InterruptedException {
399403
@Timeout(5)
400404
public void testRetryAtCompletionTimeout() throws InterruptedException {
401405
CountDownLatch retryLatch = new CountDownLatch(1);
402-
DecatonProcessor<byte[]> retryProcessor = spy(
403-
// This can't be a lambda for mockito
404-
new DecatonProcessor<byte[]>() {
405-
@Override
406-
public void process(ProcessingContext<byte[]> context, byte[] task)
407-
throws InterruptedException {
408-
Completion comp = context.deferCompletion();
409-
new Thread(() -> {
410-
try {
411-
retryLatch.await();
412-
} catch (InterruptedException ignored) {}
413-
comp.complete();
414-
}).start();
415-
}
416-
});
406+
DecatonProcessor<byte[]> retryProcessor = spy(new AsyncCompleteProcessor(retryLatch));
417407
TaskRequest request = new TaskRequest(
418408
new TopicPartition("topic", 1), 1, null, "TEST".getBytes(StandardCharsets.UTF_8), null, null, REQUEST.toByteArray(), null);
419409
DecatonTask<byte[]> task = new DecatonTask<>(

testing/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ dependencies {
3939
implementation "org.junit.jupiter:junit-jupiter:$junitVersion"
4040
implementation "org.hamcrest:hamcrest:$hamcrestVersion"
4141

42-
testRuntimeOnly "ch.qos.logback:logback-classic:1.4.11"
42+
// We keep using 1.3.x for a while until we drop Java 8 support.
43+
runtimeOnly "ch.qos.logback:logback-classic:1.3.14"
4344
}

0 commit comments

Comments
 (0)