1 |
|
/* |
2 |
< |
* Written by members of JCP JSR-166 Expert Group and released to the |
3 |
< |
* public domain. Use, modify, and redistribute this code in any way |
4 |
< |
* without acknowledgement. Other contributors include Andrew Wright, |
5 |
< |
* Jeffrey Hayes, Pat Fischer, Mike Judd. |
2 |
> |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
> |
* Expert Group and released to the public domain, as explained at |
4 |
> |
* http://creativecommons.org/licenses/publicdomain |
5 |
> |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
> |
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
24 |
|
*/ |
25 |
|
static class PublicFutureTask extends FutureTask { |
26 |
|
public PublicFutureTask(Callable r) { super(r); } |
27 |
< |
public boolean reset() { return super.reset(); } |
27 |
< |
public void setCancelled() { super.setCancelled(); } |
27 |
> |
public boolean runAndReset() { return super.runAndReset(); } |
28 |
|
public void set(Object x) { super.set(x); } |
29 |
|
public void setException(Throwable t) { super.setException(t); } |
30 |
|
} |
64 |
|
} |
65 |
|
|
66 |
|
/** |
67 |
< |
* reset of a done task succeeds and changes status to not done |
67 |
> |
* runAndReset of a non-cancelled task succeeds |
68 |
|
*/ |
69 |
< |
public void testReset() { |
69 |
> |
public void testRunAndReset() { |
70 |
|
PublicFutureTask task = new PublicFutureTask(new NoOpCallable()); |
71 |
< |
task.run(); |
72 |
< |
assertTrue(task.isDone()); |
73 |
< |
assertTrue(task.reset()); |
71 |
> |
assertTrue(task.runAndReset()); |
72 |
|
assertFalse(task.isDone()); |
73 |
|
} |
74 |
|
|
75 |
|
/** |
76 |
< |
* Resetting after cancellation fails |
76 |
> |
* runAndReset after cancellation fails |
77 |
|
*/ |
78 |
|
public void testResetAfterCancel() { |
79 |
|
PublicFutureTask task = new PublicFutureTask(new NoOpCallable()); |
80 |
|
assertTrue(task.cancel(false)); |
81 |
< |
task.run(); |
81 |
> |
assertFalse(task.runAndReset()); |
82 |
|
assertTrue(task.isDone()); |
83 |
|
assertTrue(task.isCancelled()); |
86 |
– |
assertFalse(task.reset()); |
84 |
|
} |
85 |
|
|
86 |
|
|
90 |
– |
/** |
91 |
– |
* setCancelled of a new task causes isCancelled to be true |
92 |
– |
*/ |
93 |
– |
public void testSetCancelled() { |
94 |
– |
PublicFutureTask task = new PublicFutureTask(new NoOpCallable()); |
95 |
– |
assertTrue(task.cancel(false)); |
96 |
– |
task.setCancelled(); |
97 |
– |
assertTrue(task.isDone()); |
98 |
– |
assertTrue(task.isCancelled()); |
99 |
– |
} |
87 |
|
|
88 |
|
/** |
89 |
|
* setting value gauses get to return it |