You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by km...@apache.org on 2014/02/28 14:26:34 UTC
git commit: KNOX-280: Add more retry/timeout logic to make test more
resilient.
Repository: knox
Updated Branches:
refs/heads/master a6317fc81 -> 1333808b0
KNOX-280: Add more retry/timeout logic to make test more resilient.
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/1333808b
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/1333808b
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/1333808b
Branch: refs/heads/master
Commit: 1333808b075cf6b3f64a3f6fdcbc0ebee6309065
Parents: a6317fc
Author: Kevin Minder <ke...@hortonworks.com>
Authored: Fri Feb 28 08:26:26 2014 -0500
Committer: Kevin Minder <ke...@hortonworks.com>
Committed: Fri Feb 28 08:26:26 2014 -0500
----------------------------------------------------------------------
.../hadoop/gateway/GatewayDeployFuncTest.java | 38 +++++++++++---------
1 file changed, 22 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/1333808b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
index 78771b5..1e8ef5d 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
@@ -17,7 +17,7 @@
*/
package org.apache.hadoop.gateway;
-import com.google.common.io.Files;
+import com.jayway.restassured.response.Response;
import com.mycila.xmltool.XMLDoc;
import com.mycila.xmltool.XMLTag;
import org.apache.commons.io.FileUtils;
@@ -52,6 +52,7 @@ import java.util.UUID;
import java.util.regex.Pattern;
import static com.jayway.restassured.RestAssured.given;
+import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.lessThan;
@@ -203,7 +204,7 @@ public class GatewayDeployFuncTest {
@Test
public void testDeployUndeploy() throws Exception {
- long timeout = 5 * 1000;
+ long timeout = 5 * 1000; // Five seconds.
long sleep = 200;
String username = "guest";
String password = "guest-password";
@@ -227,8 +228,10 @@ public class GatewayDeployFuncTest {
// Make sure deployment directory has one WAR with the correct name.
long before = System.currentTimeMillis();
+ long elapsed = 0;
while( true ) {
- assertThat( "Waited too long for topology deployment dir creation.", System.currentTimeMillis() - before, lessThan( timeout ) );
+ elapsed = System.currentTimeMillis() - before;
+ assertThat( "Waited too long for topology deployment dir creation.", elapsed, lessThan( timeout ) );
File[] files = deployDir.listFiles( new RegexDirFilter( "test-cluster.war\\.[0-9A-Fa-f]+" ) );
if( files.length == 1 ) {
warDir = files[0];
@@ -237,7 +240,8 @@ public class GatewayDeployFuncTest {
Thread.sleep( sleep );
}
while( true ) {
- assertThat( "Waited too long for topology deployment file creation.", System.currentTimeMillis() - before, lessThan( timeout ) );
+ elapsed = System.currentTimeMillis() - before;
+ assertThat( "Waited too long for topology deployment file creation.", elapsed, lessThan( timeout ) );
File webInfDir = new File( warDir, "WEB-INF" );
File[] files = webInfDir.listFiles();
//System.out.println( "DEPLOYMENT FILES: " + files.length );
@@ -250,19 +254,21 @@ public class GatewayDeployFuncTest {
Thread.sleep( sleep );
}
- // Wait a bit more to make sure deployment finished.
- Thread.sleep( sleep );
-
// Make sure the test topology is accessible.
- given()
- //.log().all()
- .auth().preemptive().basic( username, password )
- .expect()
- //.log().all()
- .statusCode( HttpStatus.SC_OK )
- .contentType( "text/plain" )
- .body( is( "test-service-response" ) )
- .when().get( serviceUrl );
+ while( true ) {
+ elapsed = System.currentTimeMillis() - before;
+ assertThat( "Waited too long for topology to be accessible.", elapsed, lessThan( timeout ) );
+ Response response = given()
+ .auth().preemptive().basic( username, password )
+ .when().get( serviceUrl ).andReturn();
+ if( response.getStatusCode() == HttpStatus.SC_NOT_FOUND ) {
+ Thread.sleep( sleep );
+ continue;
+ }
+ assertThat( response.getContentType(), containsString( "text/plain" ) );
+ assertThat( response.getBody().asString(), is( "test-service-response" ) );
+ break;
+ }
// Delete the test topology.
assertThat( "Failed to delete the topology file.", descriptor.delete(), is( true ) );