Skip to content

Commit 51735e4

Browse files
authored
update sdk to support java 8 (microsoft#44)
* update sdk to support java 8 * change jdk8 vendor * change to linux excution file * resolve hard code issue in sdk build.gradle
1 parent f8a2dbf commit 51735e4

File tree

9 files changed

+39
-11
lines changed

9 files changed

+39
-11
lines changed

.github/workflows/build-validation.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ jobs:
2727
with:
2828
java-version: '11'
2929
distribution: 'microsoft'
30+
- name: set JDK_11 environment variable test compiling and running
31+
env:
32+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
33+
run: echo ::set-env name=JDK_11::$(echo $JAVA_HOME)
34+
- name: Set up JDK 8
35+
uses: actions/setup-java@v2
36+
with:
37+
java-version: '8'
38+
distribution: 'temurin'
3039
- name: Build with Gradle
3140
uses: gradle/gradle-build-action@bc3340afc5e3cc44f2321809ac090d731c13c514
3241
with:

azurefunctions/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ dependencies {
2121
implementation "com.google.protobuf:protobuf-java:${protocVersion}"
2222
}
2323

24+
sourceCompatibility = 8
25+
targetCompatibility = 8
26+
2427
publishing {
2528
publications {
2629
mavenPublication(MavenPublication) {

samples/src/main/java/io/durabletask/samples/FanOutFanInPattern.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.io.IOException;
88
import java.time.Duration;
9+
import java.util.Arrays;
910
import java.util.List;
1011
import java.util.StringTokenizer;
1112
import java.util.stream.Collectors;
@@ -23,7 +24,7 @@ public static void main(String[] args) throws IOException, InterruptedException
2324
final DurableTaskClient client = DurableTaskGrpcClient.newBuilder().build();
2425

2526
// The input is an arbitrary list of strings.
26-
List<String> listOfStrings = List.of(
27+
List<String> listOfStrings = Arrays.asList(
2728
"Hello, world!",
2829
"The quick brown fox jumps over the lazy dog.",
2930
"If a tree falls in the forest and there is no one there to hear it, does it make a sound?",

sdk/build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ archivesBaseName = 'durabletask-sdk'
1313
def grpcVersion = '1.38.0'
1414
def protocVersion = '3.12.0'
1515
def jacksonVersion = '2.12.3'
16+
def PATH_TO_TEST_JAVA_RUNTIME = "$System.env.JDK_11"
1617

1718
dependencies {
1819

@@ -33,6 +34,16 @@ dependencies {
3334
testImplementation('org.junit.jupiter:junit-jupiter')
3435
}
3536

37+
compileJava {
38+
sourceCompatibility = 1.8
39+
}
40+
compileTestJava {
41+
sourceCompatibility = 11
42+
targetCompatibility = 11
43+
options.fork = true
44+
options.forkOptions.executable = "${PATH_TO_TEST_JAVA_RUNTIME}/bin/javac"
45+
}
46+
3647
protobuf {
3748
protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
3849
plugins {
@@ -55,6 +66,10 @@ sourceSets {
5566
}
5667
}
5768

69+
tasks.withType(Test) {
70+
executable = new File("${PATH_TO_TEST_JAVA_RUNTIME}", 'bin/java')
71+
}
72+
5873
test {
5974
useJUnitPlatform {
6075
// Skip tests tagged as "integration" since those are slower

sdk/src/main/java/com/microsoft/durabletask/DurableTaskGrpcClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class DurableTaskGrpcClient extends DurableTaskClient {
2727
private final TaskHubSidecarServiceBlockingStub sidecarClient;
2828

2929
private DurableTaskGrpcClient(Builder builder) {
30-
this.dataConverter = Objects.requireNonNullElseGet(builder.dataConverter, JacksonDataConverter::new);
30+
this.dataConverter = builder.dataConverter != null ? builder.dataConverter : new JacksonDataConverter();
3131

3232
Channel sidecarGrpcChannel;
3333
if (builder.channel != null) {

sdk/src/main/java/com/microsoft/durabletask/DurableTaskGrpcWorker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private DurableTaskGrpcWorker(Builder builder) {
5454
}
5555

5656
this.sidecarClient = TaskHubSidecarServiceGrpc.newBlockingStub(sidecarGrpcChannel);
57-
this.dataConverter = Objects.requireNonNullElse(builder.dataConverter, new JacksonDataConverter());
57+
this.dataConverter = builder.dataConverter != null ? builder.dataConverter : new JacksonDataConverter();
5858
}
5959

6060
public void start() {
@@ -86,11 +86,11 @@ private String getSidecarAddress() {
8686
public void runAndBlock() throws InterruptedException {
8787
logger.log(Level.INFO, "Durable Task worker is connecting to sidecar at {0}.", this.getSidecarAddress());
8888

89-
var taskOrchestrationExecutor = new TaskOrchestrationExecutor(
89+
TaskOrchestrationExecutor taskOrchestrationExecutor = new TaskOrchestrationExecutor(
9090
this.orchestrationFactories,
9191
this.dataConverter,
9292
logger);
93-
var taskActivityExecutor = new TaskActivityExecutor(
93+
TaskActivityExecutor taskActivityExecutor = new TaskActivityExecutor(
9494
this.activityFactories,
9595
this.dataConverter,
9696
logger);

sdk/src/main/java/com/microsoft/durabletask/FailureDetails.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FailureDetails {
2424
this.stackTrace = errorDetails;
2525

2626
// Error message can be null for things like NullPointerException but the gRPC contract doesn't allow null
27-
this.errorMessage = Objects.requireNonNullElse(errorMessage, "");
27+
this.errorMessage = errorMessage != null ? errorMessage : "";
2828
this.isNonRetriable = isNonRetriable;
2929
}
3030

@@ -86,7 +86,7 @@ TaskFailureDetails toProto() {
8686
return TaskFailureDetails.newBuilder()
8787
.setErrorType(this.getErrorType())
8888
.setErrorMessage(this.getErrorMessage())
89-
.setStackTrace(StringValue.of(Objects.requireNonNullElse(this.getStackTrace(), "")))
89+
.setStackTrace(StringValue.of(this.getStackTrace() != null ? this.getStackTrace() : ""))
9090
.build();
9191
}
9292
}

sdk/src/main/java/com/microsoft/durabletask/OrchestrationRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static byte[] loadAndRun(byte[] triggerStateProtoBytes, TaskOrchestration
6464
}
6565

6666
// Register the passed orchestration as the default ("*") orchestration
67-
var orchestrationFactories = new HashMap<String, TaskOrchestrationFactory>();
67+
HashMap orchestrationFactories = new HashMap<String, TaskOrchestrationFactory>();
6868
orchestrationFactories.put("*", new TaskOrchestrationFactory() {
6969
@Override
7070
public String getName() {
@@ -77,7 +77,7 @@ public TaskOrchestration create() {
7777
}
7878
});
7979

80-
var taskOrchestrationExecutor = new TaskOrchestrationExecutor(
80+
TaskOrchestrationExecutor taskOrchestrationExecutor = new TaskOrchestrationExecutor(
8181
orchestrationFactories,
8282
new JacksonDataConverter(),
8383
logger);

sdk/src/main/java/com/microsoft/durabletask/RetryPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ private RetryPolicy(Builder builder) {
1818
this.maxNumberOfAttempts = builder.maxNumberOfAttempts;
1919
this.firstRetryInterval = builder.firstRetryInterval;
2020
this.backoffCoefficient = builder.backoffCoefficient;
21-
this.maxRetryInterval = Objects.requireNonNullElse(builder.maxRetryInterval, Duration.ZERO);
22-
this.retryTimeout = Objects.requireNonNullElse(builder.retryTimeout, Duration.ZERO);
21+
this.maxRetryInterval = builder.maxRetryInterval != null ? builder.maxRetryInterval : Duration.ZERO;
22+
this.retryTimeout = builder.retryTimeout != null ? builder.retryTimeout : Duration.ZERO;
2323
}
2424

2525
public static Builder newBuilder(int maxNumberOfAttempts, Duration firstRetryInterval) {

0 commit comments

Comments
 (0)