Skip to content

Commit

Permalink
Properly wrap exceptions from schedule client (#1827)
Browse files Browse the repository at this point in the history
Wrap schedule exception
  • Loading branch information
Quinn-With-Two-Ns authored Aug 1, 2023
1 parent bf6ae4b commit 7b623bf
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public void createSchedule(CreateScheduleInput input) {
} else {
throw new ScheduleException(e);
}
} catch (Exception e) {
throw new ScheduleException(e);
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ 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.
try {
ScheduleHandle badHandle = client.getHandle(UUID.randomUUID().toString());
badHandle.delete();
Assert.fail();
} catch (Exception e) {
} catch (ScheduleException e) {
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7b623bf

Please sign in to comment.