Skip to content

Commit

Permalink
Test 404 propagation for internal function calls (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper authored Aug 8, 2022
1 parent 598db23 commit dc15f76
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions functions/errors/contract/src/main/proto/errors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ service FailingService {
rpc Fail (ErrorMessage) returns (google.protobuf.Empty);
rpc FailAndHandle (ErrorMessage) returns (ErrorMessage);
rpc InvokeExternalAndHandleFailure(FailRequest) returns (ErrorMessage);
rpc HandleNotFound (FailRequest) returns (ErrorMessage);
}

message FailRequest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.restate.e2e.functions.errors;

import com.google.protobuf.Empty;
import com.google.rpc.Code;
import dev.restate.e2e.functions.utils.NumberSortHttpServerUtils;
import dev.restate.sdk.RestateContext;
import io.grpc.MethodDescriptor;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.stub.StreamObserver;
Expand Down Expand Up @@ -85,4 +87,24 @@ public void invokeExternalAndHandleFailure(
responseObserver.onNext(ErrorMessage.newBuilder().setErrorMessage(finalMessage).build());
responseObserver.onCompleted();
}

@Override
public void handleNotFound(FailRequest request, StreamObserver<ErrorMessage> responseObserver) {
var methodDescriptor =
FailingServiceGrpc.getFailMethod().toBuilder()
.setFullMethodName(
MethodDescriptor.generateFullMethodName(
FailingServiceGrpc.SERVICE_NAME, "UnknownFn"))
.build();
try {
RestateContext.current().call(methodDescriptor, ErrorMessage.getDefaultInstance()).await();
} catch (StatusRuntimeException e) {
if (e.getStatus().getCode().value() == Code.NOT_FOUND_VALUE) {
responseObserver.onNext(ErrorMessage.newBuilder().setErrorMessage("notfound").build());
responseObserver.onCompleted();
}
}

throw new IllegalStateException("This should be unreachable");
}
}
9 changes: 9 additions & 0 deletions tests/src/test/kotlin/dev/restate/e2e/ErrorsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,13 @@ class ErrorsTest {
.extracting(ErrorMessage::getErrorMessage)
.isEqualTo("begin:external_call:internal_call")
}

@Test
fun propagate404(@InjectBlockingStub stub: FailingServiceBlockingStub) {
assertThat(
stub.handleNotFound(
FailRequest.newBuilder().setKey(UUID.randomUUID().toString()).build()))
.extracting(ErrorMessage::getErrorMessage)
.isEqualTo("notfound")
}
}

0 comments on commit dc15f76

Please sign in to comment.