837 |
|
} |
838 |
|
|
839 |
|
/** |
840 |
< |
* poll and take should decrement the waiting consumer count |
840 |
> |
* poll and take decrement the waiting consumer count |
841 |
|
*/ |
842 |
|
public void testWaitingConsumer() throws InterruptedException { |
843 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
869 |
|
} |
870 |
|
|
871 |
|
/** |
872 |
< |
* transfer attempts to insert into the queue then wait until that |
873 |
< |
* object is removed via take or poll. |
872 |
> |
* transfer waits until a poll occurs. The transfered element |
873 |
> |
* is returned by this associated poll. |
874 |
|
*/ |
875 |
|
public void testTransfer2() throws InterruptedException { |
876 |
|
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>(); |
892 |
|
} |
893 |
|
|
894 |
|
/** |
895 |
< |
* transfer will attempt to transfer in fifo order and continue |
896 |
< |
* waiting if the element being transfered is not polled or taken |
895 |
> |
* transfer waits until a poll occurs, and then transfers in fifo order |
896 |
|
*/ |
897 |
|
public void testTransfer3() throws InterruptedException { |
898 |
|
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>(); |
939 |
|
} |
940 |
|
|
941 |
|
/** |
942 |
< |
* transfer will wait as long as a poll or take occurs if one does occur |
943 |
< |
* the waiting is finished and the thread that tries to poll/take |
945 |
< |
* wins in retrieving the element |
942 |
> |
* transfer waits until a poll occurs, at which point the polling |
943 |
> |
* thread returns the element |
944 |
|
*/ |
945 |
|
public void testTransfer4() throws InterruptedException { |
946 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
960 |
|
} |
961 |
|
|
962 |
|
/** |
963 |
+ |
* transfer waits until a take occurs. The transfered element |
964 |
+ |
* is returned by this associated take. |
965 |
+ |
*/ |
966 |
+ |
public void testTransfer5() throws InterruptedException { |
967 |
+ |
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>(); |
968 |
+ |
|
969 |
+ |
new Thread(new Runnable() { |
970 |
+ |
public void run() { |
971 |
+ |
try { |
972 |
+ |
q.transfer(SIZE); |
973 |
+ |
threadAssertTrue(q.isEmpty()); |
974 |
+ |
} catch (Throwable ex) { |
975 |
+ |
threadUnexpectedException(ex); |
976 |
+ |
} |
977 |
+ |
}}).start(); |
978 |
+ |
|
979 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
980 |
+ |
assertEquals(SIZE, (int) q.take()); |
981 |
+ |
assertTrue(q.isEmpty()); |
982 |
+ |
} |
983 |
+ |
|
984 |
+ |
/** |
985 |
|
* tryTransfer(null) throws NullPointerException |
986 |
|
*/ |
987 |
|
public void testTryTransfer1() { |
1054 |
|
} |
1055 |
|
|
1056 |
|
/** |
1057 |
< |
* tryTransfer waits the amount given if interrupted, show an |
1058 |
< |
* interrupted exception |
1057 |
> |
* tryTransfer waits the amount given if interrupted, and |
1058 |
> |
* throws interrupted exception |
1059 |
|
*/ |
1060 |
|
public void testTryTransfer5() throws InterruptedException { |
1061 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |