You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/01/25 02:02:12 UTC
[1/5] incubator-brooklyn git commit: group software process tasks
better
Repository: incubator-brooklyn
Updated Branches:
refs/heads/master 80f7f6216 -> b50e17645
group software process tasks better
causes a much nicer tree to display, rather than lots of steps.
most are no-op and i think this structure makes it better to navigate.
unfortunately it is hard to tell if a step is no-op, as they are methods,
so we don't have a way just to not run empty steps.
it would be better to do away with most of them, finding a different mechanism
for subclasses to insert at the right point, but this helps in the short term.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/39e2a4e4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/39e2a4e4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/39e2a4e4
Branch: refs/heads/master
Commit: 39e2a4e4a81138e22d35d026cdcd6307fba67eb8
Parents: b28ba02
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Jan 21 14:10:09 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Jan 21 14:16:37 2016 +0000
----------------------------------------------------------------------
.../base/AbstractSoftwareProcessDriver.java | 99 +++++++++++---------
1 file changed, 53 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/39e2a4e4/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java
index d243833..4ffeb1a 100644
--- a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java
+++ b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java
@@ -107,40 +107,43 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr
skipStart = entityStarted.or(false);
}
if (!skipStart) {
- Optional<Boolean> locationInstalled = Optional.fromNullable(getLocation().getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION));
- Optional<Boolean> entityInstalled = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION));
- boolean skipInstall = locationInstalled.or(entityInstalled).or(false);
- if (!skipInstall) {
- DynamicTasks.queue("copy-pre-install-resources", new Runnable() { public void run() {
- waitForConfigKey(BrooklynConfigKeys.PRE_INSTALL_RESOURCES_LATCH);
- copyPreInstallResources();
- }});
-
- DynamicTasks.queue("pre-install", new Runnable() { public void run() {
- preInstall();
- }});
-
- DynamicTasks.queue("pre-install-command", new Runnable() { public void run() {
- runPreInstallCommand();
- }});
- DynamicTasks.queue("setup", new Runnable() { public void run() {
- waitForConfigKey(BrooklynConfigKeys.SETUP_LATCH);
- setup();
- }});
-
- DynamicTasks.queue("copy-install-resources", new Runnable() { public void run() {
- waitForConfigKey(BrooklynConfigKeys.INSTALL_RESOURCES_LATCH);
- copyInstallResources();
- }});
+ DynamicTasks.queue("install", new Runnable() { public void run() {
+
+ Optional<Boolean> locationInstalled = Optional.fromNullable(getLocation().getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION));
+ Optional<Boolean> entityInstalled = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION));
+ boolean skipInstall = locationInstalled.or(entityInstalled).or(false);
+ if (!skipInstall) {
+ DynamicTasks.queue("copy-pre-install-resources", new Runnable() { public void run() {
+ waitForConfigKey(BrooklynConfigKeys.PRE_INSTALL_RESOURCES_LATCH);
+ copyPreInstallResources();
+ }});
+
+ DynamicTasks.queue("pre-install", new Runnable() { public void run() {
+ preInstall();
+ }});
+
+ DynamicTasks.queue("pre-install-command", new Runnable() { public void run() {
+ runPreInstallCommand();
+ }});
+ DynamicTasks.queue("setup", new Runnable() { public void run() {
+ waitForConfigKey(BrooklynConfigKeys.SETUP_LATCH);
+ setup();
+ }});
+
+ DynamicTasks.queue("copy-install-resources", new Runnable() { public void run() {
+ waitForConfigKey(BrooklynConfigKeys.INSTALL_RESOURCES_LATCH);
+ copyInstallResources();
+ }});
+
+ DynamicTasks.queue("install (main)", new Runnable() { public void run() {
+ waitForConfigKey(BrooklynConfigKeys.INSTALL_LATCH);
+ install();
+ }});
+ }
- DynamicTasks.queue("install", new Runnable() { public void run() {
- waitForConfigKey(BrooklynConfigKeys.INSTALL_LATCH);
- install();
+ DynamicTasks.queue("post-install-command", new Runnable() { public void run() {
+ runPostInstallCommand();
}});
- }
-
- DynamicTasks.queue("post-install-command", new Runnable() { public void run() {
- runPostInstallCommand();
}});
DynamicTasks.queue("customize", new Runnable() { public void run() {
@@ -148,22 +151,24 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr
customize();
}});
- DynamicTasks.queue("copy-runtime-resources", new Runnable() { public void run() {
- waitForConfigKey(BrooklynConfigKeys.RUNTIME_RESOURCES_LATCH);
- copyRuntimeResources();
- }});
+ DynamicTasks.queue("launch", new Runnable() { public void run() {
+ DynamicTasks.queue("copy-runtime-resources", new Runnable() { public void run() {
+ waitForConfigKey(BrooklynConfigKeys.RUNTIME_RESOURCES_LATCH);
+ copyRuntimeResources();
+ }});
- DynamicTasks.queue("pre-launch-command", new Runnable() { public void run() {
- runPreLaunchCommand();
- }});
+ DynamicTasks.queue("pre-launch-command", new Runnable() { public void run() {
+ runPreLaunchCommand();
+ }});
- DynamicTasks.queue("launch", new Runnable() { public void run() {
- waitForConfigKey(BrooklynConfigKeys.LAUNCH_LATCH);
- launch();
- }});
+ DynamicTasks.queue("launch (main)", new Runnable() { public void run() {
+ waitForConfigKey(BrooklynConfigKeys.LAUNCH_LATCH);
+ launch();
+ }});
- DynamicTasks.queue("post-launch-command", new Runnable() { public void run() {
- runPostLaunchCommand();
+ DynamicTasks.queue("post-launch-command", new Runnable() { public void run() {
+ runPostLaunchCommand();
+ }});
}});
}
@@ -187,6 +192,7 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr
public abstract void customize();
public abstract void runPreLaunchCommand();
public abstract void launch();
+ /** Only run if launch is run (if start is not skipped). */
public abstract void runPostLaunchCommand();
@Override
@@ -195,7 +201,8 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr
}
/**
- * Implement this method in child classes to add some post-launch behavior
+ * Implement this method in child classes to add some post-launch behavior.
+ * This is run even if start is skipped and launch is not run.
*/
public void postLaunch() {}
[3/5] incubator-brooklyn git commit: also improve jmx port allocation
in tests
Posted by he...@apache.org.
also improve jmx port allocation in tests
to fix another observed test failure,
at https://builds.apache.org/job/incubator-brooklyn-pull-requests/org.apache.brooklyn$brooklyn-software-base/2439/testReport/junit/org.apache.brooklyn.feed.jmx/JmxFeedTest/setUp/
Port already in use: 40125; nested exception is:
java.net.BindException: Address already in use
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/e77f62a0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/e77f62a0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/e77f62a0
Branch: refs/heads/master
Commit: e77f62a09cc0b256387e564862682d11c809861f
Parents: cfd54d5
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Jan 22 11:46:50 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Jan 22 11:46:50 2016 +0000
----------------------------------------------------------------------
.../entity/software/base/test/jmx/JmxService.java | 10 +++++++---
.../java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java | 9 ++++++++-
.../org/apache/brooklyn/test/NetworkingTestUtils.java | 12 +++++++++++-
.../java/org/apache/brooklyn/util/net/Networking.java | 5 ++---
4 files changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e77f62a0/brooklyn-server/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/jmx/JmxService.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/jmx/JmxService.java b/brooklyn-server/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/jmx/JmxService.java
index 2e23789..397aff3 100644
--- a/brooklyn-server/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/jmx/JmxService.java
+++ b/brooklyn-server/software/base/src/test/java/org/apache/brooklyn/entity/software/base/test/jmx/JmxService.java
@@ -21,7 +21,6 @@ package org.apache.brooklyn.entity.software.base.test.jmx;
import java.io.IOException;
import java.util.List;
import java.util.Map;
-import java.util.Random;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanNotificationInfo;
@@ -47,6 +46,7 @@ import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.core.entity.Attributes;
import org.apache.brooklyn.entity.java.UsesJmx;
import org.apache.brooklyn.feed.jmx.JmxHelper;
+import org.apache.brooklyn.test.NetworkingTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -68,8 +68,10 @@ public class JmxService {
private String url;
public JmxService() throws Exception {
- this("localhost", 28000 + (int)Math.floor(new Random().nextDouble() * 1000));
- logger.warn("use of deprecated default host and port in JmxService");
+ this("localhost", NetworkingTestUtils.randomPortAround(28000));
+
+ // TODO why this message if the constructor is not actually deprecated, and it seems useful?
+ //logger.warn("use of deprecated default host and port in JmxService");
}
/**
@@ -151,10 +153,12 @@ public class JmxService {
* @throws MBeanRegistrationException
* @throws InstanceAlreadyExistsException
*/
+ @SuppressWarnings({ "rawtypes" })
public GeneralisedDynamicMBean registerMBean(Map initialAttributes, String name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException, NullPointerException {
return registerMBean(initialAttributes, ImmutableMap.of(), name);
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public GeneralisedDynamicMBean registerMBean(Map initialAttributes, Map operations, String name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException, NullPointerException {
GeneralisedDynamicMBean mbean = new GeneralisedDynamicMBean(initialAttributes, operations);
server.registerMBean(mbean, new ObjectName(name));
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e77f62a0/brooklyn-server/software/base/src/test/java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/software/base/src/test/java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java b/brooklyn-server/software/base/src/test/java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java
index a90d657..d8df35b 100644
--- a/brooklyn-server/software/base/src/test/java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java
+++ b/brooklyn-server/software/base/src/test/java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java
@@ -65,6 +65,7 @@ import org.apache.brooklyn.entity.software.base.test.jmx.GeneralisedDynamicMBean
import org.apache.brooklyn.entity.software.base.test.jmx.JmxService;
import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.test.NetworkingTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
@@ -114,7 +115,13 @@ public class JmxFeedTest {
@Override public void init() {
sensors().set(Attributes.HOSTNAME, "localhost");
sensors().set(UsesJmx.JMX_PORT,
- LocalhostMachineProvisioningLocation.obtainPort(PortRanges.fromString("40123+")));
+ LocalhostMachineProvisioningLocation.obtainPort(PortRanges.fromString(
+ // just doing "40123+" was not enough to avoid collisions (on 40125),
+ // observed on jenkins, not sure why but
+ // maybe something else had a UDP connection we weren't detected,
+ // or the static lock our localhost uses was being bypassed;
+ // this should improve things (2016-01)
+ NetworkingTestUtils.randomPortAround(40000)+"+")));
// only supports no-agent, at the moment
config().set(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.NONE);
sensors().set(UsesJmx.RMI_REGISTRY_PORT, -1); // -1 means to use the JMX_PORT only
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e77f62a0/brooklyn-server/test-support/src/main/java/org/apache/brooklyn/test/NetworkingTestUtils.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/test-support/src/main/java/org/apache/brooklyn/test/NetworkingTestUtils.java b/brooklyn-server/test-support/src/main/java/org/apache/brooklyn/test/NetworkingTestUtils.java
index 7b48eaf..3cb4ba9 100644
--- a/brooklyn-server/test-support/src/main/java/org/apache/brooklyn/test/NetworkingTestUtils.java
+++ b/brooklyn-server/test-support/src/main/java/org/apache/brooklyn/test/NetworkingTestUtils.java
@@ -22,13 +22,13 @@ import static org.testng.Assert.assertTrue;
import java.util.Map;
-import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.net.Networking;
import org.apache.brooklyn.util.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableMap;
public class NetworkingTestUtils {
@@ -65,4 +65,14 @@ public class NetworkingTestUtils {
assertTrue(Networking.isPortAvailable(entry.getValue()), errmsg);
}
}
+
+ /** Returns a port not in use somewhere around the seed;
+ * this is not a foolproof way to prevent collisions,
+ * but strikes a good balance of traceability (different callers will use different ranges)
+ * and collision avoidance, esp when combined with <code>Localhost...obtain(thisResult+"+");</code>.
+ */
+ @Beta
+ public static int randomPortAround(int seed) {
+ return Networking.nextAvailablePort( seed + (int)Math.floor(Math.random() * 1000) );
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e77f62a0/brooklyn-server/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java b/brooklyn-server/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java
index fb988c7..85c87a0 100644
--- a/brooklyn-server/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java
+++ b/brooklyn-server/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java
@@ -18,6 +18,8 @@
*/
package org.apache.brooklyn.util.net;
+import static com.google.common.base.Preconditions.checkArgument;
+
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;
@@ -26,7 +28,6 @@ import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
-import java.net.URI;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Enumeration;
@@ -48,8 +49,6 @@ import com.google.common.base.Throwables;
import com.google.common.net.HostAndPort;
import com.google.common.primitives.UnsignedBytes;
-import static com.google.common.base.Preconditions.checkArgument;
-
public class Networking {
private static final Logger log = LoggerFactory.getLogger(Networking.class);
[2/5] incubator-brooklyn git commit: fix race in DSTTest.testCancel
Posted by he...@apache.org.
fix race in DSTTest.testCancel
seeing errors on jenkins server though it runs fine locally;
have patched what looks like one race, but not sure it explains the failure
at https://builds.apache.org/job/incubator-brooklyn-pull-requests/org.apache.brooklyn$brooklyn-core/2440/testReport/junit/org.apache.brooklyn.util.core.task/DynamicSequentialTaskTest/testCancelled/
where we are seeing an extra semaphore at the end of the test;
have added comments and logging in case it is seen again.
(locally all is well.)
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/cfd54d5b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/cfd54d5b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/cfd54d5b
Branch: refs/heads/master
Commit: cfd54d5bc5201f0d8d8cde29ac6893f5a6090947
Parents: b28ba02
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Jan 22 09:41:00 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Jan 22 11:30:38 2016 +0000
----------------------------------------------------------------------
.../util/core/task/BasicExecutionManager.java | 11 ++++-
.../brooklyn/util/core/task/BasicTask.java | 2 +-
.../core/task/DynamicSequentialTaskTest.java | 45 ++++++++++++++------
3 files changed, 43 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfd54d5b/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
index 0aab7d5..c75ad0b 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
@@ -67,7 +67,6 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.CaseFormat;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ExecutionList;
@@ -565,7 +564,15 @@ public class BasicExecutionManager implements ExecutionManager {
int subtasksReallyCancelled=0;
if (task instanceof HasTaskChildren) {
- for (Task<?> child: ((HasTaskChildren)task).getChildren()) {
+ // cancel tasks in reverse order --
+ // it should be the case that if child1 is cancelled,
+ // a parentTask should NOT call a subsequent child2,
+ // but just in case, we cancel child2 first
+ // NB: DST and others may apply their own recursive cancel behaviour
+ MutableList<Task<?>> childrenReversed = MutableList.copyOf( ((HasTaskChildren)task).getChildren() );
+ Collections.reverse(childrenReversed);
+
+ for (Task<?> child: childrenReversed) {
if (log.isTraceEnabled()) {
log.trace("Cancelling "+child+" on recursive cancellation of "+task);
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfd54d5b/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicTask.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicTask.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicTask.java
index 7c29bba..efd3001 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicTask.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/task/BasicTask.java
@@ -298,7 +298,7 @@ public class BasicTask<T> implements TaskInternal<T> {
public synchronized boolean cancel(TaskCancellationMode mode) {
if (isDone()) return false;
if (log.isTraceEnabled()) {
- log.trace("BT cancelling "+this+" mode "+mode);
+ log.trace("BT cancelling "+this+" mode "+mode+", from thread "+Thread.currentThread());
}
cancelled = true;
doCancel(mode);
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfd54d5b/brooklyn-server/core/src/test/java/org/apache/brooklyn/util/core/task/DynamicSequentialTaskTest.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/test/java/org/apache/brooklyn/util/core/task/DynamicSequentialTaskTest.java b/brooklyn-server/core/src/test/java/org/apache/brooklyn/util/core/task/DynamicSequentialTaskTest.java
index 364870a..763c067 100644
--- a/brooklyn-server/core/src/test/java/org/apache/brooklyn/util/core/task/DynamicSequentialTaskTest.java
+++ b/brooklyn-server/core/src/test/java/org/apache/brooklyn/util/core/task/DynamicSequentialTaskTest.java
@@ -139,6 +139,7 @@ public class DynamicSequentialTaskTest {
Thread.sleep(duration.toMillisecondsRoundingUp());
}
} catch (InterruptedException e) {
+ log.info("releasing semaphore on interruption after saying "+message);
cancellations.release();
throw Exceptions.propagate(e);
}
@@ -159,7 +160,8 @@ public class DynamicSequentialTaskTest {
}
public Task<String> sayTask(String message, Duration duration, String message2) {
- return Tasks.<String>builder().displayName("say:"+message).body(sayCallable(message, duration, message2)).build();
+ return Tasks.<String>builder().displayName("say:"+message+(duration!=null ? ":wait("+duration+")" : "")+(message2!=null ? ":"+message2 : ""))
+ .body(sayCallable(message, duration, message2)).build();
}
public <T> Task<T> submitting(final Task<T> task) {
@@ -193,33 +195,52 @@ public class DynamicSequentialTaskTest {
sayTask("2a", Duration.THIRTY_SECONDS, "2b"),
sayTask("3"));
ec.submit(t);
-
+
+ // wait for 2 to start, saying "2a", and the first interruptible block is when it waits for its 30s
waitForMessages(Predicates.compose(MathPredicates.greaterThanOrEqual(2), CollectionFunctionals.sizeFunction()), TIMEOUT);
Assert.assertEquals(messages, Arrays.asList("1", "2a"));
- Time.sleep(Duration.millis(50));
+
+ // now cancel, and make sure we get the right behaviour
t.cancel(true);
Assert.assertTrue(t.isDone());
- // 2 should get cancelled, and invoke the cancellation semaphore
+ // 2 should get cancelled, and invoke the cancellation semaphore, but not say 2b
// 3 should get cancelled and not run at all
- Assert.assertEquals(messages, Arrays.asList("1", "2a"));
- // Need to ensure that 2 has been started; race where we might cancel it before its run method
- // is even begun. Hence doing "2a; pause; 2b" where nothing is interruptable before pause.
+ // cancel(..) currently cancels everything in the tree in the calling thread
+ // so we could even assert task3.isCancelled() now
+ // but not sure we will guarantee that for subtasks, so weaker assertion
+ // that it is eventually cancelled, and that it for sure never starts
+
+ // message list is still 1, 2a
+ Assert.assertEquals(messages, Arrays.asList("1", "2a"));
+ // And 2 when cancelled should release the semaphore
+ log.info("testCancelled waiting on semaphore; permits left is "+cancellations.availablePermits());
Assert.assertTrue(cancellations.tryAcquire(10, TimeUnit.SECONDS));
+ log.info("testCancelled acquired semaphore; permits left is "+cancellations.availablePermits());
Iterator<Task<?>> ci = ((HasTaskChildren)t).getChildren().iterator();
+ // 1 completed fine
Assert.assertEquals(ci.next().get(), "1");
+ // 2 is cancelled -- cancelled flag should always be set *before* the interrupt sent
+ // (and that released the semaphore above, even if thread is not completed, so this should be set)
Task<?> task2 = ci.next();
Assert.assertTrue(task2.isBegun());
Assert.assertTrue(task2.isDone());
Assert.assertTrue(task2.isCancelled());
-
+
Task<?> task3 = ci.next();
+ // 3 is being cancelled in the thread which cancelled 2, and should either be
+ // *before* 2 was cancelled or *not run* because the parent was cancelled
+ // so we shouldn't need to wait ... but if we did:
+// Asserts.eventually(Suppliers.ofInstance(task3), TaskPredicates.isDone());
+ Assert.assertTrue(task3.isDone());
+ Assert.assertTrue(task3.isCancelled());
Assert.assertFalse(task3.isBegun());
- Assert.assertTrue(task2.isDone());
- Assert.assertTrue(task2.isCancelled());
-
- // but we do _not_ get a mutex from task3 as it does not run (is not interrupted)
+ // messages unchanged
+ Assert.assertEquals(messages, Arrays.asList("1", "2a"));
+ // no further mutexes should be available (ie 3 should not run)
+ // TODO for some reason this was observed to fail on the jenkins box (2016-01)
+ // but i can't see why; have added logging in case it happens again
Assert.assertEquals(cancellations.availablePermits(), 0);
}
[4/5] incubator-brooklyn git commit: This closes #1171
Posted by he...@apache.org.
This closes #1171
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ac0636cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ac0636cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ac0636cd
Branch: refs/heads/master
Commit: ac0636cdfa3a8f21fcc2cbaed3fc82c216dff258
Parents: 80f7f62 e77f62a
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Jan 25 01:01:38 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Jan 25 01:01:38 2016 +0000
----------------------------------------------------------------------
.../util/core/task/BasicExecutionManager.java | 11 ++++-
.../brooklyn/util/core/task/BasicTask.java | 2 +-
.../core/task/DynamicSequentialTaskTest.java | 45 ++++++++++++++------
.../software/base/test/jmx/JmxService.java | 10 +++--
.../apache/brooklyn/feed/jmx/JmxFeedTest.java | 9 +++-
.../brooklyn/test/NetworkingTestUtils.java | 12 +++++-
.../apache/brooklyn/util/net/Networking.java | 5 +--
7 files changed, 71 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
[5/5] incubator-brooklyn git commit: This closes #1167
Posted by he...@apache.org.
This closes #1167
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/b50e1764
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/b50e1764
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/b50e1764
Branch: refs/heads/master
Commit: b50e17645d404b09b254a754c41d90462586a307
Parents: ac0636c 39e2a4e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Jan 25 01:02:01 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Jan 25 01:02:01 2016 +0000
----------------------------------------------------------------------
.../base/AbstractSoftwareProcessDriver.java | 99 +++++++++++---------
1 file changed, 53 insertions(+), 46 deletions(-)
----------------------------------------------------------------------