Skip to content

Commit

Permalink
Merge pull request #2967 from jamezp/RESTEASY-3049-4.x
Browse files Browse the repository at this point in the history
[RESTEASY-3049] Use a timeout when waiting for the latch to count dow…
  • Loading branch information
jamezp committed Nov 24, 2021
2 parents bc60a58 + 61ed5ae commit 9184327
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -40,6 +41,7 @@
*/
public class StreamingOutputTest
{
private static final int LOOP_COUNT = 10;
static String BASE_URI = generateURL("");
static Client client;
static CountDownLatch latch;
Expand All @@ -53,7 +55,7 @@ public StreamingOutput stream() {
return new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
for (int i = 0; i < 10; i++) {
for (int i = 0; i < LOOP_COUNT; i++) {
output.write(("" + i + "\n\n").getBytes(StandardCharsets.ISO_8859_1));
output.flush();
}
Expand All @@ -68,7 +70,7 @@ public StreamingOutput delay() {
return new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
for (int i = 0; i < 10; i++) {
for (int i = 0; i < LOOP_COUNT; i++) {
output.write(("" + i + "\n\n").getBytes(StandardCharsets.ISO_8859_1));
try
{
Expand Down Expand Up @@ -128,7 +130,7 @@ public static void end() throws Exception
public void testConcurrent() throws Exception
{
pass = false;
latch = new CountDownLatch(1);
latch = new CountDownLatch(LOOP_COUNT);
Runnable r = new Runnable()
{
@Override
Expand All @@ -140,11 +142,10 @@ public void run()
};
Thread t = new Thread(r);
t.start();
latch.await();
Assert.assertTrue("Result not returned within 30 seconds. Lath count: " + latch.getCount(), latch.await(30, TimeUnit.SECONDS));
long start = System.currentTimeMillis();
testStreamingOutput();
long end = System.currentTimeMillis() - start;
// System.out.println(end);
Assert.assertTrue(end < 1000);
t.join();
Assert.assertTrue(pass);
Expand Down

0 comments on commit 9184327

Please sign in to comment.