|
57 | 57 | import com.uber.cadence.worker.WorkflowImplementationOptions;
|
58 | 58 | import com.uber.cadence.workflow.Functions.Func;
|
59 | 59 | import com.uber.cadence.workflow.Functions.Func1;
|
| 60 | +import java.io.File; |
| 61 | +import java.io.FileInputStream; |
60 | 62 | import java.io.FileNotFoundException;
|
61 | 63 | import java.io.IOException;
|
| 64 | +import java.io.InputStream; |
62 | 65 | import java.lang.management.ManagementFactory;
|
63 | 66 | import java.lang.reflect.Type;
|
64 | 67 | import java.time.Duration;
|
@@ -3851,6 +3854,103 @@ public void testGenericParametersWorkflow() throws ExecutionException, Interrupt
|
3851 | 3854 | assertEquals(expectedResult, result);
|
3852 | 3855 | }
|
3853 | 3856 |
|
| 3857 | + public static class NonSerializableException extends RuntimeException { |
| 3858 | + private final InputStream file; // gson chokes on this field |
| 3859 | + |
| 3860 | + public NonSerializableException() { |
| 3861 | + try { |
| 3862 | + file = new FileInputStream(File.createTempFile("foo", "bar")); |
| 3863 | + } catch (IOException e) { |
| 3864 | + throw Activity.wrap(e); |
| 3865 | + } |
| 3866 | + } |
| 3867 | + } |
| 3868 | + |
| 3869 | + public interface NonSerializableExceptionActivity { |
| 3870 | + |
| 3871 | + @ActivityMethod(scheduleToCloseTimeoutSeconds = 5) |
| 3872 | + void execute(); |
| 3873 | + } |
| 3874 | + |
| 3875 | + public static class NonSerializableExceptionActivityImpl |
| 3876 | + implements NonSerializableExceptionActivity { |
| 3877 | + |
| 3878 | + @Override |
| 3879 | + public void execute() { |
| 3880 | + throw new NonSerializableException(); |
| 3881 | + } |
| 3882 | + } |
| 3883 | + |
| 3884 | + public static class TestNonSerializableExceptionInActivityWorkflow implements TestWorkflow1 { |
| 3885 | + |
| 3886 | + @Override |
| 3887 | + public String execute(String taskList) { |
| 3888 | + NonSerializableExceptionActivity activity = |
| 3889 | + Workflow.newActivityStub(NonSerializableExceptionActivity.class); |
| 3890 | + try { |
| 3891 | + activity.execute(); |
| 3892 | + } catch (ActivityFailureException e) { |
| 3893 | + return e.getMessage(); |
| 3894 | + } |
| 3895 | + return "done"; |
| 3896 | + } |
| 3897 | + } |
| 3898 | + |
| 3899 | + @Test |
| 3900 | + public void testNonSerializableExceptionInActivity() { |
| 3901 | + worker.registerActivitiesImplementations(new NonSerializableExceptionActivityImpl()); |
| 3902 | + startWorkerFor(TestNonSerializableExceptionInActivityWorkflow.class); |
| 3903 | + TestWorkflow1 workflowStub = |
| 3904 | + workflowClient.newWorkflowStub( |
| 3905 | + TestWorkflow1.class, newWorkflowOptionsBuilder(taskList).build()); |
| 3906 | + |
| 3907 | + String result = workflowStub.execute(taskList); |
| 3908 | + assertTrue(result.contains("NonSerializableException")); |
| 3909 | + } |
| 3910 | + |
| 3911 | + public interface NonSerializableExceptionChildWorkflow { |
| 3912 | + |
| 3913 | + @WorkflowMethod |
| 3914 | + String execute(String taskList); |
| 3915 | + } |
| 3916 | + |
| 3917 | + public static class NonSerializableExceptionChildWorkflowImpl |
| 3918 | + implements NonSerializableExceptionChildWorkflow { |
| 3919 | + |
| 3920 | + @Override |
| 3921 | + public String execute(String taskList) { |
| 3922 | + throw new NonSerializableException(); |
| 3923 | + } |
| 3924 | + } |
| 3925 | + |
| 3926 | + public static class TestNonSerializableExceptionInChildWorkflow implements TestWorkflow1 { |
| 3927 | + |
| 3928 | + @Override |
| 3929 | + public String execute(String taskList) { |
| 3930 | + NonSerializableExceptionChildWorkflow child = |
| 3931 | + Workflow.newChildWorkflowStub(NonSerializableExceptionChildWorkflow.class); |
| 3932 | + try { |
| 3933 | + child.execute(taskList); |
| 3934 | + } catch (ChildWorkflowFailureException e) { |
| 3935 | + return e.getMessage(); |
| 3936 | + } |
| 3937 | + return "done"; |
| 3938 | + } |
| 3939 | + } |
| 3940 | + |
| 3941 | + @Test |
| 3942 | + public void testNonSerializableExceptionInChildWorkflow() { |
| 3943 | + startWorkerFor( |
| 3944 | + TestNonSerializableExceptionInChildWorkflow.class, |
| 3945 | + NonSerializableExceptionChildWorkflowImpl.class); |
| 3946 | + TestWorkflow1 workflowStub = |
| 3947 | + workflowClient.newWorkflowStub( |
| 3948 | + TestWorkflow1.class, newWorkflowOptionsBuilder(taskList).build()); |
| 3949 | + |
| 3950 | + String result = workflowStub.execute(taskList); |
| 3951 | + assertTrue(result.contains("NonSerializableException")); |
| 3952 | + } |
| 3953 | + |
3854 | 3954 | public interface TestLargeWorkflow {
|
3855 | 3955 |
|
3856 | 3956 | @WorkflowMethod
|
|
0 commit comments