[
https://issues.apache.org/jira/browse/BROOKLYN-446?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15964103#comment-15964103
]
ASF GitHub Bot commented on BROOKLYN-446:
-----------------------------------------
GitHub user aledsage opened a pull request:
https://github.com/apache/brooklyn-server/pull/627
BROOKLYN-446: deprecate broken ScheduledTask constructors
See https://issues.apache.org/jira/browse/BROOKLYN-446
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/aledsage/brooklyn-server BROOKLYN-446
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/brooklyn-server/pull/627.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #627
----
commit a3520eb82a5737989a3927fd7b22627088810e8d
Author: Aled Sage <[email protected]>
Date: 2017-04-11T09:55:41Z
BROOKLYN-446: deprecate broken ScheduledTask constructors
----
> Constructor ScheduledTask(Map, Task) is broken
> ----------------------------------------------
>
> Key: BROOKLYN-446
> URL: https://issues.apache.org/jira/browse/BROOKLYN-446
> Project: Brooklyn
> Issue Type: Bug
> Affects Versions: 0.10.0
> Reporter: Svetoslav Neykov
>
> The resulting task is executed only once, not rescheduled.
> A test case to show the behaviour:
> {noformat}
> import static org.testng.Assert.assertTrue;
> import java.util.Map;
> import java.util.concurrent.atomic.AtomicInteger;
> import org.apache.brooklyn.api.mgmt.Task;
> import org.apache.brooklyn.core.test.BrooklynMgmtUnitTestSupport;
> import org.apache.brooklyn.test.Asserts;
> import org.apache.brooklyn.util.collections.MutableMap;
> import org.apache.brooklyn.util.time.Duration;
> import org.testng.annotations.Test;
> import com.google.common.collect.ImmutableMap;
> import com.google.common.util.concurrent.Runnables;
> public class ScheduledTaskTest extends BrooklynMgmtUnitTestSupport {
> /**
> * Fails with:
> * java.lang.UnsupportedOperationException
> * at
> com.google.common.collect.ImmutableMap.remove(ImmutableMap.java:338)
> * at
> org.apache.brooklyn.util.core.task.BasicTask.<init>(BasicTask.java:115)
> * at
> org.apache.brooklyn.util.core.task.BasicTask.<init>(BasicTask.java:107)
> * at
> org.apache.brooklyn.util.core.task.ScheduledTask.<init>(ScheduledTask.java:96)
> * at
> org.apache.brooklyn.util.core.task.ScheduledTask.<init>(ScheduledTask.java:88)
> * at
> org.apache.brooklyn.util.core.task.ScheduledTaskTest.testImmutableFlags(ScheduledTaskTest.java:43)
> */
> @Test
> public void testImmutableFlags() {
> Map<?, ?> flags = ImmutableMap.of(
> "period", Duration.ONE_SECOND,
> "delay", Duration.ONE_SECOND);
> Task<?> task = new BasicTask<>(Runnables.doNothing());
> new ScheduledTask(flags, task);
> }
> /**
> * Fails with:
> * java.lang.AssertionError: failed succeeds-eventually, 69 attempts,
> 30005ms elapsed: AssertionError: expected [true] but found [false]
> * at
> org.apache.brooklyn.test.Asserts.succeedsEventually(Asserts.java:1008)
> * at
> org.apache.brooklyn.test.Asserts.succeedsEventually(Asserts.java:895)
> * at
> org.apache.brooklyn.test.Asserts.succeedsEventually(Asserts.java:888)
> * at
> org.apache.brooklyn.util.core.task.ScheduledTaskTest.testTaskConstructor(ScheduledTaskTest.java:60)
> */
> @Test
> public void testTaskConstructor() {
> final AtomicInteger cnt = new AtomicInteger();
> Map<?, ?> flags = MutableMap.of(
> "period", Duration.ONE_SECOND,
> "delay", Duration.ONE_SECOND);
> Task<?> task = new BasicTask<>(new Runnable() {
> @Override
> public void run() {
> cnt.incrementAndGet();
> }
> });
> ScheduledTask scheduledTask = new ScheduledTask(flags, task);
> mgmt.getExecutionManager().submit(scheduledTask);
> Asserts.succeedsEventually(new Runnable() {
> @Override
> public void run() {
> assertTrue(cnt.get() > 1);
> }
> });
> }
> }
> {noformat}
> The problem is that the task gets reused and on the second schedule attempt
> it already has a future assigned so is not scheduled any more.
> The best solution seems to be to remove the constructor altogether.
> Optionally providing a Runnable/Callable job constructor, wrapping the job in
> a factory, returning a new task on each submission.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)