From 7b623bfaf3c31d28934d3b49d84e6d630e6faba4 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Tue, 1 Aug 2023 07:46:54 -0700 Subject: [PATCH] Properly wrap exceptions from schedule client (#1827) Wrap schedule exception --- .../client/RootScheduleClientInvoker.java | 63 ++++++++++++++----- .../client/schedules/ScheduleTest.java | 31 ++++++++- 2 files changed, 75 insertions(+), 19 deletions(-) diff --git a/temporal-sdk/src/main/java/io/temporal/internal/client/RootScheduleClientInvoker.java b/temporal-sdk/src/main/java/io/temporal/internal/client/RootScheduleClientInvoker.java index 25a02bbea..a46037890 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/client/RootScheduleClientInvoker.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/client/RootScheduleClientInvoker.java @@ -107,6 +107,8 @@ public void createSchedule(CreateScheduleInput input) { } else { throw new ScheduleException(e); } + } catch (Exception e) { + throw new ScheduleException(e); } } @@ -153,7 +155,11 @@ public void backfillSchedule(BackfillScheduleInput input) { .setScheduleId(input.getScheduleId()) .setPatch(patch) .build(); - genericClient.patchSchedule(request); + try { + genericClient.patchSchedule(request); + } catch (Exception e) { + throw new ScheduleException(e); + } } @Override @@ -164,7 +170,11 @@ public void deleteSchedule(DeleteScheduleInput input) { .setNamespace(clientOptions.getNamespace()) .setScheduleId(input.getScheduleId()) .build(); - genericClient.deleteSchedule(request); + try { + genericClient.deleteSchedule(request); + } catch (Exception e) { + throw new ScheduleException(e); + } } @Override @@ -175,16 +185,20 @@ public DescribeScheduleOutput describeSchedule(DescribeScheduleInput input) { .setScheduleId(input.getScheduleId()) .build(); - DescribeScheduleResponse response = genericClient.describeSchedule(request); - return new DescribeScheduleOutput( - new ScheduleDescription( - input.getScheduleId(), - scheduleRequestHeader.protoToScheduleInfo(response.getInfo()), - scheduleRequestHeader.protoToSchedule(response.getSchedule()), - Collections.unmodifiableMap( - SearchAttributesUtil.decode(response.getSearchAttributes())), - response.getMemo().getFieldsMap(), - clientOptions.getDataConverter())); + try { + DescribeScheduleResponse response = genericClient.describeSchedule(request); + return new DescribeScheduleOutput( + new ScheduleDescription( + input.getScheduleId(), + scheduleRequestHeader.protoToScheduleInfo(response.getInfo()), + scheduleRequestHeader.protoToSchedule(response.getSchedule()), + Collections.unmodifiableMap( + SearchAttributesUtil.decode(response.getSearchAttributes())), + response.getMemo().getFieldsMap(), + clientOptions.getDataConverter())); + } catch (Exception e) { + throw new ScheduleException(e); + } } @Override @@ -198,8 +212,11 @@ public void pauseSchedule(PauseScheduleInput input) { .setScheduleId(input.getScheduleId()) .setPatch(patch) .build(); - - genericClient.patchSchedule(request); + try { + genericClient.patchSchedule(request); + } catch (Exception e) { + throw new ScheduleException(e); + } } @Override @@ -216,7 +233,11 @@ public void triggerSchedule(TriggerScheduleInput input) { .setScheduleId(input.getScheduleId()) .setPatch(patch) .build(); - genericClient.patchSchedule(request); + try { + genericClient.patchSchedule(request); + } catch (Exception e) { + throw new ScheduleException(e); + } } @Override @@ -230,7 +251,11 @@ public void unpauseSchedule(UnpauseScheduleInput input) { .setScheduleId(input.getScheduleId()) .setPatch(patch) .build(); - genericClient.patchSchedule(request); + try { + genericClient.patchSchedule(request); + } catch (Exception e) { + throw new ScheduleException(e); + } } @Override @@ -249,6 +274,10 @@ public void updateSchedule(UpdateScheduleInput input) { .setRequestId(UUID.randomUUID().toString()) .setSchedule(scheduleRequestHeader.scheduleToProto(schedule.getSchedule())) .build(); - genericClient.updateSchedule(request); + try { + genericClient.updateSchedule(request); + } catch (Exception e) { + throw new ScheduleException(e); + } } } diff --git a/temporal-sdk/src/test/java/io/temporal/client/schedules/ScheduleTest.java b/temporal-sdk/src/test/java/io/temporal/client/schedules/ScheduleTest.java index 9574624b8..a7b9c30d1 100644 --- a/temporal-sdk/src/test/java/io/temporal/client/schedules/ScheduleTest.java +++ b/temporal-sdk/src/test/java/io/temporal/client/schedules/ScheduleTest.java @@ -111,7 +111,7 @@ public void createSchedule() { try { handle.describe(); Assert.fail(); - } catch (Exception e) { + } catch (ScheduleException e) { } // Create a handle to a non-existent schedule, creating the handle should not throw // but any operations on it should. @@ -119,7 +119,7 @@ public void createSchedule() { ScheduleHandle badHandle = client.getHandle(UUID.randomUUID().toString()); badHandle.delete(); Assert.fail(); - } catch (Exception e) { + } catch (ScheduleException e) { } } @@ -167,6 +167,12 @@ public void pauseUnpauseSchedule() { Assert.assertEquals(false, description.getSchedule().getState().isPaused()); // Cleanup schedule handle.delete(); + // Try to unpause a deleted schedule + try { + handle.unpause(""); + Assert.fail(); + } catch (ScheduleException e) { + } } @Test @@ -221,6 +227,12 @@ public void triggerSchedule() { Assert.assertEquals(3, handle.describe().getInfo().getNumActions()); // Cleanup schedule handle.delete(); + // Try to trigger a deleted schedule + try { + handle.trigger(); + Assert.fail(); + } catch (ScheduleException e) { + } } @Test @@ -253,6 +265,15 @@ public void backfillSchedules() { waitForActions(handle, 15); // Cleanup schedule handle.delete(); + // Try to backfill a deleted schedule + try { + handle.backfill( + Arrays.asList( + new ScheduleBackfill(now.minusMillis(5500), now.minusMillis(2500)), + new ScheduleBackfill(now.minusMillis(2500), now))); + Assert.fail(); + } catch (ScheduleException e) { + } } @Test @@ -356,6 +377,12 @@ public void describeSchedules() { Assert.assertEquals(schedule.getState(), description.getSchedule().getState()); // Cleanup schedule handle.delete(); + // Try to describe a deleted schedule + try { + handle.describe(); + Assert.fail(); + } catch (ScheduleException e) { + } } @Test