1
- use crate :: awakeable_holder;
2
- use crate :: list_object:: ListObjectClient ;
3
1
use futures:: future:: BoxFuture ;
4
2
use futures:: FutureExt ;
5
3
use restate_sdk:: prelude:: * ;
6
- use serde:: { Deserialize , Serialize } ;
7
4
use std:: collections:: HashMap ;
5
+ use std:: convert:: Infallible ;
8
6
use std:: sync:: atomic:: { AtomicU8 , Ordering } ;
9
7
use std:: sync:: Arc ;
10
8
use std:: time:: Duration ;
11
9
12
- #[ derive( Serialize , Deserialize ) ]
13
- #[ serde( rename_all = "camelCase" ) ]
14
- pub ( crate ) struct CreateAwakeableAndAwaitItRequest {
15
- awakeable_key : String ,
16
- await_timeout : Option < u64 > ,
17
- }
18
-
19
- #[ derive( Serialize , Deserialize ) ]
20
- #[ serde( tag = "type" ) ]
21
- #[ serde( rename_all_fields = "camelCase" ) ]
22
- pub ( crate ) enum CreateAwakeableAndAwaitItResponse {
23
- #[ serde( rename = "timeout" ) ]
24
- Timeout ,
25
- #[ serde( rename = "result" ) ]
26
- Result { value : String } ,
27
- }
28
-
29
- #[ derive( Serialize , Deserialize ) ]
30
- #[ serde( rename_all = "camelCase" ) ]
31
- pub ( crate ) struct InterpretRequest {
32
- list_name : String ,
33
- commands : Vec < InterpretCommand > ,
34
- }
35
-
36
- #[ derive( Serialize , Deserialize ) ]
37
- #[ serde( tag = "type" ) ]
38
- #[ serde( rename_all_fields = "camelCase" ) ]
39
- pub ( crate ) enum InterpretCommand {
40
- #[ serde( rename = "createAwakeableAndAwaitIt" ) ]
41
- CreateAwakeableAndAwaitIt { awakeable_key : String } ,
42
- #[ serde( rename = "getEnvVariable" ) ]
43
- GetEnvVariable { env_name : String } ,
44
- }
45
-
46
10
#[ restate_sdk:: service]
47
11
#[ name = "TestUtilsService" ]
48
12
pub ( crate ) trait TestUtilsService {
49
13
#[ name = "echo" ]
50
14
async fn echo ( input : String ) -> HandlerResult < String > ;
51
15
#[ name = "uppercaseEcho" ]
52
16
async fn uppercase_echo ( input : String ) -> HandlerResult < String > ;
17
+ #[ name = "rawEcho" ]
18
+ async fn raw_echo ( input : Vec < u8 > ) -> Result < Vec < u8 > , Infallible > ;
53
19
#[ name = "echoHeaders" ]
54
20
async fn echo_headers ( ) -> HandlerResult < Json < HashMap < String , String > > > ;
55
- #[ name = "createAwakeableAndAwaitIt" ]
56
- async fn create_awakeable_and_await_it (
57
- req : Json < CreateAwakeableAndAwaitItRequest > ,
58
- ) -> HandlerResult < Json < CreateAwakeableAndAwaitItResponse > > ;
59
21
#[ name = "sleepConcurrently" ]
60
22
async fn sleep_concurrently ( millis_durations : Json < Vec < u64 > > ) -> HandlerResult < ( ) > ;
61
23
#[ name = "countExecutedSideEffects" ]
62
24
async fn count_executed_side_effects ( increments : u32 ) -> HandlerResult < u32 > ;
63
- #[ name = "getEnvVariable" ]
64
- async fn get_env_variable ( env : String ) -> HandlerResult < String > ;
65
25
#[ name = "cancelInvocation" ]
66
26
async fn cancel_invocation ( invocation_id : String ) -> Result < ( ) , TerminalError > ;
67
- #[ name = "interpretCommands" ]
68
- async fn interpret_commands ( req : Json < InterpretRequest > ) -> HandlerResult < ( ) > ;
69
27
}
70
28
71
29
pub ( crate ) struct TestUtilsServiceImpl ;
@@ -79,6 +37,10 @@ impl TestUtilsService for TestUtilsServiceImpl {
79
37
Ok ( input. to_ascii_uppercase ( ) )
80
38
}
81
39
40
+ async fn raw_echo ( & self , _: Context < ' _ > , input : Vec < u8 > ) -> Result < Vec < u8 > , Infallible > {
41
+ Ok ( input)
42
+ }
43
+
82
44
async fn echo_headers (
83
45
& self ,
84
46
context : Context < ' _ > ,
@@ -94,27 +56,6 @@ impl TestUtilsService for TestUtilsServiceImpl {
94
56
Ok ( headers. into ( ) )
95
57
}
96
58
97
- async fn create_awakeable_and_await_it (
98
- & self ,
99
- context : Context < ' _ > ,
100
- Json ( req) : Json < CreateAwakeableAndAwaitItRequest > ,
101
- ) -> HandlerResult < Json < CreateAwakeableAndAwaitItResponse > > {
102
- if req. await_timeout . is_some ( ) {
103
- unimplemented ! ( "await timeout is not yet implemented" ) ;
104
- }
105
-
106
- let ( awk_id, awakeable) = context. awakeable :: < String > ( ) ;
107
-
108
- context
109
- . object_client :: < awakeable_holder:: AwakeableHolderClient > ( req. awakeable_key )
110
- . hold ( awk_id)
111
- . call ( )
112
- . await ?;
113
- let value = awakeable. await ?;
114
-
115
- Ok ( CreateAwakeableAndAwaitItResponse :: Result { value } . into ( ) )
116
- }
117
-
118
59
async fn sleep_concurrently (
119
60
& self ,
120
61
context : Context < ' _ > ,
@@ -153,10 +94,6 @@ impl TestUtilsService for TestUtilsServiceImpl {
153
94
Ok ( counter. load ( Ordering :: SeqCst ) as u32 )
154
95
}
155
96
156
- async fn get_env_variable ( & self , _: Context < ' _ > , env : String ) -> HandlerResult < String > {
157
- Ok ( std:: env:: var ( env) . ok ( ) . unwrap_or_default ( ) )
158
- }
159
-
160
97
async fn cancel_invocation (
161
98
& self ,
162
99
ctx : Context < ' _ > ,
@@ -165,34 +102,4 @@ impl TestUtilsService for TestUtilsServiceImpl {
165
102
ctx. invocation_handle ( invocation_id) . cancel ( ) . await ?;
166
103
Ok ( ( ) )
167
104
}
168
-
169
- async fn interpret_commands (
170
- & self ,
171
- context : Context < ' _ > ,
172
- Json ( req) : Json < InterpretRequest > ,
173
- ) -> HandlerResult < ( ) > {
174
- let list_client = context. object_client :: < ListObjectClient > ( req. list_name ) ;
175
-
176
- for cmd in req. commands {
177
- match cmd {
178
- InterpretCommand :: CreateAwakeableAndAwaitIt { awakeable_key } => {
179
- let ( awk_id, awakeable) = context. awakeable :: < String > ( ) ;
180
- context
181
- . object_client :: < awakeable_holder:: AwakeableHolderClient > ( awakeable_key)
182
- . hold ( awk_id)
183
- . call ( )
184
- . await ?;
185
- let value = awakeable. await ?;
186
- list_client. append ( value) . send ( ) ;
187
- }
188
- InterpretCommand :: GetEnvVariable { env_name } => {
189
- list_client
190
- . append ( std:: env:: var ( env_name) . ok ( ) . unwrap_or_default ( ) )
191
- . send ( ) ;
192
- }
193
- }
194
- }
195
-
196
- Ok ( ( ) )
197
- }
198
105
}
0 commit comments