3030import java .util .concurrent .atomic .AtomicBoolean ;
3131
3232import org .hamcrest .Matcher ;
33- import org .jctools .queues .atomic .AtomicQueueFactory ;
3433import org .jctools .util .Pow2 ;
3534import org .junit .Before ;
3635import org .junit .Test ;
@@ -44,12 +43,16 @@ public abstract class QueueSanityTest {
4443 public static final int SIZE = 8192 * 2 ;
4544
4645 private final Queue <Integer > queue ;
47- private final org .jctools .queues .spec .ConcurrentQueueSpec spec ;
46+ private final Ordering ordering ;
47+ private final boolean isBounded ;
48+ private final int capacity ;
4849
49- protected QueueSanityTest (
50- org . jctools . queues . spec . ConcurrentQueueSpec spec , Queue < Integer > queue ) {
50+ protected QueueSanityTest (Queue < Integer > queue ,
51+ Ordering ordering , int capacity , boolean isBounded ) {
5152 this .queue = queue ;
52- this .spec = spec ;
53+ this .ordering = ordering ;
54+ this .capacity = capacity ;
55+ this .isBounded = isBounded ;
5356 }
5457
5558 @ Before
@@ -69,7 +72,7 @@ public void sanity() {
6972 }
7073 int size = i ;
7174 assertEquals (size , queue .size ());
72- if (spec . ordering == org . jctools . queues . spec . Ordering .FIFO ) {
75+ if (ordering == Ordering .FIFO ) {
7376 // expect FIFO
7477 i = 0 ;
7578 Integer p ;
@@ -107,7 +110,7 @@ public void testSizeIsTheNumberOfOffers() {
107110
108111 @ Test
109112 public void whenFirstInThenFirstOut () {
110- assumeThat (spec . ordering , is (org . jctools . queues . spec . Ordering .FIFO ));
113+ assumeThat (ordering , is (Ordering .FIFO ));
111114
112115 // Arrange
113116 int i = 0 ;
@@ -157,8 +160,8 @@ public void whenOfferItemAndPollItemThenSameInstanceReturnedAndQueueIsEmpty() {
157160
158161 @ Test
159162 public void testPowerOf2Capacity () {
160- assumeThat (spec . isBounded () , is (true ));
161- int n = Pow2 .roundToPowerOfTwo (spec . capacity );
163+ assumeThat (isBounded , is (true ));
164+ int n = Pow2 .roundToPowerOfTwo (capacity );
162165
163166 for (int i = 0 ; i < n ; i ++) {
164167 assertTrue ("Failed to insert:" + i , queue .offer (i ));
@@ -172,7 +175,7 @@ static final class Val {
172175
173176 @ Test
174177 @ SuppressWarnings ({"rawtypes" , "unchecked" })
175- public void testHappensBefore () throws Exception {
178+ public void testHappensBefore () throws InterruptedException {
176179 final AtomicBoolean stop = new AtomicBoolean ();
177180 final Queue q = queue ;
178181 final Val fail = new Val ();
@@ -217,7 +220,7 @@ public void run() {
217220 }
218221
219222 @ Test
220- public void testSize () throws Exception {
223+ public void testSize () throws InterruptedException {
221224 final AtomicBoolean stop = new AtomicBoolean ();
222225 final Queue <Integer > q = queue ;
223226 final Val fail = new Val ();
@@ -253,7 +256,7 @@ public void run() {
253256 }
254257
255258 @ Test
256- public void testPollAfterIsEmpty () throws Exception {
259+ public void testPollAfterIsEmpty () throws InterruptedException {
257260 final AtomicBoolean stop = new AtomicBoolean ();
258261 final Queue <Integer > q = queue ;
259262 final Val fail = new Val ();
@@ -289,29 +292,11 @@ public void run() {
289292
290293 }
291294
292- public static Object [] makeQueue (int producers , int consumers , int capacity ,
293- org .jctools .queues .spec .Ordering ordering , Queue <Integer > q ) {
294- org .jctools .queues .spec .ConcurrentQueueSpec spec =
295- new org .jctools .queues .spec .ConcurrentQueueSpec (
296- producers , consumers , capacity , ordering , org .jctools .queues .spec .Preference .NONE );
297- if (q == null ) {
298- q = org .jctools .queues .QueueFactory .newQueue (spec );
299- }
300- return new Object [] {spec , q };
301- }
302-
303- public static Object [] makeAtomic (int producers , int consumers , int capacity ,
304- org .jctools .queues .spec .Ordering ordering , Queue <Integer > q ) {
305- org .jctools .queues .spec .ConcurrentQueueSpec spec =
306- new org .jctools .queues .spec .ConcurrentQueueSpec (
307- producers , consumers , capacity , ordering , org .jctools .queues .spec .Preference .NONE );
308- if (q == null ) {
309- q = AtomicQueueFactory .newQueue (spec );
310- }
311- return new Object [] {spec , q };
312- }
313-
314295 public static Matcher <Collection <?>> emptyAndZeroSize () {
315296 return allOf (hasSize (0 ), empty ());
316297 }
298+
299+ enum Ordering {
300+ FIFO
301+ }
317302}
0 commit comments