-
Notifications
You must be signed in to change notification settings - Fork 554
/
QueueSanityTestSpscGrowable.java
60 lines (52 loc) · 1.75 KB
/
QueueSanityTestSpscGrowable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.jctools.queues;
import org.jctools.queues.spec.ConcurrentQueueSpec;
import org.jctools.queues.spec.Ordering;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Queue;
import static org.hamcrest.Matchers.is;
@RunWith(Parameterized.class)
public class QueueSanityTestSpscGrowable extends QueueSanityTest
{
public QueueSanityTestSpscGrowable(ConcurrentQueueSpec spec, Queue<Integer> queue)
{
super(spec, queue);
}
@Parameterized.Parameters
public static Collection<Object[]> parameters()
{
ArrayList<Object[]> list = new ArrayList<Object[]>();
list.add(makeQueue(1, 1, 16, Ordering.FIFO, new SpscGrowableArrayQueue<>(8, 16)));
list.add(makeQueue(1, 1, SIZE, Ordering.FIFO, new SpscGrowableArrayQueue<>(8, SIZE)));
return list;
}
@Test
public void testSizeNeverExceedCapacity()
{
final SpscGrowableArrayQueue<Integer> q = new SpscGrowableArrayQueue<>(8, 16);
final Integer v = 0;
final int capacity = q.capacity();
for (int i = 0; i < capacity; i++)
{
Assert.assertTrue(q.offer(v));
}
Assert.assertFalse(q.offer(v));
Assert.assertThat(q.size(), is(capacity));
for (int i = 0; i < 6; i++)
{
Assert.assertEquals(v, q.poll());
}
//the consumer is left in the chunk previous the last and biggest one
Assert.assertThat(q.size(), is(capacity - 6));
for (int i = 0; i < 6; i++)
{
q.offer(v);
}
Assert.assertThat(q.size(), is(capacity));
Assert.assertFalse(q.offer(v));
}
}