File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed
main/java/com/uber/cadence
test/java/com/uber/cadence/workflow Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 2020import com .uber .cadence .QueryRejectCondition ;
2121import com .uber .cadence .WorkflowExecution ;
2222import com .uber .cadence .internal .common .QueryResponse ;
23+ import java .lang .reflect .InvocationHandler ;
24+ import java .lang .reflect .Proxy ;
2325import java .lang .reflect .Type ;
2426import java .util .Optional ;
2527import java .util .concurrent .CompletableFuture ;
@@ -44,12 +46,20 @@ public interface WorkflowStub {
4446 * @return untyped workflow stub for the same workflow instance.
4547 */
4648 static <T > WorkflowStub fromTyped (T typed ) {
47- if (!(typed instanceof Supplier )) {
49+ if (!(typed instanceof Proxy )) {
4850 throw new IllegalArgumentException (
4951 "arguments must be created through WorkflowClient.newWorkflowStub" );
5052 }
53+
54+ InvocationHandler handler = Proxy .getInvocationHandler (typed );
55+
56+ if (!(handler instanceof Supplier )) {
57+ throw new IllegalArgumentException (
58+ "arguments must be created through WorkflowClient.newWorkflowStub" );
59+ }
60+
5161 @ SuppressWarnings ("unchecked" )
52- Supplier <WorkflowStub > supplier = (Supplier <WorkflowStub >) typed ;
62+ Supplier <WorkflowStub > supplier = (Supplier <WorkflowStub >) handler ;
5363 return supplier .get ();
5464 }
5565
Original file line number Diff line number Diff line change 3838import java .lang .reflect .InvocationHandler ;
3939import java .lang .reflect .Method ;
4040import java .util .Optional ;
41+ import java .util .function .Supplier ;
4142
4243/**
4344 * Dynamic implementation of a strongly typed workflow interface that can be used to start, signal
4445 * and query workflows from external processes.
4546 */
46- class WorkflowInvocationHandler implements InvocationHandler {
47+ class WorkflowInvocationHandler implements InvocationHandler , Supplier <WorkflowStub > {
48+
49+ @ Override
50+ public WorkflowStub get () {
51+ return untyped ;
52+ }
4753
4854 public enum InvocationType {
4955 SYNC ,
Original file line number Diff line number Diff line change @@ -1395,6 +1395,16 @@ public void testStart() {
13951395 assertEquals ("1234" , stubP4 .query ());
13961396 assertEquals ("12345" , stubP5 .query ());
13971397 assertEquals ("123456" , stubP6 .query ());
1398+
1399+ // Test execution from untyped stub.
1400+ workflowOptions =
1401+ newWorkflowOptionsBuilder (taskList ).setWorkflowId (UUID .randomUUID ().toString ()).build ();
1402+ TestMultiargsWorkflowsFunc stub2 =
1403+ workflowClient .newWorkflowStub (TestMultiargsWorkflowsFunc .class , workflowOptions );
1404+ WorkflowStub untypedStub = WorkflowStub .fromTyped (stub2 );
1405+ untypedStub .start ();
1406+ String result = untypedStub .getResult (String .class );
1407+ assertEquals ("func" , result );
13981408 }
13991409
14001410 @ Test
You can’t perform that action at this time.
0 commit comments