@@ -123,6 +123,39 @@ class FailingForwardGreetingService implements TestGreeter {
123123 }
124124}
125125
126+ const delayedCallTime = 1835661783000 ;
127+ class DelayedInBackgroundInvokeGreeter implements TestGreeter {
128+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
129+ async greet ( request : TestRequest ) : Promise < TestResponse > {
130+ const ctx = restate . useContext ( this ) ;
131+
132+ const client = new TestGreeterClientImpl ( ctx ) ;
133+ await ctx . inBackground (
134+ ( ) => client . greet ( TestRequest . create ( { name : "Francesco" } ) ) ,
135+ delayedCallTime - Date . now ( )
136+ ) ;
137+
138+ return TestResponse . create ( { greeting : `Hello` } ) ;
139+ }
140+ }
141+ class DelayedAndNormalInBackgroundInvokesGreeter implements TestGreeter {
142+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
143+ async greet ( request : TestRequest ) : Promise < TestResponse > {
144+ const ctx = restate . useContext ( this ) ;
145+
146+ const client = new TestGreeterClientImpl ( ctx ) ;
147+ await ctx . inBackground (
148+ ( ) => client . greet ( TestRequest . create ( { name : "Francesco" } ) ) ,
149+ delayedCallTime - Date . now ( )
150+ ) ;
151+ await ctx . inBackground ( ( ) =>
152+ client . greet ( TestRequest . create ( { name : "Francesco" } ) )
153+ ) ;
154+
155+ return TestResponse . create ( { greeting : `Hello` } ) ;
156+ }
157+ }
158+
126159describe ( "ReverseAwaitOrder: None completed" , ( ) => {
127160 it ( "should call greet" , async ( ) => {
128161 const result = await new TestDriver (
@@ -669,4 +702,98 @@ describe("FailingSideEffectInBackgroundInvokeGreeter: failing background call ",
669702 } ) ;
670703} ) ;
671704
705+ describe ( "DelayedInBackgroundInvokeGreeter: delayed in back ground call without completion" , ( ) => {
706+ it ( "should call greet" , async ( ) => {
707+ const result = await new TestDriver (
708+ protoMetadata ,
709+ "TestGreeter" ,
710+ new DelayedInBackgroundInvokeGreeter ( ) ,
711+ "/test.TestGreeter/Greet" ,
712+ [ startMessage ( 1 ) , inputMessage ( greetRequest ( "Till" ) ) ]
713+ ) . run ( ) ;
714+
715+ expect ( result ) . toStrictEqual ( [
716+ backgroundInvokeMessage (
717+ "test.TestGreeter" ,
718+ "Greet" ,
719+ greetRequest ( "Francesco" ) ,
720+ delayedCallTime
721+ ) ,
722+ outputMessage ( greetResponse ( "Hello" ) ) ,
723+ ] ) ;
724+ } ) ;
725+ } ) ;
726+
727+ describe ( "DelayedInBackgroundInvokeGreeter: delayed in background call with replay" , ( ) => {
728+ it ( "should call greet" , async ( ) => {
729+ const result = await new TestDriver (
730+ protoMetadata ,
731+ "TestGreeter" ,
732+ new DelayedInBackgroundInvokeGreeter ( ) ,
733+ "/test.TestGreeter/Greet" ,
734+ [
735+ startMessage ( 2 ) ,
736+ inputMessage ( greetRequest ( "Till" ) ) ,
737+ backgroundInvokeMessage (
738+ "test.TestGreeter" ,
739+ "Greet" ,
740+ greetRequest ( "Francesco" ) ,
741+ delayedCallTime
742+ ) ,
743+ ]
744+ ) . run ( ) ;
745+
746+ expect ( result ) . toStrictEqual ( [ outputMessage ( greetResponse ( "Hello" ) ) ] ) ;
747+ } ) ;
748+ } ) ;
749+
750+ describe ( "DelayedInBackgroundInvokeGreeter: delayed in background call with journal mismatch" , ( ) => {
751+ it ( "should call greet" , async ( ) => {
752+ const result = await new TestDriver (
753+ protoMetadata ,
754+ "TestGreeter" ,
755+ new DelayedInBackgroundInvokeGreeter ( ) ,
756+ "/test.TestGreeter/Greet" ,
757+ [
758+ startMessage ( 2 ) ,
759+ inputMessage ( greetRequest ( "Till" ) ) ,
760+ invokeMessage ( "test.TestGreeter" , "Greet" , greetRequest ( "Francesco" ) ) ,
761+ ]
762+ ) . run ( ) ;
763+
764+ expect ( result . length ) . toStrictEqual ( 1 ) ;
765+ checkError (
766+ result [ 0 ] ,
767+ "Replayed journal entries did not correspond to the user code. The user code has to be deterministic!"
768+ ) ;
769+ } ) ;
770+ } ) ;
771+
772+ describe ( "DelayedAndNormalInBackgroundInvokesGreeter: two async calls. One with delay, one normal." , ( ) => {
773+ it ( "should call greet" , async ( ) => {
774+ const result = await new TestDriver (
775+ protoMetadata ,
776+ "TestGreeter" ,
777+ new DelayedAndNormalInBackgroundInvokesGreeter ( ) ,
778+ "/test.TestGreeter/Greet" ,
779+ [ startMessage ( 1 ) , inputMessage ( greetRequest ( "Till" ) ) ]
780+ ) . run ( ) ;
781+
782+ expect ( result ) . toStrictEqual ( [
783+ backgroundInvokeMessage (
784+ "test.TestGreeter" ,
785+ "Greet" ,
786+ greetRequest ( "Francesco" ) ,
787+ delayedCallTime
788+ ) ,
789+ backgroundInvokeMessage (
790+ "test.TestGreeter" ,
791+ "Greet" ,
792+ greetRequest ( "Francesco" )
793+ ) ,
794+ outputMessage ( greetResponse ( "Hello" ) ) ,
795+ ] ) ;
796+ } ) ;
797+ } ) ;
798+
672799// TODO also implement the other tests of the Java SDK.
0 commit comments