Issue #12185 Custom FJP in unit test and more white space formatting
This commit is contained in:
parent
f37a4a167b
commit
994012e7eb
|
@ -17,6 +17,7 @@ import java.time.Duration;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
|
@ -436,31 +437,35 @@ public class QoSHandlerTest
|
|||
|
||||
int parallelism = 8;
|
||||
Vector<Integer> statusCodes = new Vector<>(); // due to synchronized List
|
||||
IntStream.range(0, parallelism).parallel().forEach(i ->
|
||||
ForkJoinPool fjp = new ForkJoinPool(parallelism);
|
||||
try
|
||||
{
|
||||
try (LocalConnector.LocalEndPoint endPoint = connector.executeRequest("""
|
||||
GET /%d HTTP/1.1
|
||||
Host: localhost
|
||||
fjp.submit(() -> IntStream.range(0, parallelism).parallel().forEach(i ->
|
||||
{
|
||||
try (LocalConnector.LocalEndPoint endPoint = connector.executeRequest("""
|
||||
GET /%d HTTP/1.1
|
||||
Host: localhost
|
||||
|
||||
""".formatted(i)))
|
||||
{
|
||||
String text = endPoint.getResponse(false, parallelism * delay * 5, TimeUnit.MILLISECONDS);
|
||||
HttpTester.Response response = HttpTester.parseResponse(text);
|
||||
statusCodes.add(response.getStatus());
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
fail(x);
|
||||
}
|
||||
});
|
||||
|
||||
await().atMost(5, TimeUnit.SECONDS).until(statusCodes::size, is(8));
|
||||
// expectation is that
|
||||
// 2 requests will be handled straight away
|
||||
// 2 will be suspended and eventually handled
|
||||
// 4 will hit the max suspended request limit
|
||||
assertEquals(4, statusCodes.stream().filter(sc -> sc == HttpStatus.OK_200).count());
|
||||
assertEquals(4, statusCodes.stream().filter(sc -> sc == HttpStatus.SERVICE_UNAVAILABLE_503).count());
|
||||
""".formatted(i))) {
|
||||
String text = endPoint.getResponse(false, parallelism * delay * 5, TimeUnit.MILLISECONDS);
|
||||
HttpTester.Response response = HttpTester.parseResponse(text);
|
||||
statusCodes.add(response.getStatus());
|
||||
} catch (Exception x) {
|
||||
fail(x);
|
||||
}
|
||||
}));
|
||||
await().atMost(5, TimeUnit.SECONDS).until(statusCodes::size, is(8));
|
||||
// expectation is that
|
||||
// 2 requests will be handled straight away
|
||||
// 2 will be suspended and eventually handled
|
||||
// 4 will hit the max suspended request limit
|
||||
assertEquals(4, statusCodes.stream().filter(sc -> sc == HttpStatus.OK_200).count());
|
||||
assertEquals(4, statusCodes.stream().filter(sc -> sc == HttpStatus.SERVICE_UNAVAILABLE_503).count());
|
||||
}
|
||||
finally
|
||||
{
|
||||
fjp.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue