@@ -239,7 +239,7 @@ public boolean canTripCircuitBreaker() {
239239
240240 public void testDispatchRequestAddsAndFreesBytesOnSuccess () {
241241 int contentLength = BREAKER_LIMIT .bytesAsInt ();
242- String content = randomAlphaOfLength (contentLength );
242+ String content = randomAlphaOfLength (( int ) Math . round ( contentLength / inFlightRequestsBreaker . getOverhead ()) );
243243 RestRequest request = testRestRequest ("/" , content , XContentType .JSON );
244244 AssertingChannel channel = new AssertingChannel (request , true , RestStatus .OK );
245245
@@ -251,7 +251,7 @@ public void testDispatchRequestAddsAndFreesBytesOnSuccess() {
251251
252252 public void testDispatchRequestAddsAndFreesBytesOnError () {
253253 int contentLength = BREAKER_LIMIT .bytesAsInt ();
254- String content = randomAlphaOfLength (contentLength );
254+ String content = randomAlphaOfLength (( int ) Math . round ( contentLength / inFlightRequestsBreaker . getOverhead ()) );
255255 RestRequest request = testRestRequest ("/error" , content , XContentType .JSON );
256256 AssertingChannel channel = new AssertingChannel (request , true , RestStatus .BAD_REQUEST );
257257
@@ -263,7 +263,7 @@ public void testDispatchRequestAddsAndFreesBytesOnError() {
263263
264264 public void testDispatchRequestAddsAndFreesBytesOnlyOnceOnError () {
265265 int contentLength = BREAKER_LIMIT .bytesAsInt ();
266- String content = randomAlphaOfLength (contentLength );
266+ String content = randomAlphaOfLength (( int ) Math . round ( contentLength / inFlightRequestsBreaker . getOverhead ()) );
267267 // we will produce an error in the rest handler and one more when sending the error response
268268 RestRequest request = testRestRequest ("/error" , content , XContentType .JSON );
269269 ExceptionThrowingChannel channel = new ExceptionThrowingChannel (request , true );
@@ -276,7 +276,7 @@ public void testDispatchRequestAddsAndFreesBytesOnlyOnceOnError() {
276276
277277 public void testDispatchRequestLimitsBytes () {
278278 int contentLength = BREAKER_LIMIT .bytesAsInt () + 1 ;
279- String content = randomAlphaOfLength (contentLength );
279+ String content = randomAlphaOfLength (( int ) Math . round ( contentLength / inFlightRequestsBreaker . getOverhead ()) );
280280 RestRequest request = testRestRequest ("/" , content , XContentType .JSON );
281281 AssertingChannel channel = new AssertingChannel (request , true , RestStatus .SERVICE_UNAVAILABLE );
282282
@@ -287,7 +287,7 @@ public void testDispatchRequestLimitsBytes() {
287287 }
288288
289289 public void testDispatchRequiresContentTypeForRequestsWithContent () {
290- String content = randomAlphaOfLengthBetween ( 1 , BREAKER_LIMIT .bytesAsInt ( ));
290+ String content = randomAlphaOfLength (( int ) Math . round ( BREAKER_LIMIT .getBytes () / inFlightRequestsBreaker . getOverhead () ));
291291 RestRequest request = testRestRequest ("/" , content , null );
292292 AssertingChannel channel = new AssertingChannel (request , true , RestStatus .NOT_ACCEPTABLE );
293293 restController = new RestController (
@@ -312,7 +312,7 @@ public void testDispatchDoesNotRequireContentTypeForRequestsWithoutContent() {
312312 }
313313
314314 public void testDispatchFailsWithPlainText () {
315- String content = randomAlphaOfLengthBetween ( 1 , BREAKER_LIMIT .bytesAsInt ( ));
315+ String content = randomAlphaOfLength (( int ) Math . round ( BREAKER_LIMIT .getBytes () / inFlightRequestsBreaker . getOverhead () ));
316316 FakeRestRequest fakeRestRequest = new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
317317 .withContent (new BytesArray (content ), null ).withPath ("/foo" )
318318 .withHeaders (Collections .singletonMap ("Content-Type" , Collections .singletonList ("text/plain" ))).build ();
@@ -342,7 +342,7 @@ public void testDispatchUnsupportedContentType() {
342342
343343 public void testDispatchWorksWithNewlineDelimitedJson () {
344344 final String mimeType = "application/x-ndjson" ;
345- String content = randomAlphaOfLengthBetween ( 1 , BREAKER_LIMIT .bytesAsInt ( ));
345+ String content = randomAlphaOfLength (( int ) Math . round ( BREAKER_LIMIT .getBytes () / inFlightRequestsBreaker . getOverhead () ));
346346 FakeRestRequest fakeRestRequest = new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
347347 .withContent (new BytesArray (content ), null ).withPath ("/foo" )
348348 .withHeaders (Collections .singletonMap ("Content-Type" , Collections .singletonList (mimeType ))).build ();
@@ -366,7 +366,7 @@ public boolean supportsContentStream() {
366366
367367 public void testDispatchWithContentStream () {
368368 final String mimeType = randomFrom ("application/json" , "application/smile" );
369- String content = randomAlphaOfLengthBetween ( 1 , BREAKER_LIMIT .bytesAsInt ( ));
369+ String content = randomAlphaOfLength (( int ) Math . round ( BREAKER_LIMIT .getBytes () / inFlightRequestsBreaker . getOverhead () ));
370370 final List <String > contentTypeHeader = Collections .singletonList (mimeType );
371371 FakeRestRequest fakeRestRequest = new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
372372 .withContent (new BytesArray (content ), RestRequest .parseContentType (contentTypeHeader )).withPath ("/foo" )
0 commit comments