Repository: knox Updated Branches: refs/heads/master 1e8d8a195 -> 75866cb1d
KNOX-301: Attempt to stabilize deployment unit test on various platforms. Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/75866cb1 Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/75866cb1 Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/75866cb1 Branch: refs/heads/master Commit: 75866cb1d03f91f64fb9a01a7b7e36089ce84736 Parents: 1e8d8a1 Author: Kevin Minder <[email protected]> Authored: Wed Mar 12 17:26:11 2014 -0400 Committer: Kevin Minder <[email protected]> Committed: Wed Mar 12 17:26:11 2014 -0400 ---------------------------------------------------------------------- .../hadoop/gateway/GatewayDeployFuncTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/75866cb1/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 8d8f453..f253cf3 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 @@ -218,6 +218,7 @@ public class GatewayDeployFuncTest { assertThat( deployDir.listFiles().length, is( 0 ) ); File descriptor = writeTestTopology( "test-cluster", createTopology() ); + long writeTime = System.currentTimeMillis(); warDir = waitForFiles( deployDir, "test-cluster.war\\.[0-9A-Fa-f]+", 1, 0, sleep ); for( File webInfDir : warDir.listFiles() ) { @@ -225,9 +226,13 @@ public class GatewayDeployFuncTest { } waitForAccess( serviceUrl, username, password, sleep ); + // Wait to make sure a second has passed to ensure the the file timestamps are different. + waitForElapsed( writeTime, 1000, 100 ); + // Redeploy and make sure the timestamp is updated. topoTimestampBefore = descriptor.lastModified(); GatewayServer.redeployTopologies( config, null ); + writeTime = System.currentTimeMillis(); topoTimestampAfter = descriptor.lastModified(); assertThat( topoTimestampAfter, greaterThan( topoTimestampBefore ) ); @@ -238,9 +243,13 @@ public class GatewayDeployFuncTest { } waitForAccess( serviceUrl, username, password, sleep ); + // Wait to make sure a second has passed to ensure the the file timestamps are different. + waitForElapsed( writeTime, 1000, 100 ); + // Redeploy and make sure the timestamp is updated. topoTimestampBefore = descriptor.lastModified(); GatewayServer.redeployTopologies( config, "test-cluster" ); + writeTime = System.currentTimeMillis(); topoTimestampAfter = descriptor.lastModified(); assertThat( topoTimestampAfter, greaterThan( topoTimestampBefore ) ); @@ -254,6 +263,9 @@ public class GatewayDeployFuncTest { // Delete the test topology. assertThat( "Failed to delete the topology file.", descriptor.delete(), is( true ) ); + // Wait to make sure a second has passed to ensure the the file timestamps are different. + waitForElapsed( writeTime, 1000, 100 ); + waitForFiles( deployDir, ".*", 0, -1, sleep ); // Wait a bit more to make sure undeployment finished. @@ -269,6 +281,12 @@ public class GatewayDeployFuncTest { assertThat( deployDir.listFiles().length, is( 0 ) ); } + private void waitForElapsed( long from, long total, long sleep ) throws InterruptedException { + while( System.currentTimeMillis() - from < total ) { + Thread.sleep( sleep ); + } + } + private File writeTestTopology( String name, XMLTag xml ) throws IOException { // Create the test topology. File tempFile = new File( config.getGatewayTopologyDir(), name + ".xml." + UUID.randomUUID() );
