99import com .azure .core .perf .core .CorePerfStressOptions ;
1010import com .azure .core .perf .core .RestProxyTestBase ;
1111import com .azure .core .util .BinaryData ;
12+ import com .azure .core .util .UrlBuilder ;
1213import reactor .core .publisher .Mono ;
1314
1415import java .io .UncheckedIOException ;
@@ -20,15 +21,22 @@ public class PipelineSendTest extends RestProxyTestBase<CorePerfStressOptions> {
2021
2122 private final Supplier <BinaryData > binaryDataSupplier ;
2223 private final URL targetURL ;
24+ private final String contentLengthHeaderValue ;
2325
2426 public PipelineSendTest (CorePerfStressOptions options ) {
2527 super (options );
2628 binaryDataSupplier = createBinaryDataSupplier (options );
2729 try {
28- targetURL = new URL (new URL (endpoint ), "BinaryData" );
30+ UrlBuilder urlBuilder = UrlBuilder .parse (endpoint );
31+ String path = urlBuilder .getPath ();
32+ path = path == null ? "" : path ;
33+ targetURL = urlBuilder
34+ .setPath (path + "/BinaryData" )
35+ .toUrl ();
2936 } catch (MalformedURLException e ) {
3037 throw new UncheckedIOException (e );
3138 }
39+ contentLengthHeaderValue = Long .toString (options .getSize ());
3240 }
3341
3442 @ Override
@@ -38,9 +46,17 @@ public void run() {
3846
3947 @ Override
4048 public Mono <Void > runAsync () {
49+ HttpHeaders headers = new HttpHeaders ();
50+ headers .set ("Content-Length" , contentLengthHeaderValue );
4151 HttpRequest httpRequest = new HttpRequest (
42- HttpMethod .PUT , targetURL , new HttpHeaders () , binaryDataSupplier .get ().toFluxByteBuffer ());
52+ HttpMethod .PUT , targetURL , headers , binaryDataSupplier .get ().toFluxByteBuffer ());
4353 return httpPipeline .send (httpRequest )
54+ .map (httpResponse -> {
55+ if (httpResponse .getStatusCode () / 100 != 2 ) {
56+ throw new IllegalStateException ("Endpoint didn't return 2xx http status code." );
57+ }
58+ return httpResponse ;
59+ })
4460 .then ();
4561 }
4662}
0 commit comments