Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor MpscBlocking::offerBelow + bug fix + tests
- Loading branch information
Showing
4 changed files
with
104 additions
and
29 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
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
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
66 changes: 66 additions & 0 deletions
66
.../test/java/org/jctools/queues/QueueSanityTestMpscBlockingConsumerOfferBelowThreshold.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,66 @@ | ||
package org.jctools.queues; | ||
|
||
import org.jctools.queues.spec.ConcurrentQueueSpec; | ||
import org.jctools.queues.spec.Ordering; | ||
import org.junit.Ignore; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Queue; | ||
|
||
@RunWith(Parameterized.class) | ||
public class QueueSanityTestMpscBlockingConsumerOfferBelowThreshold extends QueueSanityTest | ||
{ | ||
public QueueSanityTestMpscBlockingConsumerOfferBelowThreshold(ConcurrentQueueSpec spec, Queue<Integer> queue) | ||
{ | ||
super(spec, queue); | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> parameters() | ||
{ | ||
ArrayList<Object[]> list = new ArrayList<Object[]>(); | ||
MpscBlockingConsumerArrayQueueOverride<Integer> q = new MpscBlockingConsumerArrayQueueOverride<Integer>(16); | ||
list.add(makeQueue(0, 1, 8, Ordering.FIFO, q)); | ||
q = new MpscBlockingConsumerArrayQueueOverride<Integer>(16); | ||
q.threshold = 12; | ||
list.add(makeQueue(0, 1, 12, Ordering.FIFO, q)); | ||
q = new MpscBlockingConsumerArrayQueueOverride<Integer>(16); | ||
q.threshold = 4; | ||
list.add(makeQueue(0, 1, 4, Ordering.FIFO, q)); | ||
return list; | ||
} | ||
|
||
@Ignore | ||
public void testPowerOf2Capacity() | ||
{ | ||
} | ||
|
||
@Ignore | ||
public void testIterator() | ||
{ | ||
} | ||
|
||
/** | ||
* This allows us to test the offersIfBelowThreshold through all the offer utilizing threads. The effect should be | ||
* as if the queue capacity is halved. | ||
*/ | ||
static class MpscBlockingConsumerArrayQueueOverride<E> extends MpscBlockingConsumerArrayQueue<E> | ||
{ | ||
int threshold; | ||
|
||
public MpscBlockingConsumerArrayQueueOverride(int capacity) | ||
{ | ||
super(capacity); | ||
threshold = capacity() / 2; | ||
} | ||
|
||
@Override | ||
public boolean offer(E e) | ||
{ | ||
return super.offerIfBelowThreshold(e, threshold); | ||
} | ||
} | ||
} |