From 23f3fff367680397c1245b39d1c1311bf52ca2e5 Mon Sep 17 00:00:00 2001 From: Lukas Krecan Date: Tue, 29 Mar 2016 10:33:21 +0200 Subject: [PATCH] Replacing potentionally slow and infinite while loop by a latch --- .../server/reactive/XmlHandlerIntegrationTests.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/XmlHandlerIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/XmlHandlerIntegrationTests.java index b286a8273b..502b9f9176 100644 --- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/XmlHandlerIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/XmlHandlerIntegrationTests.java @@ -19,6 +19,8 @@ package org.springframework.http.server.reactive; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; @@ -69,9 +71,7 @@ public class XmlHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTe ResponseEntity response = restTemplate.exchange(request, Person.class); assertEquals(janeDoe, response.getBody()); - while (!handler.requestComplete) { - Thread.sleep(100); - } + handler.requestComplete.await(10, TimeUnit.SECONDS); if (handler.requestError != null) { throw handler.requestError; } @@ -81,7 +81,7 @@ public class XmlHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTe private static class XmlHandler implements HttpHandler { - private volatile boolean requestComplete = false; + private CountDownLatch requestComplete = new CountDownLatch(1); private Person requestPerson; @@ -108,7 +108,7 @@ public class XmlHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTe requestError = ex; } finally { - requestComplete = true; + requestComplete.countDown(); } };