Repository: incubator-brooklyn Updated Branches: refs/heads/master d20d452d8 -> d2b47e770
Fix integration tests - brooklyn-core Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/fae666cf Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/fae666cf Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/fae666cf Branch: refs/heads/master Commit: fae666cfbc0502af7b0afeac135c4604fd429bf9 Parents: 9c9a866 Author: Svetoslav Neykov <[email protected]> Authored: Thu Jun 18 13:00:15 2015 +0300 Committer: Svetoslav Neykov <[email protected]> Committed: Fri Jun 19 12:43:02 2015 +0300 ---------------------------------------------------------------------- .../location/basic/SshMachineLocation.java | 10 ++++--- .../util/internal/ssh/ShellAbstractTool.java | 29 +++++++++++------- .../catalog/internal/CatalogDtoTest.java | 12 ++++---- .../entity/basic/ServiceStateLogicTest.java | 22 +++++++------- .../persister/XmlMementoSerializerTest.java | 15 ++++++++++ .../brooklyn/event/feed/http/HttpFeedTest.java | 17 ++--------- .../SshMachineLocationIntegrationTest.java | 9 +++++- .../location/basic/SshMachineLocationTest.java | 4 ++- .../geo/HostGeoLookupIntegrationTest.java | 6 +++- .../sshj/SshjToolAsyncStubIntegrationTest.java | 6 ++-- .../ssh/sshj/SshjToolIntegrationTest.java | 31 +++++++++++++------- 11 files changed, 100 insertions(+), 61 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java b/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java index 40dc1e5..a249305 100644 --- a/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java +++ b/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java @@ -35,9 +35,9 @@ import java.io.PipedOutputStream; import java.io.Reader; import java.io.StringReader; import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.Socket; import java.security.KeyPair; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -76,12 +76,10 @@ import brooklyn.util.file.ArchiveUtils; import brooklyn.util.flags.SetFromFlag; import brooklyn.util.flags.TypeCoercions; import brooklyn.util.guava.KeyTransformingLoadingCache.KeyTransformingSameTypeLoadingCache; -import brooklyn.util.guava.Maybe; import brooklyn.util.internal.ssh.ShellTool; import brooklyn.util.internal.ssh.SshException; import brooklyn.util.internal.ssh.SshTool; import brooklyn.util.internal.ssh.sshj.SshjTool; -import brooklyn.util.javalang.StackTraceSimplifier; import brooklyn.util.mutex.MutexSupport; import brooklyn.util.mutex.WithMutexes; import brooklyn.util.net.Urls; @@ -133,6 +131,9 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat public static final Logger LOG = LoggerFactory.getLogger(SshMachineLocation.class); /** @deprecated since 0.7.0 shouldn't be public */ public static final Logger logSsh = LoggerFactory.getLogger(BrooklynLogging.SSH_IO); + + // Use a sane timeout when doing a connectivity test + private static final int SSHABLE_CONNECT_TIMEOUT = (int)Duration.minutes(2).toMilliseconds(); public static final ConfigKey<Duration> SSH_CACHE_EXPIRY_DURATION = ConfigKeys.newConfigKey(Duration.class, "sshCacheExpiryDuration", "Expiry time for unused cached ssh connections", Duration.FIVE_MINUTES); @@ -876,7 +877,8 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat String cmd = "date"; try { try { - Socket s = new Socket(getAddress(), getPort()); + Socket s = new Socket(); + s.connect(new InetSocketAddress(getAddress(), getPort()), SSHABLE_CONNECT_TIMEOUT); s.close(); } catch (IOException e) { if (LOG.isDebugEnabled()) LOG.debug(""+this+" not [yet] reachable (socket "+getAddress()+":"+getPort()+"): "+e); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/main/java/brooklyn/util/internal/ssh/ShellAbstractTool.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/util/internal/ssh/ShellAbstractTool.java b/core/src/main/java/brooklyn/util/internal/ssh/ShellAbstractTool.java index e677399..10e9699 100644 --- a/core/src/main/java/brooklyn/util/internal/ssh/ShellAbstractTool.java +++ b/core/src/main/java/brooklyn/util/internal/ssh/ShellAbstractTool.java @@ -296,9 +296,10 @@ public abstract class ShellAbstractTool implements ShellTool { * The executed command will return immediately, but the output from the script * will continue to be written * note that some modes require \$RESULT passed in order to access a variable, whereas most just need $ */ + @Override protected List<String> buildRunScriptCommand() { String touchCmd = String.format("touch %s %s %s %s", stdoutPath, stderrPath, exitStatusPath, pidPath); - String cmd = String.format("( %s > %s 2> %s < /dev/null ; echo $? > %s ) & disown", scriptPath, stdoutPath, stderrPath, exitStatusPath); + String cmd = String.format("nohup sh -c \"( %s > %s 2> %s < /dev/null ) ; echo \\$? > %s \" > /dev/null 2>&1 < /dev/null &", scriptPath, stdoutPath, stderrPath, exitStatusPath); MutableList.Builder<String> cmds = MutableList.<String>builder() .add(runAsRoot ? BashCommands.sudo(touchCmd) : touchCmd) .add(runAsRoot ? BashCommands.sudo(cmd) : cmd) @@ -352,8 +353,8 @@ public abstract class ShellAbstractTool implements ShellTool { */ protected List<String> buildRetrieveStdoutAndStderrCommand(int stdoutPosition, int stderrPosition) { // Note that `tail -c +1` means start at the *first* character (i.e. start counting from 1, not 0) - String catStdoutCmd = "tail -c +"+(stdoutPosition+1)+" "+stdoutPath; - String catStderrCmd = "tail -c +"+(stderrPosition+1)+" "+stderrPath+" 1>&2"; + String catStdoutCmd = "tail -c +"+(stdoutPosition+1)+" "+stdoutPath+" 2> /dev/null"; + String catStderrCmd = "tail -c +"+(stderrPosition+1)+" "+stderrPath+" 2>&1 > /dev/null"; MutableList.Builder<String> cmds = MutableList.<String>builder() .add((runAsRoot ? BashCommands.sudo(catStdoutCmd) : catStdoutCmd)) .add((runAsRoot ? BashCommands.sudo(catStderrCmd) : catStderrCmd)) @@ -371,9 +372,12 @@ public abstract class ShellAbstractTool implements ShellTool { // Note that `tail -c +1` means start at the *first* character (i.e. start counting from 1, not 0) List<String> waitForExitStatusParts = ImmutableList.of( + //Should be careful here because any output will be part of the stdout/stderr streams "# Long poll", // comment is to aid testing - see SshjToolAsyncStubIntegrationTest - "tail -c +"+(stdoutPosition+1)+" -f "+stdoutPath+" & export TAIL_STDOUT_PID=$!", - "tail -c +"+(stderrPosition+1)+" -f "+stderrPath+" 1>&2 & export TAIL_STDERR_PID=$!", + // disown to avoid Terminated message after killing the process + // redirect error output to avoid "file truncated" messages + "tail -c +"+(stdoutPosition+1)+" -f "+stdoutPath+" 2> /dev/null & export TAIL_STDOUT_PID=$!; disown", + "tail -c +"+(stderrPosition+1)+" -f "+stderrPath+" 1>&2 2> /dev/null & export TAIL_STDERR_PID=$!; disown", "EXIT_STATUS_PATH="+exitStatusPath, "PID_PATH="+pidPath, "MAX_TIME="+maxTime, @@ -381,19 +385,20 @@ public abstract class ShellAbstractTool implements ShellTool { "while [ \"$COUNTER\" -lt $MAX_TIME ]; do", " if test -s $EXIT_STATUS_PATH; then", " EXIT_STATUS=`cat $EXIT_STATUS_PATH`", + " kill ${TAIL_STDERR_PID} ${TAIL_STDOUT_PID} 2> /dev/null", " exit $EXIT_STATUS", " elif test -s $PID_PATH; then", " PID=`cat $PID_PATH`", - " if ! ps -p $PID > /dev/null < /dev/null; then", + " if ! ps -p $PID > /dev/null 2>&1 < /dev/null; then", " # no exit status, and not executing; give a few seconds grace in case just about to write exit status", " sleep 3", " if test -s $EXIT_STATUS_PATH; then", " EXIT_STATUS=`cat $EXIT_STATUS_PATH`", - " kill ${TAIL_STDERR_PID} ${TAIL_STDOUT_PID}", + " kill ${TAIL_STDERR_PID} ${TAIL_STDOUT_PID} 2> /dev/null", " exit $EXIT_STATUS", " else", " echo \"No exit status in $EXIT_STATUS_PATH, and pid in $PID_PATH ($PID) not executing\"", - " kill ${TAIL_STDERR_PID} ${TAIL_STDOUT_PID}", + " kill ${TAIL_STDERR_PID} ${TAIL_STDOUT_PID} 2> /dev/null", " exit 126", " fi", " fi", @@ -402,7 +407,7 @@ public abstract class ShellAbstractTool implements ShellTool { " sleep 1", " COUNTER+=1", "done", - "kill ${TAIL_STDERR_PID} ${TAIL_STDOUT_PID}", + "kill ${TAIL_STDERR_PID} ${TAIL_STDOUT_PID} 2> /dev/null", "exit 125"+"\n"); String waitForExitStatus = Joiner.on("\n").join(waitForExitStatusParts); @@ -422,14 +427,16 @@ public abstract class ShellAbstractTool implements ShellTool { // If the buildLongPollCommand didn't complete properly then it might have left tail command running; // ensure they are killed. cmdParts.add( - "ps aux | grep \"tail -c\" | grep \""+stdoutPath+"\" | grep -v grep | awk '{ printf $2 }' | xargs kill", - "ps aux | grep \"tail -c\" | grep \""+stderrPath+"\" | grep -v grep | awk '{ printf $2 }' | xargs kill"); + //ignore error output for the case where there are no running processes and kill is called without arguments + "ps aux | grep \"tail -c\" | grep \""+stdoutPath+"\" | grep -v grep | awk '{ printf $2 }' | xargs kill 2> /dev/null", + "ps aux | grep \"tail -c\" | grep \""+stderrPath+"\" | grep -v grep | awk '{ printf $2 }' | xargs kill 2> /dev/null"); String cmd = Joiner.on("\n").join(cmdParts.build()); return ImmutableList.of(runAsRoot ? BashCommands.sudo(cmd) : cmd); } + @Override public abstract int run(); } } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java b/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java index 8ab75d5..a6f5c80 100644 --- a/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java +++ b/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java @@ -21,8 +21,6 @@ package brooklyn.catalog.internal; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.util.Arrays; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -40,6 +38,8 @@ import brooklyn.test.entity.TestEntity; import brooklyn.util.BrooklynMavenArtifacts; import brooklyn.util.maven.MavenRetriever; +import com.google.common.collect.ImmutableList; + public class CatalogDtoTest { private static final Logger log = LoggerFactory.getLogger(CatalogDtoTest.class); @@ -100,10 +100,12 @@ public class CatalogDtoTest { CatalogDto.newNamedInstance("Test Entities from Java", null, "test-java")); testEntitiesJavaCatalog.setClasspathScanForEntities(CatalogScanningModes.NONE); testEntitiesJavaCatalog.addToClasspath(bundleUrl); - testEntitiesJavaCatalog.addEntry(CatalogItemBuilder.newTemplate(TestApplication.class.getCanonicalName(), "Test App from JAR") + testEntitiesJavaCatalog.addEntry(CatalogItemBuilder.newTemplate(TestApplication.class.getCanonicalName(), BasicBrooklynCatalog.NO_VERSION) + .displayName("Test App from JAR") .javaType(TestApplication.class.getCanonicalName()) .build()); - testEntitiesJavaCatalog.addEntry(CatalogItemBuilder.newEntity(TestEntity.class.getCanonicalName(), "Test Entity from JAR") + testEntitiesJavaCatalog.addEntry(CatalogItemBuilder.newEntity(TestEntity.class.getCanonicalName(), BasicBrooklynCatalog.NO_VERSION) + .displayName("Test Entity from JAR") .javaType(TestEntity.class.getCanonicalName()) .build()); root.addCatalog(testEntitiesJavaCatalog.dto); @@ -122,7 +124,7 @@ public class CatalogDtoTest { osgiCatalog.setClasspathScanForEntities(CatalogScanningModes.NONE); CatalogEntityItemDto osgiEntity = CatalogItemBuilder.newEntity(TestEntity.class.getCanonicalName(), "Test Entity from OSGi") // NB: this is not actually an OSGi bundle, but it's okay as we don't instantiate the bundles ahead of time (currently) - .libraries(Arrays.<CatalogBundle>asList(new CatalogBundleDto(null, null, bundleUrl))) + .libraries(ImmutableList.<CatalogBundle>of(new CatalogBundleDto(null, null, bundleUrl))) .build(); testEntitiesJavaCatalog.addEntry(osgiEntity); root.addCatalog(osgiCatalog.dto); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java b/core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java index b39c585..ae1e1a0 100644 --- a/core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java +++ b/core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java @@ -167,14 +167,15 @@ public class ServiceStateLogicTest extends BrooklynAppUnitTestSupport { // won't propagate due to it's SERVICE_STATE_ACTUAL (null) being in IGNORE_ENTITIES_WITH_THESE_SERVICE_STATES ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "We're also pretending to block service up"); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, false); - assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true); - assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); + assertAttributeEqualsContinually(app, Attributes.SERVICE_UP, true); + assertAttributeEqualsContinually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); // the entity still has no opinion about its state - assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, null); + assertAttributeEqualsContinually(entity, Attributes.SERVICE_STATE_ACTUAL, null); // switching the entity state to one not in IGNORE_ENTITIES_WITH_THESE_SERVICE_STATES will propagate the up state ServiceStateLogic.setExpectedState(entity, Lifecycle.RUNNING); - assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, false); + assertAttributeEqualsContinually(entity, Attributes.SERVICE_UP, false); + assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, false); assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED); @@ -182,17 +183,18 @@ public class ServiceStateLogicTest extends BrooklynAppUnitTestSupport { // if the entity expects to be stopped, it will report stopped ServiceStateLogic.setExpectedState(entity, Lifecycle.STOPPED); assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED); - // and now so does the app - assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED); + // and the app will ignore the entity state, so becomes running + assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); + assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true); // if we clear the not-up indicator, both the entity and the app report service up (with the entity first) ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); - assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true); - assertAttributeEquals(entity, Attributes.SERVICE_UP, true); + assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); // but entity is still stopped because that is what is expected there, and that's okay even if service is apparently up - assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED); + assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED); // the app however is running, because the default state quorum check is "all are healthy" - assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); + assertAttributeEqualsContinually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); + assertAttributeEqualsContinually(app, Attributes.SERVICE_UP, true); // if we change the state quorum check for the app to be "all are healthy and at least one running" *then* it shows stopped // (normally this would be done in `initEnrichers` of course) http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java b/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java index 316c549..0aeaa86 100644 --- a/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java +++ b/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java @@ -20,6 +20,8 @@ package brooklyn.entity.rebind.persister; import static org.testng.Assert.assertEquals; +import java.util.Arrays; +import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -108,6 +110,19 @@ public class XmlMementoSerializerTest { } @Test + public void testArraysAsList() throws Exception { + // For some reason Arrays.asList used in the catalog's libraries can't be deserialized correctly, + // but here works perfectly - the generated catalog xml contains + // <libraries class="list"> + // <a ...> + // <bundle....> + // which is deserialized as an ArrayList with a single member array of bundles. + // The cause is the class="list" type which should be java.util.Arrays$ArrayList instead. + Collection<String> obj = Arrays.asList("a", "b"); + assertSerializeAndDeserialize(obj); + } + + @Test public void testImmutableList() throws Exception { List<String> obj = ImmutableList.of("123"); assertSerializeAndDeserialize(obj); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java b/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java index 817fdb1..99b095d 100644 --- a/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java +++ b/core/src/test/java/brooklyn/event/feed/http/HttpFeedTest.java @@ -300,24 +300,11 @@ public class HttpFeedTest extends BrooklynAppUnitTestSupport { } - @Test(groups="Integration") - /** marked as integration so it doesn't fail the plain build in environments - * with dodgy DNS (ie where "unresolvable_hostname_or_one_with_no_webserver_on_port_80" resolves as a host run by the provider) - * <p> - * (a surprising number of ISP's do this, - * happily serving adverts for your ISP, yielding "success" here, - * or timing out, giving null here) - * <p> - * if you want to make this test work, you can e.g. set it to loopback IP assuming you don't have any servers on port 80, - * with the following in /etc/hosts - * <p> - * 127.0.0.1 unresolvable_hostname_or_one_with_no_webserver_on_port_80 - // or some other IP which won't resolve - */ + @Test public void testPollsAndParsesHttpErrorResponseWild() throws Exception { feed = HttpFeed.builder() .entity(entity) - .baseUri("http://unresolvable_hostname_or_one_with_no_webserver_on_port_80") + .baseUri("http://0.0.0.0") .poll(HttpPollConfig.forSensor(SENSOR_STRING) .onSuccess(Functions.constant("success")) .onFailure(Functions.constant("failure")) http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/test/java/brooklyn/location/basic/SshMachineLocationIntegrationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/location/basic/SshMachineLocationIntegrationTest.java b/core/src/test/java/brooklyn/location/basic/SshMachineLocationIntegrationTest.java index 9c85e95..1c0e570 100644 --- a/core/src/test/java/brooklyn/location/basic/SshMachineLocationIntegrationTest.java +++ b/core/src/test/java/brooklyn/location/basic/SshMachineLocationIntegrationTest.java @@ -63,7 +63,14 @@ public class SshMachineLocationIntegrationTest { mgmt = null; } - // Note: requires `named:localhost-passphrase` set up with a key whose passphrase is "localhost" + // Note: requires `named:localhost-passphrase` set up with a key whose passphrase is "localhost" + // * create the key with: + // ssh-keygen -t rsa -N "brooklyn" -f ~/.ssh/id_rsa_passphrase + // ssh-copy-id localhost + // * create brooklyn.properties, containing: + // brooklyn.location.named.localhost-passphrase=localhost + // brooklyn.location.named.localhost-passphrase.privateKeyFile=~/.ssh/id_rsa_passphrase + // brooklyn.location.named.localhost-passphrase.privateKeyPassphrase=brooklyn @Test(groups = "Integration") public void testExtractingConnectablePassphraselessKey() throws Exception { LocalhostMachineProvisioningLocation lhp = (LocalhostMachineProvisioningLocation) mgmt.getLocationRegistry().resolve("named:localhost-passphrase", true, null).orNull(); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java b/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java index 774d54e..31d48f2 100644 --- a/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java +++ b/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java @@ -275,6 +275,8 @@ public class SshMachineLocationTest { // Note: on some (home/airport) networks, `ssh 123.123.123.123` hangs seemingly forever. // Make sure we fail, waiting for longer than the 70 second TCP timeout. + // + // Times out in 2m7s on Ubuntu Vivid (syn retries set to 6) @Test(groups = "Integration") public void testIsSshableWhenFalse() throws Exception { byte[] unreachableIp = new byte[] {123,123,123,123}; @@ -283,7 +285,7 @@ public class SshMachineLocationTest { public void run() { assertFalse(unreachableHost.isSshable()); }}, - Duration.TWO_MINUTES); + Duration.minutes(3)); } @Test http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/test/java/brooklyn/location/geo/HostGeoLookupIntegrationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/location/geo/HostGeoLookupIntegrationTest.java b/core/src/test/java/brooklyn/location/geo/HostGeoLookupIntegrationTest.java index 85acb6d..c362ab4 100644 --- a/core/src/test/java/brooklyn/location/geo/HostGeoLookupIntegrationTest.java +++ b/core/src/test/java/brooklyn/location/geo/HostGeoLookupIntegrationTest.java @@ -27,6 +27,7 @@ import org.testng.annotations.Test; import brooklyn.location.basic.LocalhostMachineProvisioningLocation; import brooklyn.location.basic.SshMachineLocation; +import brooklyn.util.time.Duration; import com.google.common.base.Objects; @@ -34,6 +35,7 @@ public class HostGeoLookupIntegrationTest { public static final Logger log = LoggerFactory.getLogger(HostGeoLookupIntegrationTest.class); + // Needs fast network connectivity to figure out the external IP. If response not returned in 2s fails. @Test(groups = "Integration") public void testLocalhostGetsLocation() throws Exception { LocalhostMachineProvisioningLocation ll = new LocalhostMachineProvisioningLocation(); @@ -58,7 +60,9 @@ public class HostGeoLookupIntegrationTest { @Test(groups = "Integration") public void testUtraceLookup() throws Exception { - HostGeoInfo geo = new UtraceHostGeoLookup().getHostGeoInfo(InetAddress.getByName("utrace.de")); + // The test times out in a VM - VirtualBox + Ubuntu Vivid, possibly due to proxy usage? + // Increase the timeout so we can actually test it's working correctly, regardless of test environment. + HostGeoInfo geo = new UtraceHostGeoLookup().getHostGeoInfo(InetAddress.getByName("utrace.de"), Duration.THIRTY_SECONDS); Assert.assertNotNull(geo, "host lookup unavailable - maybe network not available "); Assert.assertTrue(geo.displayName.contains("(DE)")); Assert.assertEquals(geo.latitude, 51, 2); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/test/java/brooklyn/util/internal/ssh/sshj/SshjToolAsyncStubIntegrationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/util/internal/ssh/sshj/SshjToolAsyncStubIntegrationTest.java b/core/src/test/java/brooklyn/util/internal/ssh/sshj/SshjToolAsyncStubIntegrationTest.java index caebac1..9d468a6 100644 --- a/core/src/test/java/brooklyn/util/internal/ssh/sshj/SshjToolAsyncStubIntegrationTest.java +++ b/core/src/test/java/brooklyn/util/internal/ssh/sshj/SshjToolAsyncStubIntegrationTest.java @@ -117,7 +117,7 @@ public class SshjToolAsyncStubIntegrationTest { @Test(groups="Integration") public void testPolls() throws Exception { sequence = ImmutableList.of( - new InjectedResult(containsCmd("& disown"), returning(0, "", "")), + new InjectedResult(containsCmd("nohup"), returning(0, "", "")), new InjectedResult(containsCmd("# Long poll"), returning(0, "mystringToStdout", "mystringToStderr"))); runTest(0, "mystringToStdout", "mystringToStderr"); @@ -127,7 +127,7 @@ public class SshjToolAsyncStubIntegrationTest { @Test(groups="Integration") public void testPollsAndReturnsNonZeroExitCode() throws Exception { sequence = ImmutableList.of( - new InjectedResult(containsCmd("& disown"), returning(0, "", "")), + new InjectedResult(containsCmd("nohup"), returning(0, "", "")), new InjectedResult(containsCmd("# Long poll"), returning(123, "mystringToStdout", "mystringToStderr")), new InjectedResult(containsCmd("# Retrieve status"), returning(0, "123", ""))); @@ -138,7 +138,7 @@ public class SshjToolAsyncStubIntegrationTest { @Test(groups="Integration") public void testPollsRepeatedly() throws Exception { sequence = ImmutableList.of( - new InjectedResult(containsCmd("& disown"), returning(0, "", "")), + new InjectedResult(containsCmd("nohup"), returning(0, "", "")), new InjectedResult(containsCmd("# Long poll"), returning(125, "mystringToStdout", "mystringToStderr")), new InjectedResult(containsCmd("# Retrieve status"), returning(0, "", "")), new InjectedResult(containsCmd("# Long poll"), returning(125, "mystringToStdout2", "mystringToStderr2")), http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fae666cf/core/src/test/java/brooklyn/util/internal/ssh/sshj/SshjToolIntegrationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/util/internal/ssh/sshj/SshjToolIntegrationTest.java b/core/src/test/java/brooklyn/util/internal/ssh/sshj/SshjToolIntegrationTest.java index c809ad1..de3f58e 100644 --- a/core/src/test/java/brooklyn/util/internal/ssh/sshj/SshjToolIntegrationTest.java +++ b/core/src/test/java/brooklyn/util/internal/ssh/sshj/SshjToolIntegrationTest.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; import net.schmizz.sshj.connection.channel.direct.Session; @@ -236,18 +237,24 @@ public class SshjToolIntegrationTest extends SshToolAbstractIntegrationTest { @Test(groups = {"Integration"}) public void testAsyncExecAbortsIfProcessFails() throws Exception { + final AtomicReference<Throwable> error = new AtomicReference<Throwable>(); Thread thread = new Thread(new Runnable() { + @Override public void run() { - Stopwatch stopwatch = Stopwatch.createStarted(); - int exitStatus = tool.execScript( - ImmutableMap.of(SshjTool.PROP_EXEC_ASYNC.getName(), true, SshjTool.PROP_EXEC_TIMEOUT.getName(), Duration.millis(1)), - ImmutableList.of("sleep 63"), - ImmutableMap.<String,String>of()); - - assertEquals(exitStatus, 1); - - long seconds = stopwatch.elapsed(TimeUnit.SECONDS); - assertTrue(seconds < 30, "exec took "+seconds+" seconds"); + try { + Stopwatch stopwatch = Stopwatch.createStarted(); + int exitStatus = tool.execScript( + ImmutableMap.of(SshjTool.PROP_EXEC_ASYNC.getName(), true, SshjTool.PROP_EXEC_TIMEOUT.getName(), Duration.millis(1)), + ImmutableList.of("sleep 63"), + ImmutableMap.<String,String>of()); + + assertEquals(exitStatus, 143 /* 128 + Signal number (SIGTERM) */); + + long seconds = stopwatch.elapsed(TimeUnit.SECONDS); + assertTrue(seconds < 30, "exec took "+seconds+" seconds"); + } catch (Throwable t) { + error.set(t); + } }}); boolean origFeatureEnablement = BrooklynFeatureEnablement.enable(BrooklynFeatureEnablement.FEATURE_SSH_ASYNC_EXEC); @@ -255,6 +262,7 @@ public class SshjToolIntegrationTest extends SshToolAbstractIntegrationTest { thread.start(); Asserts.succeedsEventually(new Runnable() { + @Override public void run() { int exitStatus = tool.execCommands(ImmutableMap.<String,Object>of(), ImmutableList.of("ps aux| grep \"sleep 63\" | grep -v grep")); assertEquals(exitStatus, 0); @@ -264,6 +272,9 @@ public class SshjToolIntegrationTest extends SshToolAbstractIntegrationTest { thread.join(30*1000); assertFalse(thread.isAlive()); + if (error.get() != null) { + throw Exceptions.propagate(error.get()); + } } finally { thread.interrupt(); BrooklynFeatureEnablement.setEnablement(BrooklynFeatureEnablement.FEATURE_SSH_ASYNC_EXEC, origFeatureEnablement);
