@@ -182,6 +182,7 @@ struct RequestExecutor<B> {
182
182
ctx : ExecutorContext < B > ,
183
183
client : Arc < BenchmarkServiceClient > ,
184
184
req : SimpleRequest ,
185
+ cfg : ClientConfig ,
185
186
}
186
187
187
188
impl < B : Backoff + Send + ' static > RequestExecutor < B > {
@@ -190,6 +191,7 @@ impl<B: Backoff + Send + 'static> RequestExecutor<B> {
190
191
ctx,
191
192
client : Arc :: new ( BenchmarkServiceClient :: new ( channel) ) ,
192
193
req : gen_req ( cfg) ,
194
+ cfg : cfg. clone ( ) ,
193
195
}
194
196
}
195
197
@@ -254,6 +256,38 @@ impl<B: Backoff + Send + 'static> RequestExecutor<B> {
254
256
} ;
255
257
spawn ! ( client, keep_running, "streaming ping pong" , f) ;
256
258
}
259
+
260
+ fn execute_stream_from_client ( mut self ) {
261
+ let client = self . client . clone ( ) ;
262
+ let keep_running = self . ctx . keep_running . clone ( ) ;
263
+
264
+ let mut send_data = vec ! [ ] ;
265
+ for _ in 0 ..self . cfg . get_messages_per_stream ( ) {
266
+ send_data. push ( self . req . clone ( ) ) ;
267
+ }
268
+ let f = async move {
269
+ loop {
270
+ let ( mut sender, receiver) = self . client . streaming_from_client ( ) . unwrap ( ) ;
271
+ let latency_timer = Instant :: now ( ) ;
272
+ let send_stream = futures:: stream:: iter ( send_data. clone ( ) ) ;
273
+ sender
274
+ . send_all ( & mut send_stream. map ( move |item| Ok ( ( item, WriteFlags :: default ( ) ) ) ) )
275
+ . await ?;
276
+ sender. close ( ) . await ?;
277
+ receiver. await ?;
278
+ self . ctx . observe_latency ( latency_timer. elapsed ( ) ) ;
279
+ let mut time = self . ctx . backoff_async ( ) ;
280
+ if let Some ( t) = & mut time {
281
+ t. await ;
282
+ }
283
+ if !self . ctx . keep_running ( ) {
284
+ break ;
285
+ }
286
+ }
287
+ Ok ( ( ) )
288
+ } ;
289
+ spawn ! ( client, keep_running, "streaming from client" , f) ;
290
+ }
257
291
}
258
292
259
293
fn execute < B : Backoff + Send + ' static > (
@@ -272,7 +306,7 @@ fn execute<B: Backoff + Send + 'static>(
272
306
ClientType :: ASYNC_CLIENT => match cfg. get_rpc_type ( ) {
273
307
RpcType :: UNARY => {
274
308
if cfg. get_payload_config ( ) . has_bytebuf_params ( ) {
275
- panic ! ( "only streaming is supported for generic service." ) ;
309
+ panic ! ( "only ping pong streaming is supported for generic service." ) ;
276
310
}
277
311
RequestExecutor :: new ( ctx, ch, cfg) . execute_unary_async ( )
278
312
}
@@ -283,6 +317,12 @@ fn execute<B: Backoff + Send + 'static>(
283
317
RequestExecutor :: new ( ctx, ch, cfg) . execute_stream_ping_pong ( )
284
318
}
285
319
}
320
+ RpcType :: STREAMING_FROM_CLIENT => {
321
+ if cfg. get_payload_config ( ) . has_bytebuf_params ( ) {
322
+ panic ! ( "only ping pong streaming is supported for generic service." ) ;
323
+ }
324
+ RequestExecutor :: new ( ctx, ch, cfg) . execute_stream_from_client ( )
325
+ }
286
326
_ => unimplemented ! ( ) ,
287
327
} ,
288
328
_ => unimplemented ! ( ) ,
0 commit comments