Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/464#discussion_r89767565
--- Diff:
core/src/test/java/org/apache/brooklyn/core/mgmt/internal/EntityExecutionManagerTest.java
---
@@ -82,18 +83,33 @@ public void testOnDoneCallback() throws
InterruptedException {
@Override
public void onTaskDone(Task<?> task) {
Assert.assertTrue(task.isDone());
- Assert.assertEquals(task.getUnchecked(), "foo");
- completedTasks.put(task,
Duration.sinceUtc(task.getEndTimeUtc()));
- sema4.release();
+ Object result = task.getUnchecked();
+ if(result != null && result.equals("foo")) {
+ synchronized (completedTasks) {
+ completedTasks.put(task,
Duration.sinceUtc(task.getEndTimeUtc()));
+ }
+ sema4.release();
+ }
}
});
- Task<String> t1 = em.submit(
Tasks.<String>builder().displayName("t1").dynamic(false).body(Callables.returning("foo")).build()
);
- t1.getUnchecked();
- Task<String> t2 = em.submit(
Tasks.<String>builder().displayName("t2").dynamic(false).body(Callables.returning("foo")).build()
);
+ Task<String> t1 = em.submit(
+ Tasks.<String>builder()
+ .displayName("t1")
+ .dynamic(false)
+ .body(Callables.returning("foo"))
+ .build());
+ Task<String> t2 = em.submit(
+ Tasks.<String>builder()
+ .displayName("t2")
+ .dynamic(false)
+ .body(Callables.returning("foo"))
+ .build());
sema4.acquire();
--- End diff --
I much prefer:
```
boolean acquired =
sema4.tryAcquire(Asserts.DEFAULT_LONG_TIMEOUT.toMilliseconds(),
TimeUnit.MILLISECONDS);
assertTrue(acquired);
```
The current code will hang the build if someone changes something that
breaks the test.
Also (for future reference - not worth changing here unless you really want
to) a `CountDownLatch` is a more appropriate mechanism in this case - doing
`new CountDownLatch(2)` is much simpler/clearer in its intent, compared to `new
Semaphore(-1)`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---