Skip to content

Commit

Permalink
Fix replay of get state with empty result (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper authored Apr 24, 2023
1 parent 14709bf commit 389f77f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void trace(GetStateEntryMessage expected, Span span) {

@Override
public boolean hasResult(GetStateEntryMessage actual) {
return actual.getResultCase() == GetStateEntryMessage.ResultCase.VALUE;
return actual.getResultCase() != GetStateEntryMessage.ResultCase.RESULT_NOT_SET;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static dev.restate.sdk.core.impl.CoreTestRunner.TestCaseBuilder.testInvocation;
import static dev.restate.sdk.core.impl.ProtoUtils.*;

import com.google.protobuf.Empty;
import dev.restate.sdk.blocking.RestateBlockingService;
import dev.restate.sdk.core.StateKey;
import dev.restate.sdk.core.TypeTag;
Expand All @@ -18,7 +19,8 @@ private static class GetStateGreeter extends GreeterGrpc.GreeterImplBase
implements RestateBlockingService {
@Override
public void greet(GreetingRequest request, StreamObserver<GreetingResponse> responseObserver) {
String state = restateContext().get(StateKey.of("STATE", TypeTag.STRING_UTF8)).get();
String state =
restateContext().get(StateKey.of("STATE", TypeTag.STRING_UTF8)).orElse("Unknown");

responseObserver.onNext(GreetingResponse.newBuilder().setMessage("Hello " + state).build());
responseObserver.onCompleted();
Expand All @@ -37,6 +39,15 @@ Stream<TestDefinition> definitions() {
.expectingOutput(
outputMessage(GreetingResponse.newBuilder().setMessage("Hello Francesco")))
.named("With GetStateEntry already completed"),
testInvocation(new GetStateGreeter(), GreeterGrpc.getGreetMethod())
.withInput(
startMessage(2),
inputMessage(GreetingRequest.newBuilder().setName("Till")),
getStateMessage("STATE").setEmpty(Empty.getDefaultInstance()))
.usingAllThreadingModels()
.expectingOutput(
outputMessage(GreetingResponse.newBuilder().setMessage("Hello Unknown")))
.named("With GetStateEntry already completed empty"),
testInvocation(new GetStateGreeter(), GreeterGrpc.getGreetMethod())
.withInput(startMessage(1), inputMessage(GreetingRequest.newBuilder().setName("Till")))
.usingAllThreadingModels()
Expand Down

0 comments on commit 389f77f

Please sign in to comment.