Skip to content
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

Ensure decaton works with older jdk #225

Merged
merged 10 commits into from
Mar 7, 2024
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
17 changes: 13 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Is this intentionally left or just forgot to remove line?

Copy link
Member Author

Choose a reason for hiding this comment

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

Intentionally. We need to install 21 always to build the project, regardless test-jdk version.
Last one will be used as the global java version (refs: https://github.com/actions/setup-java?tab=readme-ov-file#install-multiple-jdks)

Copy link
Member

Choose a reason for hiding this comment

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

ah-ok. now understand how it works


- 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
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@

@ExtendWith(MockitoExtension.class)
public class DecatonClientTest {
@Spy
private final DecatonClient<HelloTask> decaton = new DecatonClient<HelloTask>() {
private static class NoopClient implements DecatonClient<HelloTask> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Spying anonymous class fails on JDK8 with reflection error
https://github.com/line/decaton/actions/runs/8174863099/job/22350646261
image

I didn't want to dig into the detail as we likely drop JDK8-support in not-so-far-future so I just rewrote it with static class for now.

@Override
public CompletableFuture<PutTaskResult> put(String key, HelloTask task) {
return null;
Expand Down Expand Up @@ -73,7 +72,10 @@ public CompletableFuture<PutTaskResult> put(String key, HelloTask task,
public void close() throws Exception {
// noop
}
};
}

@Spy
private final DecatonClient<HelloTask> decaton = new NoopClient();

@Test
public void testPutAsyncHelperOnSuccess() throws Exception {
Expand Down
1 change: 0 additions & 1 deletion processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +35,7 @@
import com.linecorp.decaton.testing.RandomExtension;
import com.linecorp.decaton.testing.processor.ProcessorTestSuite;

@EnabledForJreRange(min = JRE.JAVA_21)
Copy link
Member

Choose a reason for hiding this comment

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

Oh... there's such a convenient annotation existed... !

public class VThreadCoreFunctionalityTest {
@RegisterExtension
public static KafkaClusterExtension rule = new KafkaClusterExtension();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HelloTask> {
Expand All @@ -90,6 +92,22 @@ public void process(ProcessingContext<HelloTask> ctx, HelloTask task)
}
}

@RequiredArgsConstructor
private static class AsyncCompleteProcessor implements DecatonProcessor<byte[]> {
private final CountDownLatch latch;

@Override
public void process(ProcessingContext<byte[]> 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 =
Expand Down Expand Up @@ -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<byte[]> retryProcessor = spy(
// This can't be a lambda for mockito
new DecatonProcessor<byte[]>() {
@Override
public void process(ProcessingContext<byte[]> context, byte[] task)
throws InterruptedException {
Completion comp = context.deferCompletion();
new Thread(() -> {
try {
retryLatch.await();
} catch (InterruptedException ignored) {}
comp.complete();
}).start();
}
});
DecatonProcessor<byte[]> 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<byte[]> task = new DecatonTask<>(
Expand Down Expand Up @@ -399,21 +403,7 @@ public void testRetry_NOT_CONFIGURED() throws InterruptedException {
@Timeout(5)
public void testRetryAtCompletionTimeout() throws InterruptedException {
CountDownLatch retryLatch = new CountDownLatch(1);
DecatonProcessor<byte[]> retryProcessor = spy(
// This can't be a lambda for mockito
new DecatonProcessor<byte[]>() {
@Override
public void process(ProcessingContext<byte[]> context, byte[] task)
throws InterruptedException {
Completion comp = context.deferCompletion();
new Thread(() -> {
try {
retryLatch.await();
} catch (InterruptedException ignored) {}
comp.complete();
}).start();
}
});
DecatonProcessor<byte[]> 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<byte[]> task = new DecatonTask<>(
Expand Down
3 changes: 2 additions & 1 deletion testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading