Skip to content

Commit 32fbf02

Browse files
Fix kotlin child workflow execute varargs (#2395)
* Fix kotlin child workflow execute varargs * Fix untyped activity execute kotlin varargs
1 parent 76630fe commit 32fbf02

File tree

4 files changed

+225
-4
lines changed

4 files changed

+225
-4
lines changed

temporal-kotlin/src/main/kotlin/io/temporal/workflow/ActivityStubExt.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import kotlin.reflect.typeOf
3333
*/
3434
@OptIn(ExperimentalStdlibApi::class)
3535
inline fun <reified T> ActivityStub.execute(activityName: String, vararg args: Any?): T {
36-
return execute(activityName, T::class.java, typeOf<T>().javaType, args)
36+
return execute(activityName, T::class.java, typeOf<T>().javaType, *args)
3737
}
3838

3939
/**
@@ -49,5 +49,5 @@ inline fun <reified T> ActivityStub.executeAsync(
4949
activityName: String,
5050
vararg args: Any?
5151
): Promise<T> {
52-
return executeAsync(activityName, T::class.java, typeOf<T>().javaType, args)
52+
return executeAsync(activityName, T::class.java, typeOf<T>().javaType, *args)
5353
}

temporal-kotlin/src/main/kotlin/io/temporal/workflow/ChildWorkflowStubExt.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ import kotlin.reflect.typeOf
2828
*/
2929
@OptIn(ExperimentalStdlibApi::class)
3030
inline fun <reified T> ChildWorkflowStub.execute(vararg args: Any?): T {
31-
return execute(T::class.java, typeOf<T>().javaType, args)
31+
return execute(T::class.java, typeOf<T>().javaType, *args)
3232
}
3333

3434
/**
3535
* @see ChildWorkflowStub.executeAsync
3636
*/
3737
@OptIn(ExperimentalStdlibApi::class)
3838
inline fun <reified T> ChildWorkflowStub.executeAsync(vararg args: Any?): Promise<T> {
39-
return executeAsync(T::class.java, typeOf<T>().javaType, args)
39+
return executeAsync(T::class.java, typeOf<T>().javaType, *args)
4040
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3+
*
4+
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this material except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package io.temporal.workflow
22+
23+
import io.temporal.activity.ActivityInterface
24+
import io.temporal.activity.ActivityOptions
25+
import io.temporal.activity.setRetryOptions
26+
import io.temporal.client.WorkflowClientOptions
27+
import io.temporal.client.WorkflowOptions
28+
import io.temporal.common.converter.DefaultDataConverter
29+
import io.temporal.common.converter.JacksonJsonPayloadConverter
30+
import io.temporal.common.converter.KotlinObjectMapperFactory
31+
import io.temporal.testing.internal.SDKTestWorkflowRule
32+
import org.junit.Rule
33+
import org.junit.Test
34+
import java.time.Duration
35+
36+
class KotlinActivityStubExtTest {
37+
38+
@Rule
39+
@JvmField
40+
var testWorkflowRule: SDKTestWorkflowRule = SDKTestWorkflowRule.newBuilder()
41+
.setWorkflowTypes(
42+
SyncWorkflowImpl::class.java,
43+
AsyncWorkflowImpl::class.java
44+
)
45+
.setActivityImplementations(ActivityImpl())
46+
.setWorkflowClientOptions(
47+
WorkflowClientOptions.newBuilder()
48+
.setDataConverter(DefaultDataConverter(JacksonJsonPayloadConverter(KotlinObjectMapperFactory.new())))
49+
.build()
50+
)
51+
.build()
52+
53+
@WorkflowInterface
54+
interface SyncWorkflow {
55+
@WorkflowMethod
56+
fun execute()
57+
}
58+
59+
class SyncWorkflowImpl : SyncWorkflow {
60+
61+
override fun execute() {
62+
val activity = Workflow.newUntypedActivityStub(
63+
ActivityOptions {
64+
setStartToCloseTimeout(Duration.ofSeconds(5))
65+
setRetryOptions { setMaximumAttempts(1) }
66+
}
67+
)
68+
69+
activity.execute<Unit>("Run", "test-argument")
70+
}
71+
}
72+
73+
@WorkflowInterface
74+
interface AsyncWorkflow {
75+
@WorkflowMethod
76+
fun execute()
77+
}
78+
79+
class AsyncWorkflowImpl : AsyncWorkflow {
80+
override fun execute() {
81+
val activity = Workflow.newUntypedActivityStub(
82+
ActivityOptions {
83+
setStartToCloseTimeout(Duration.ofSeconds(5))
84+
setRetryOptions { setMaximumAttempts(1) }
85+
}
86+
)
87+
88+
val promise = activity.executeAsync<Unit>("Run", "test-argument")
89+
promise.get()
90+
}
91+
}
92+
93+
@ActivityInterface
94+
interface TestActivity {
95+
fun run(arg: String)
96+
}
97+
98+
class ActivityImpl : TestActivity {
99+
override fun run(arg: String) {
100+
}
101+
}
102+
103+
@Test
104+
fun `execute on untyped activity stub should spread varargs`() {
105+
val client = testWorkflowRule.workflowClient
106+
val options = WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.taskQueue).build()
107+
val workflowStub = client.newWorkflowStub(SyncWorkflow::class.java, options)
108+
workflowStub.execute()
109+
}
110+
111+
@Test
112+
fun `executeAsync on untyped activity stub should spread varargs`() {
113+
val client = testWorkflowRule.workflowClient
114+
val options = WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.taskQueue).build()
115+
val workflowStub = client.newWorkflowStub(AsyncWorkflow::class.java, options)
116+
workflowStub.execute()
117+
}
118+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3+
*
4+
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this material except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package io.temporal.workflow
22+
23+
import io.temporal.client.WorkflowClientOptions
24+
import io.temporal.client.WorkflowOptions
25+
import io.temporal.common.converter.DefaultDataConverter
26+
import io.temporal.common.converter.JacksonJsonPayloadConverter
27+
import io.temporal.common.converter.KotlinObjectMapperFactory
28+
import io.temporal.testing.internal.SDKTestWorkflowRule
29+
import org.junit.Rule
30+
import org.junit.Test
31+
32+
class KotlinChildWorkflowStubExtTest {
33+
34+
@Rule
35+
@JvmField
36+
var testWorkflowRule: SDKTestWorkflowRule = SDKTestWorkflowRule.newBuilder()
37+
.setWorkflowTypes(
38+
ParentWorkflowImpl::class.java,
39+
AsyncParentWorkflowImpl::class.java,
40+
ChildWorkflowImpl::class.java
41+
)
42+
.setWorkflowClientOptions(
43+
WorkflowClientOptions.newBuilder()
44+
.setDataConverter(DefaultDataConverter(JacksonJsonPayloadConverter(KotlinObjectMapperFactory.new())))
45+
.build()
46+
)
47+
.build()
48+
49+
@WorkflowInterface
50+
interface ChildWorkflow {
51+
@WorkflowMethod
52+
fun execute(argument: String): Int
53+
}
54+
55+
class ChildWorkflowImpl : ChildWorkflow {
56+
override fun execute(argument: String): Int {
57+
return 0
58+
}
59+
}
60+
61+
@WorkflowInterface
62+
interface ParentWorkflow {
63+
@WorkflowMethod
64+
fun execute()
65+
}
66+
67+
class ParentWorkflowImpl : ParentWorkflow {
68+
override fun execute() {
69+
val childWorkflow = Workflow.newUntypedChildWorkflowStub("ChildWorkflow")
70+
childWorkflow.execute<Any>("test-argument")
71+
}
72+
}
73+
74+
@WorkflowInterface
75+
interface AsyncParentWorkflow {
76+
@WorkflowMethod
77+
fun execute()
78+
}
79+
80+
class AsyncParentWorkflowImpl : AsyncParentWorkflow {
81+
override fun execute() {
82+
val childWorkflow = Workflow.newUntypedChildWorkflowStub("ChildWorkflow")
83+
val promise = childWorkflow.executeAsync<Any>("test-argument")
84+
promise.get()
85+
}
86+
}
87+
88+
@Test
89+
fun `execute on untyped child workflow should spread varargs`() {
90+
val client = testWorkflowRule.workflowClient
91+
val options = WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.taskQueue).build()
92+
val workflowStub = client.newWorkflowStub(ParentWorkflow::class.java, options)
93+
workflowStub.execute()
94+
}
95+
96+
@Test
97+
fun `executeAsync on untyped child workflow should spread varargs`() {
98+
val client = testWorkflowRule.workflowClient
99+
val options = WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.taskQueue).build()
100+
val workflowStub = client.newWorkflowStub(AsyncParentWorkflow::class.java, options)
101+
workflowStub.execute()
102+
}
103+
}

0 commit comments

Comments
 (0)