@@ -239,7 +239,7 @@ public boolean canTripCircuitBreaker() {
239
239
240
240
public void testDispatchRequestAddsAndFreesBytesOnSuccess () {
241
241
int contentLength = BREAKER_LIMIT .bytesAsInt ();
242
- String content = randomAlphaOfLength (contentLength );
242
+ String content = randomAlphaOfLength (( int ) Math . round ( contentLength / inFlightRequestsBreaker . getOverhead ()) );
243
243
RestRequest request = testRestRequest ("/" , content , XContentType .JSON );
244
244
AssertingChannel channel = new AssertingChannel (request , true , RestStatus .OK );
245
245
@@ -251,7 +251,7 @@ public void testDispatchRequestAddsAndFreesBytesOnSuccess() {
251
251
252
252
public void testDispatchRequestAddsAndFreesBytesOnError () {
253
253
int contentLength = BREAKER_LIMIT .bytesAsInt ();
254
- String content = randomAlphaOfLength (contentLength );
254
+ String content = randomAlphaOfLength (( int ) Math . round ( contentLength / inFlightRequestsBreaker . getOverhead ()) );
255
255
RestRequest request = testRestRequest ("/error" , content , XContentType .JSON );
256
256
AssertingChannel channel = new AssertingChannel (request , true , RestStatus .BAD_REQUEST );
257
257
@@ -263,7 +263,7 @@ public void testDispatchRequestAddsAndFreesBytesOnError() {
263
263
264
264
public void testDispatchRequestAddsAndFreesBytesOnlyOnceOnError () {
265
265
int contentLength = BREAKER_LIMIT .bytesAsInt ();
266
- String content = randomAlphaOfLength (contentLength );
266
+ String content = randomAlphaOfLength (( int ) Math . round ( contentLength / inFlightRequestsBreaker . getOverhead ()) );
267
267
// we will produce an error in the rest handler and one more when sending the error response
268
268
RestRequest request = testRestRequest ("/error" , content , XContentType .JSON );
269
269
ExceptionThrowingChannel channel = new ExceptionThrowingChannel (request , true );
@@ -276,7 +276,7 @@ public void testDispatchRequestAddsAndFreesBytesOnlyOnceOnError() {
276
276
277
277
public void testDispatchRequestLimitsBytes () {
278
278
int contentLength = BREAKER_LIMIT .bytesAsInt () + 1 ;
279
- String content = randomAlphaOfLength (contentLength );
279
+ String content = randomAlphaOfLength (( int ) Math . round ( contentLength / inFlightRequestsBreaker . getOverhead ()) );
280
280
RestRequest request = testRestRequest ("/" , content , XContentType .JSON );
281
281
AssertingChannel channel = new AssertingChannel (request , true , RestStatus .SERVICE_UNAVAILABLE );
282
282
@@ -287,7 +287,7 @@ public void testDispatchRequestLimitsBytes() {
287
287
}
288
288
289
289
public void testDispatchRequiresContentTypeForRequestsWithContent () {
290
- String content = randomAlphaOfLengthBetween ( 1 , BREAKER_LIMIT .bytesAsInt ( ));
290
+ String content = randomAlphaOfLength (( int ) Math . round ( BREAKER_LIMIT .getBytes () / inFlightRequestsBreaker . getOverhead () ));
291
291
RestRequest request = testRestRequest ("/" , content , null );
292
292
AssertingChannel channel = new AssertingChannel (request , true , RestStatus .NOT_ACCEPTABLE );
293
293
restController = new RestController (
@@ -312,7 +312,7 @@ public void testDispatchDoesNotRequireContentTypeForRequestsWithoutContent() {
312
312
}
313
313
314
314
public void testDispatchFailsWithPlainText () {
315
- String content = randomAlphaOfLengthBetween ( 1 , BREAKER_LIMIT .bytesAsInt ( ));
315
+ String content = randomAlphaOfLength (( int ) Math . round ( BREAKER_LIMIT .getBytes () / inFlightRequestsBreaker . getOverhead () ));
316
316
FakeRestRequest fakeRestRequest = new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
317
317
.withContent (new BytesArray (content ), null ).withPath ("/foo" )
318
318
.withHeaders (Collections .singletonMap ("Content-Type" , Collections .singletonList ("text/plain" ))).build ();
@@ -342,7 +342,7 @@ public void testDispatchUnsupportedContentType() {
342
342
343
343
public void testDispatchWorksWithNewlineDelimitedJson () {
344
344
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 () ));
346
346
FakeRestRequest fakeRestRequest = new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
347
347
.withContent (new BytesArray (content ), null ).withPath ("/foo" )
348
348
.withHeaders (Collections .singletonMap ("Content-Type" , Collections .singletonList (mimeType ))).build ();
@@ -366,7 +366,7 @@ public boolean supportsContentStream() {
366
366
367
367
public void testDispatchWithContentStream () {
368
368
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 () ));
370
370
final List <String > contentTypeHeader = Collections .singletonList (mimeType );
371
371
FakeRestRequest fakeRestRequest = new FakeRestRequest .Builder (NamedXContentRegistry .EMPTY )
372
372
.withContent (new BytesArray (content ), RestRequest .parseContentType (contentTypeHeader )).withPath ("/foo" )
0 commit comments