1 |
– |
|
1 |
|
/* |
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 |
30 |
|
return new TestSuite(LinkedTransferQueueTest.class); |
31 |
|
} |
32 |
|
|
33 |
< |
/* |
34 |
< |
*Constructor builds new queue with size being zero and empty being true |
33 |
> |
/** |
34 |
> |
* Constructor builds new queue with size being zero and empty being true |
35 |
|
*/ |
36 |
|
public void testConstructor1() { |
37 |
|
assertEquals(0, new LinkedTransferQueue().size()); |
38 |
|
assertTrue(new LinkedTransferQueue().isEmpty()); |
39 |
|
} |
40 |
|
|
41 |
< |
/* |
42 |
< |
* Initizialing constructor with null collection throws NPE |
41 |
> |
/** |
42 |
> |
* Initializing constructor with null collection throws NPE |
43 |
|
*/ |
44 |
|
public void testConstructor2() { |
45 |
|
try { |
60 |
|
} catch (NullPointerException success) { |
61 |
|
} |
62 |
|
} |
63 |
< |
/* |
63 |
> |
|
64 |
> |
/** |
65 |
|
* Initializing constructor with a collection containing some null elements |
66 |
|
* throws NPE |
67 |
|
*/ |
68 |
– |
|
68 |
|
public void testConstructor4() { |
69 |
|
try { |
70 |
|
Integer[] ints = new Integer[SIZE]; |
77 |
|
} |
78 |
|
} |
79 |
|
|
80 |
< |
/* |
80 |
> |
/** |
81 |
|
* Queue contains all elements of the collection it is initialized by |
82 |
|
*/ |
83 |
|
public void testConstructor5() { |
278 |
|
unexpectedException(); |
279 |
|
} |
280 |
|
} |
281 |
< |
/* |
281 |
> |
|
282 |
> |
/** |
283 |
|
* Take removes existing elements until empty, then blocks interruptibly |
284 |
|
*/ |
285 |
– |
|
285 |
|
public void testBlockingTake() { |
286 |
|
Thread t = new Thread(new Runnable() { |
287 |
|
|
377 |
|
} |
378 |
|
|
379 |
|
/** |
380 |
< |
* timed poll before a delayed offer fails; after offer succeeds; |
381 |
< |
* on interruption throws |
380 |
> |
* timed poll before a delayed offer fails; after offer succeeds; |
381 |
> |
* on interruption throws |
382 |
|
*/ |
383 |
|
public void testTimedPollWithOffer() { |
384 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
915 |
|
} |
916 |
|
} |
917 |
|
|
918 |
< |
/* |
918 |
> |
/** |
919 |
|
* poll and take should decrement the waiting consumer count |
920 |
|
*/ |
921 |
|
public void testWaitingConsumer() { |
941 |
|
this.unexpectedException(); |
942 |
|
} |
943 |
|
} |
944 |
< |
/* |
944 |
> |
|
945 |
> |
/** |
946 |
|
* Inserts null into transfer throws NPE |
947 |
|
*/ |
948 |
– |
|
948 |
|
public void testTransfer1() { |
949 |
|
try { |
950 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
956 |
|
} |
957 |
|
} |
958 |
|
|
959 |
< |
/* |
960 |
< |
* transfer attempts to insert into the queue then wait until that |
961 |
< |
* object is removed via take or poll. |
959 |
> |
/** |
960 |
> |
* transfer attempts to insert into the queue then wait until that |
961 |
> |
* object is removed via take or poll. |
962 |
|
*/ |
963 |
|
public void testTransfer2() { |
964 |
|
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>(); |
983 |
|
this.unexpectedException(); |
984 |
|
} |
985 |
|
} |
987 |
– |
/* |
988 |
– |
* transfer will attempt to transfer in fifo order and continue waiting if |
989 |
– |
* the element being transfered is not polled or taken |
990 |
– |
*/ |
986 |
|
|
987 |
+ |
/** |
988 |
+ |
* transfer will attempt to transfer in fifo order and continue |
989 |
+ |
* waiting if the element being transfered is not polled or taken |
990 |
+ |
*/ |
991 |
|
public void testTransfer3() { |
992 |
|
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>(); |
993 |
|
new Thread(new Runnable() { |
1002 |
|
} |
1003 |
|
} |
1004 |
|
}).start(); |
1005 |
< |
Thread interruptedThread = |
1005 |
> |
Thread interruptedThread = |
1006 |
|
new Thread(new Runnable() { |
1007 |
|
public void run() { |
1008 |
|
try { |
1027 |
|
|
1028 |
|
/** |
1029 |
|
* transfer will wait as long as a poll or take occurs if one does occur |
1030 |
< |
* the waiting is finished and the thread that tries to poll/take |
1030 |
> |
* the waiting is finished and the thread that tries to poll/take |
1031 |
|
* wins in retrieving the element |
1032 |
|
*/ |
1033 |
|
public void testTransfer4() { |
1052 |
|
this.unexpectedException(); |
1053 |
|
} |
1054 |
|
} |
1056 |
– |
/* |
1057 |
– |
* Insert null into trTransfer throws NPE |
1058 |
– |
*/ |
1055 |
|
|
1056 |
+ |
/** |
1057 |
+ |
* Insert null into tryTransfer throws NPE |
1058 |
+ |
*/ |
1059 |
|
public void testTryTransfer1() { |
1060 |
|
try { |
1061 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1066 |
|
this.unexpectedException(); |
1067 |
|
} |
1068 |
|
} |
1069 |
< |
/* |
1069 |
> |
|
1070 |
> |
/** |
1071 |
|
* tryTransfer returns false and does not enqueue if there are no consumers |
1072 |
|
* waiting to poll or take. |
1073 |
|
*/ |
1074 |
– |
|
1074 |
|
public void testTryTransfer2() { |
1075 |
|
try { |
1076 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1080 |
|
this.unexpectedException(); |
1081 |
|
} |
1082 |
|
} |
1083 |
< |
/* |
1083 |
> |
|
1084 |
> |
/** |
1085 |
|
* if there is a consumer waiting poll or take tryTransfer returns |
1086 |
|
* true while enqueueing object |
1087 |
|
*/ |
1088 |
– |
|
1088 |
|
public void testTryTransfer3() { |
1089 |
|
try { |
1090 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1107 |
|
} |
1108 |
|
} |
1109 |
|
|
1110 |
< |
/* |
1110 |
> |
/** |
1111 |
|
* tryTransfer waits the amount given if interrupted, show an |
1112 |
|
* interrupted exception |
1113 |
|
*/ |
1132 |
|
} |
1133 |
|
} |
1134 |
|
|
1135 |
< |
/* |
1135 |
> |
/** |
1136 |
|
* tryTransfer gives up after the timeout and return false |
1137 |
|
*/ |
1138 |
|
public void testTryTransfer5() { |
1155 |
|
} |
1156 |
|
} |
1157 |
|
|
1158 |
< |
/* |
1158 |
> |
/** |
1159 |
|
* tryTransfer waits for any elements previously in to be removed |
1160 |
|
* before transfering to a poll or take |
1161 |
|
*/ |
1184 |
|
} |
1185 |
|
} |
1186 |
|
|
1187 |
< |
/* |
1188 |
< |
* tryTransfer attempts to enqueue into the q and fails returning false not |
1189 |
< |
* enqueueing and the successing poll is null |
1187 |
> |
/** |
1188 |
> |
* tryTransfer attempts to enqueue into the q and fails returning false not |
1189 |
> |
* enqueueing and the successive poll is null |
1190 |
|
*/ |
1191 |
|
public void testTryTransfer7() { |
1192 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |