3838import java .io .IOException ;
3939import java .time .Duration ;
4040import java .time .Instant ;
41- import java .util .NoSuchElementException ;
4241import java .util .concurrent .CancellationException ;
4342import java .util .concurrent .TimeoutException ;
4443
@@ -123,7 +122,7 @@ public void startInstance(CreateInstanceRequest request, StreamObserver<CreateIn
123122 }
124123
125124 @ Test
126- void raiseEvent_notFound_throwsNoSuchElementException () throws IOException {
125+ void raiseEvent_notFound_throwsIllegalArgumentException () throws IOException {
127126 DurableTaskClient client = createClientWithFakeService (new TaskHubSidecarServiceGrpc .TaskHubSidecarServiceImplBase () {
128127 @ Override
129128 public void raiseEvent (RaiseEventRequest request , StreamObserver <RaiseEventResponse > responseObserver ) {
@@ -132,15 +131,15 @@ public void raiseEvent(RaiseEventRequest request, StreamObserver<RaiseEventRespo
132131 }
133132 });
134133
135- NoSuchElementException ex = assertThrows (NoSuchElementException .class , () ->
134+ IllegalArgumentException ex = assertThrows (IllegalArgumentException .class , () ->
136135 client .raiseEvent ("test-instance" , "testEvent" ));
137136
138137 assertGrpcCause (ex , Status .Code .NOT_FOUND );
139138 assertTrue (ex .getMessage ().contains ("raiseEvent" ));
140139 }
141140
142141 @ Test
143- void getInstanceMetadata_notFound_throwsNoSuchElementException () throws IOException {
142+ void getInstanceMetadata_notFound_throwsIllegalArgumentException () throws IOException {
144143 DurableTaskClient client = createClientWithFakeService (new TaskHubSidecarServiceGrpc .TaskHubSidecarServiceImplBase () {
145144 @ Override
146145 public void getInstance (GetInstanceRequest request , StreamObserver <GetInstanceResponse > responseObserver ) {
@@ -149,7 +148,7 @@ public void getInstance(GetInstanceRequest request, StreamObserver<GetInstanceRe
149148 }
150149 });
151150
152- NoSuchElementException ex = assertThrows (NoSuchElementException .class , () ->
151+ IllegalArgumentException ex = assertThrows (IllegalArgumentException .class , () ->
153152 client .getInstanceMetadata ("test-instance" , false ));
154153
155154 assertGrpcCause (ex , Status .Code .NOT_FOUND );
@@ -224,7 +223,7 @@ public void deleteTaskHub(DeleteTaskHubRequest request, StreamObserver<DeleteTas
224223 }
225224
226225 @ Test
227- void purgeInstance_notFound_throwsNoSuchElementException () throws IOException {
226+ void purgeInstance_notFound_throwsIllegalArgumentException () throws IOException {
228227 DurableTaskClient client = createClientWithFakeService (new TaskHubSidecarServiceGrpc .TaskHubSidecarServiceImplBase () {
229228 @ Override
230229 public void purgeInstances (PurgeInstancesRequest request , StreamObserver <PurgeInstancesResponse > responseObserver ) {
@@ -233,7 +232,7 @@ public void purgeInstances(PurgeInstancesRequest request, StreamObserver<PurgeIn
233232 }
234233 });
235234
236- NoSuchElementException ex = assertThrows (NoSuchElementException .class , () ->
235+ IllegalArgumentException ex = assertThrows (IllegalArgumentException .class , () ->
237236 client .purgeInstance ("test-instance" ));
238237
239238 assertGrpcCause (ex , Status .Code .NOT_FOUND );
@@ -364,7 +363,7 @@ public void waitForInstanceCompletion(GetInstanceRequest request, StreamObserver
364363 }
365364
366365 @ Test
367- void purgeInstances_notFound_throwsNoSuchElementException () throws IOException {
366+ void purgeInstances_notFound_throwsIllegalArgumentException () throws IOException {
368367 DurableTaskClient client = createClientWithFakeService (new TaskHubSidecarServiceGrpc .TaskHubSidecarServiceImplBase () {
369368 @ Override
370369 public void purgeInstances (PurgeInstancesRequest request , StreamObserver <PurgeInstancesResponse > responseObserver ) {
@@ -376,7 +375,7 @@ public void purgeInstances(PurgeInstancesRequest request, StreamObserver<PurgeIn
376375 PurgeInstanceCriteria criteria = new PurgeInstanceCriteria ()
377376 .setCreatedTimeFrom (Instant .parse ("2026-01-01T00:00:00Z" ));
378377
379- NoSuchElementException ex = assertThrows (NoSuchElementException .class , () ->
378+ IllegalArgumentException ex = assertThrows (IllegalArgumentException .class , () ->
380379 client .purgeInstances (criteria ));
381380
382381 assertGrpcCause (ex , Status .Code .NOT_FOUND );
@@ -425,7 +424,7 @@ public void rewindInstance(RewindInstanceRequest request, StreamObserver<RewindI
425424 }
426425
427426 @ Test
428- void rewindInstance_notFound_throwsIllegalArgumentExceptionWithCustomMessage () throws IOException {
427+ void rewindInstance_notFound_throwsIllegalArgumentExceptionThroughHelper () throws IOException {
429428 DurableTaskClient client = createClientWithFakeService (new TaskHubSidecarServiceGrpc .TaskHubSidecarServiceImplBase () {
430429 @ Override
431430 public void rewindInstance (RewindInstanceRequest request , StreamObserver <RewindInstanceResponse > responseObserver ) {
@@ -438,8 +437,8 @@ public void rewindInstance(RewindInstanceRequest request, StreamObserver<RewindI
438437 client .rewindInstance ("test-instance" , null ));
439438
440439 assertGrpcCause (ex , Status .Code .NOT_FOUND );
441- // rewindInstance has its own custom message for NOT_FOUND
442- assertTrue (ex .getMessage ().contains ("test-instance " ));
440+ // Now goes through the helper, so message contains the operation name
441+ assertTrue (ex .getMessage ().contains ("rewindInstance " ));
443442 }
444443
445444 // -----------------------------------------------------------------------
@@ -526,7 +525,7 @@ public void raiseEvent(RaiseEventRequest request, StreamObserver<RaiseEventRespo
526525 }
527526
528527 @ Test
529- void terminate_notFound_throwsNoSuchElementException () throws IOException {
528+ void terminate_notFound_throwsIllegalArgumentException () throws IOException {
530529 DurableTaskClient client = createClientWithFakeService (new TaskHubSidecarServiceGrpc .TaskHubSidecarServiceImplBase () {
531530 @ Override
532531 public void terminateInstance (TerminateRequest request , StreamObserver <TerminateResponse > responseObserver ) {
@@ -535,7 +534,7 @@ public void terminateInstance(TerminateRequest request, StreamObserver<Terminate
535534 }
536535 });
537536
538- NoSuchElementException ex = assertThrows (NoSuchElementException .class , () ->
537+ IllegalArgumentException ex = assertThrows (IllegalArgumentException .class , () ->
539538 client .terminate ("test-instance" , null ));
540539
541540 assertGrpcCause (ex , Status .Code .NOT_FOUND );
0 commit comments