Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix MpscArrayQueue.offerIfBelowThreshold issue (fix #120)
- Loading branch information
Showing
2 changed files
with
55 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
jctools-core/src/test/java/org/jctools/queues/MpscOfferBelowThresholdQueueSanityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.jctools.queues; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Queue; | ||
|
||
import org.jctools.queues.spec.ConcurrentQueueSpec; | ||
import org.jctools.queues.spec.Ordering; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
public class MpscOfferBelowThresholdQueueSanityTest extends QueueSanityTest { | ||
/** | ||
* This allows us to test the offersIfBelowThreshold through all the offer utilizing threads. The effect should be | ||
* as if the queue capacity is halved. | ||
*/ | ||
This comment has been minimized.
Sorry, something went wrong.
philipa
Contributor
|
||
static class MpscArrayQueueOverride<E> extends MpscArrayQueue<E> { | ||
int threshold; | ||
public MpscArrayQueueOverride(int capacity) { | ||
super(capacity); | ||
threshold = capacity()/2; | ||
} | ||
@Override | ||
public boolean offer(E e) { | ||
return super.offerIfBelowThreshold(e, threshold); | ||
} | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> parameters() { | ||
ArrayList<Object[]> list = new ArrayList<Object[]>(); | ||
list.add(makeQueue(0, 1, 8, Ordering.FIFO, new MpscArrayQueueOverride<Integer>(16))); | ||
return list; | ||
} | ||
|
||
public MpscOfferBelowThresholdQueueSanityTest(ConcurrentQueueSpec spec, Queue<Integer> queue) { | ||
super(spec, queue); | ||
} | ||
|
||
} |
The threshold is the "minimum number of available slots", so shouldn't this comparison be based on the available slots, not the current size?