Skip to content

Commit

Permalink
Fix side effect guard (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper authored Apr 24, 2023
1 parent 389f77f commit ca4617d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ void enterSideEffectJournalEntry(
Runnable noEntryCallback,
Consumer<Throwable> failureCallback) {
checkInsideSideEffectGuard();
this.insideSideEffect = true;
if (this.state == State.CLOSED) {
failureCallback.accept(SuspendedException.INSTANCE);
} else if (this.state == State.REPLAYING) {
Expand All @@ -322,6 +321,7 @@ void enterSideEffectJournalEntry(
new SideEffectAckPublisher.OnEnterSideEffectCallback() {
@Override
public void onEnter() {
insideSideEffect = true;
if (span.isRecording()) {
traceFn.accept(span);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ public void greet(GreetingRequest request, StreamObserver<GreetingResponse> resp
}
}

private static class SideEffectThenAwakeable extends GreeterGrpc.GreeterImplBase
implements RestateBlockingService {

@Override
public void greet(GreetingRequest request, StreamObserver<GreetingResponse> responseObserver) {
RestateContext ctx = restateContext();

ctx.sideEffect(
() -> {
throw new IllegalStateException("This should be replayed");
});
ctx.awakeable(TypeTag.BYTES).await();

responseObserver.onNext(GreetingResponse.newBuilder().setMessage("Hello").build());
responseObserver.onCompleted();
}
}

@Override
Stream<TestDefinition> definitions() {
return Stream.of(
Expand Down Expand Up @@ -153,6 +171,13 @@ Stream<TestDefinition> definitions() {
testInvocation(new SideEffectGuard(), GreeterGrpc.getGreetMethod())
.withInput(startMessage(1), inputMessage(GreetingRequest.newBuilder().setName("Till")))
.usingAllThreadingModels()
.assertingFailure(ProtocolException.class));
.assertingFailure(ProtocolException.class),
testInvocation(new SideEffectThenAwakeable(), GreeterGrpc.getGreetMethod())
.withInput(
startMessage(2),
inputMessage(GreetingRequest.newBuilder().setName("Till")),
Java.SideEffectEntryMessage.newBuilder().setValue(ByteString.copyFromUtf8("")))
.usingAllThreadingModels()
.expectingOutput(awakeable(), suspensionMessage(2)));
}
}

0 comments on commit ca4617d

Please sign in to comment.