Skip to content

Commit 1ad4608

Browse files
authored
Upgrade dependencies & code cleanup (temporalio#1355)
1 parent 6fae1a5 commit 1ad4608

14 files changed

+63
-123
lines changed

build.gradle

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ plugins {
1010
id 'org.cadixdev.licenser' version '0.6.1'
1111
id 'com.palantir.git-version' version "${palantirGitVersionVersion}" apply false
1212
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
13-
id 'com.diffplug.spotless' version '6.9.0' apply false
13+
id 'com.diffplug.spotless' version '6.9.1' apply false
1414
id 'com.github.nbaztec.coveralls-jacoco' version "1.2.14" apply false
1515

1616
// id 'org.jetbrains.kotlin.jvm' version '1.4.32'
1717
// id 'org.jetbrains.kotlin.jvm' version '1.5.32'
18-
// id 'org.jetbrains.kotlin.jvm' version '1.6.20'
18+
// id 'org.jetbrains.kotlin.jvm' version '1.6.21'
19+
// id 'org.jetbrains.kotlin.jvm' version '1.7.10'
1920
id 'org.jetbrains.kotlin.jvm' version "${kotlinVersion}" apply false
2021
id 'base'
2122
}
@@ -30,10 +31,10 @@ ext {
3031
// Platforms
3132
grpcVersion = '1.48.1' // [1.34.0,)
3233
jacksonVersion = '2.13.1' // [2.9.0,)
33-
micrometerVersion = '1.9.2' // [1.0.0,)
34+
micrometerVersion = '1.9.3' // [1.0.0,)
3435

3536
slf4jVersion = '1.7.36' // [1.4.0,)
36-
protoVersion = '3.21.4' // [3.10.0,)
37+
protoVersion = '3.21.5' // [3.10.0,)
3738
annotationApiVersion = '1.3.2'
3839
guavaVersion = '31.1-jre' // [10.0,)
3940
tallyVersion = '0.11.1' // [0.4.0,)
@@ -44,7 +45,7 @@ ext {
4445

4546
// test scoped
4647
logbackVersion = '1.2.11'
47-
mockitoVersion = '4.6.1'
48+
mockitoVersion = '4.7.0'
4849
junitVersion = '4.13.2'
4950
}
5051

gradle/wrapper/gradle-wrapper.jar

935 Bytes
Binary file not shown.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

+6
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ set -- \
205205
org.gradle.wrapper.GradleWrapperMain \
206206
"$@"
207207

208+
# Stop when "xargs" is not available.
209+
if ! command -v xargs >/dev/null 2>&1
210+
then
211+
die "xargs is not available"
212+
fi
213+
208214
# Use "xargs" to parse quoted args.
209215
#
210216
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

gradlew.bat

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@rem limitations under the License.
1515
@rem
1616

17-
@if "%DEBUG%" == "" @echo off
17+
@if "%DEBUG%"=="" @echo off
1818
@rem ##########################################################################
1919
@rem
2020
@rem Gradle startup script for Windows
@@ -25,7 +25,7 @@
2525
if "%OS%"=="Windows_NT" setlocal
2626

2727
set DIRNAME=%~dp0
28-
if "%DIRNAME%" == "" set DIRNAME=.
28+
if "%DIRNAME%"=="" set DIRNAME=.
2929
set APP_BASE_NAME=%~n0
3030
set APP_HOME=%DIRNAME%
3131

@@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4040

4141
set JAVA_EXE=java.exe
4242
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
43+
if %ERRORLEVEL% equ 0 goto execute
4444

4545
echo.
4646
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7575

7676
:end
7777
@rem End local scope for the variables with windows NT shell
78-
if "%ERRORLEVEL%"=="0" goto mainEnd
78+
if %ERRORLEVEL% equ 0 goto mainEnd
7979

8080
:fail
8181
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
8282
rem the _cmd.exe /c_ return code!
83-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84-
exit /b 1
83+
set EXIT_CODE=%ERRORLEVEL%
84+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
85+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
86+
exit /b %EXIT_CODE%
8587

8688
:mainEnd
8789
if "%OS%"=="Windows_NT" endlocal

temporal-sdk/src/main/java/io/temporal/internal/client/ActivityClientHelper.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
* ManualActivityCompletionClient}, because they are not intended to be called by our users
4444
* directly.
4545
*/
46-
public class ActivityClientHelper {
46+
public final class ActivityClientHelper {
47+
private ActivityClientHelper() {}
48+
4749
public static RecordActivityTaskHeartbeatResponse sendHeartbeatRequest(
4850
WorkflowServiceStubs service,
4951
String namespace,

temporal-sdk/src/main/java/io/temporal/internal/client/WorkflowClientLongPollHelper.java

+2-20
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
/** This class encapsulates sync long poll logic of {@link RootWorkflowClientInvoker} */
4444
final class WorkflowClientLongPollHelper {
45+
private WorkflowClientLongPollHelper() {}
46+
4547
/**
4648
* Returns result of a workflow instance execution or throws an exception if workflow did not
4749
* complete successfully. Will wait for continue-as-new executions of the original workflow
@@ -69,26 +71,6 @@ static Optional<Payloads> getWorkflowExecutionResult(
6971
workflowExecution, workflowType, closeEvent, converter);
7072
}
7173

72-
/**
73-
* Waits up to specified timeout for workflow instance completion.
74-
*
75-
* @param workflowExecution workflowId and optional runId
76-
* @param timeout maximum time to wait for completion. 0 means wait forever.
77-
* @return instance close status
78-
*/
79-
static WorkflowExecutionStatus waitForWorkflowInstanceCompletion(
80-
GenericWorkflowClient genericClient,
81-
WorkflowClientRequestFactory workflowClientHelper,
82-
@Nonnull WorkflowExecution workflowExecution,
83-
long timeout,
84-
TimeUnit unit)
85-
throws TimeoutException {
86-
HistoryEvent closeEvent =
87-
getInstanceCloseEvent(
88-
genericClient, workflowClientHelper, workflowExecution, timeout, unit);
89-
return WorkflowExecutionUtils.getCloseStatus(closeEvent);
90-
}
91-
9274
/**
9375
* @param timeout timeout to retrieve InstanceCloseEvent in {@code unit} units. If 0 - MAX_INTEGER
9476
* will be used

temporal-sdk/src/main/java/io/temporal/internal/client/external/ManualActivityCompletionClientFactory.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.temporal.api.common.v1.WorkflowExecution;
2626
import io.temporal.common.converter.DataConverter;
2727
import io.temporal.serviceclient.WorkflowServiceStubs;
28+
import javax.annotation.Nonnull;
2829

2930
public interface ManualActivityCompletionClientFactory {
3031

@@ -33,16 +34,16 @@ public interface ManualActivityCompletionClientFactory {
3334
* ManualActivityCompletionClientImpl} implementations
3435
*/
3536
static ManualActivityCompletionClientFactory newFactory(
36-
WorkflowServiceStubs service,
37-
String namespace,
38-
String identity,
39-
DataConverter dataConverter) {
37+
@Nonnull WorkflowServiceStubs service,
38+
@Nonnull String namespace,
39+
@Nonnull String identity,
40+
@Nonnull DataConverter dataConverter) {
4041
return new ManualActivityCompletionClientFactoryImpl(
4142
service, namespace, identity, dataConverter);
4243
}
4344

44-
ManualActivityCompletionClient getClient(byte[] taskToken, Scope metricsScope);
45+
ManualActivityCompletionClient getClient(@Nonnull byte[] taskToken, Scope metricsScope);
4546

4647
ManualActivityCompletionClient getClient(
47-
WorkflowExecution execution, String activityId, Scope metricsScope);
48+
@Nonnull WorkflowExecution execution, @Nonnull String activityId, Scope metricsScope);
4849
}

temporal-sdk/src/main/java/io/temporal/internal/client/external/ManualActivityCompletionClientFactoryImpl.java

+13-36
Original file line numberDiff line numberDiff line change
@@ -20,68 +20,45 @@
2020

2121
package io.temporal.internal.client.external;
2222

23+
import com.google.common.base.Preconditions;
2324
import com.uber.m3.tally.Scope;
2425
import io.temporal.activity.ManualActivityCompletionClient;
2526
import io.temporal.api.common.v1.WorkflowExecution;
2627
import io.temporal.common.converter.DataConverter;
2728
import io.temporal.serviceclient.WorkflowServiceStubs;
2829
import java.util.Objects;
30+
import javax.annotation.Nonnull;
2931

3032
class ManualActivityCompletionClientFactoryImpl implements ManualActivityCompletionClientFactory {
31-
3233
private final WorkflowServiceStubs service;
3334
private final DataConverter dataConverter;
3435
private final String namespace;
3536
private final String identity;
3637

37-
public ManualActivityCompletionClientFactoryImpl(
38-
WorkflowServiceStubs service,
39-
String namespace,
40-
String identity,
41-
DataConverter dataConverter) {
38+
ManualActivityCompletionClientFactoryImpl(
39+
@Nonnull WorkflowServiceStubs service,
40+
@Nonnull String namespace,
41+
@Nonnull String identity,
42+
@Nonnull DataConverter dataConverter) {
4243
this.service = Objects.requireNonNull(service);
4344
this.namespace = Objects.requireNonNull(namespace);
4445
this.identity = Objects.requireNonNull(identity);
4546
this.dataConverter = Objects.requireNonNull(dataConverter);
4647
}
4748

48-
public WorkflowServiceStubs getService() {
49-
return service;
50-
}
51-
52-
public DataConverter getDataConverter() {
53-
return dataConverter;
54-
}
55-
5649
@Override
57-
public ManualActivityCompletionClient getClient(byte[] taskToken, Scope metricsScope) {
58-
// Map<String, String> tags =
59-
// new ImmutableMap.Builder<String, String>(1).put(MetricsTag.NAMESPACE,
60-
// namespace).build();
61-
// this.metricsScope = metricsScope.tagged(tags);
62-
63-
if (service == null) {
64-
throw new IllegalStateException("required property service is null");
65-
}
66-
if (dataConverter == null) {
67-
throw new IllegalStateException("required property dataConverter is null");
68-
}
69-
if (taskToken == null || taskToken.length == 0) {
70-
throw new IllegalArgumentException("null or empty task token");
71-
}
50+
public ManualActivityCompletionClient getClient(@Nonnull byte[] taskToken, Scope metricsScope) {
51+
Preconditions.checkArgument(
52+
taskToken != null && taskToken.length > 0, "null or empty task token");
7253
return new ManualActivityCompletionClientImpl(
7354
service, namespace, identity, taskToken, dataConverter, metricsScope);
7455
}
7556

7657
@Override
7758
public ManualActivityCompletionClient getClient(
78-
WorkflowExecution execution, String activityId, Scope metricsScope) {
79-
if (execution == null) {
80-
throw new IllegalArgumentException("null execution");
81-
}
82-
if (activityId == null) {
83-
throw new IllegalArgumentException("null activityId");
84-
}
59+
@Nonnull WorkflowExecution execution, @Nonnull String activityId, Scope metricsScope) {
60+
Preconditions.checkArgument(execution != null, "null execution");
61+
Preconditions.checkArgument(activityId != null, "null activityId");
8562
return new ManualActivityCompletionClientImpl(
8663
service, namespace, identity, execution, activityId, dataConverter, metricsScope);
8764
}

temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowInfoImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public String getCronSchedule() {
115115

116116
@Override
117117
public String toString() {
118-
return "ActivityInfo{"
118+
return "WorkflowInfo{"
119119
+ "namespace="
120120
+ getNamespace()
121121
+ ", workflowId="

temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowQueueImpl.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package io.temporal.internal.sync;
2222

23+
import com.google.common.base.Preconditions;
2324
import io.temporal.workflow.CancellationScope;
2425
import io.temporal.workflow.Functions;
2526
import io.temporal.workflow.QueueConsumer;
@@ -34,9 +35,7 @@ final class WorkflowQueueImpl<E> implements WorkflowQueue<E> {
3435
private final int capacity;
3536

3637
public WorkflowQueueImpl(int capacity) {
37-
if (capacity < 1) {
38-
throw new IllegalArgumentException("Capacity less than 1: " + capacity);
39-
}
38+
Preconditions.checkState(capacity > 0, "capacity must be > 0");
4039
this.capacity = capacity;
4140
}
4241

temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowThreadContext.java

+8-26
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package io.temporal.internal.sync;
2222

23+
import com.google.common.base.Preconditions;
2324
import com.google.common.base.Throwables;
2425
import io.temporal.internal.common.DebugModeUtils;
2526
import io.temporal.workflow.Functions;
@@ -71,9 +72,7 @@ public void initialYield() {
7172
if (status == Status.DONE) {
7273
throw new DestroyWorkflowThreadError("done in initialYield");
7374
}
74-
if (status != Status.RUNNING) {
75-
throw new IllegalStateException("not in RUNNING but in " + status + " state");
76-
}
75+
Preconditions.checkState(status == Status.RUNNING, "threadContext not in RUNNING state");
7776
this.yield("created", () -> true);
7877
}
7978

@@ -143,9 +142,7 @@ private void maybeEvaluateLocked(String reason) {
143142
public void evaluateInCoroutineContext(Functions.Proc1<String> function) {
144143
lock.lock();
145144
try {
146-
if (function == null) {
147-
throw new IllegalArgumentException("null function");
148-
}
145+
Preconditions.checkArgument(function != null, "null function");
149146
if (status != Status.YIELDED && status != Status.RUNNING) {
150147
throw new IllegalStateException("Not in yielded status: " + status);
151148
}
@@ -160,9 +157,7 @@ public void evaluateInCoroutineContext(Functions.Proc1<String> function) {
160157
// A more explicit solution may be implemented using a separate lock for evaluate calls.
161158
throw new IllegalStateException("Already evaluating");
162159
}
163-
if (inRunUntilBlocked) {
164-
throw new IllegalStateException("Running runUntilBlocked");
165-
}
160+
Preconditions.checkState(!inRunUntilBlocked, "Running runUntilBlocked");
166161
evaluationFunction = function;
167162
status = Status.EVALUATING;
168163
yieldCondition.signal();
@@ -249,9 +244,8 @@ public boolean runUntilBlocked(long deadlockDetectionTimeoutMs) {
249244
if (status == Status.DONE) {
250245
return false;
251246
}
252-
if (evaluationFunction != null) {
253-
throw new IllegalStateException("Cannot runUntilBlocked while evaluating");
254-
}
247+
Preconditions.checkState(
248+
evaluationFunction == null, "Cannot runUntilBlocked while evaluating");
255249
inRunUntilBlocked = true;
256250
if (status == Status.YIELDED) {
257251
// we have to swap it here to allow potentialProgressStatesLocked to start returning true
@@ -279,9 +273,8 @@ && potentialProgressStatesLocked()) {
279273
throw new PotentialDeadlockException("UnknownThread", this, detectionTimestamp);
280274
}
281275
}
282-
if (evaluationFunction != null) {
283-
throw new IllegalStateException("Cannot runUntilBlocked while evaluating");
284-
}
276+
Preconditions.checkState(
277+
evaluationFunction == null, "Cannot runUntilBlocked while evaluating");
285278
}
286279
return !remainedBlocked;
287280
} catch (InterruptedException e) {
@@ -342,17 +335,6 @@ void initiateDestroy() {
342335
}
343336
}
344337

345-
/** To be called only from a workflow thread. */
346-
public void exit() {
347-
lock.lock();
348-
try {
349-
destroyRequested = true;
350-
} finally {
351-
lock.unlock();
352-
}
353-
throw new DestroyWorkflowThreadError();
354-
}
355-
356338
public void initializeCurrentThread(Thread currentThread) {
357339
lock.lock();
358340
try {

0 commit comments

Comments
 (0)