blob: b60586d1413c99f39fddd5474df938bf9c5fd8a0 (
plain) (
blame)
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
|
#include <library/cpp/testing/unittest/registar.h>
#include "lfqueue_batch.h"
Y_UNIT_TEST_SUITE(TLockFreeQueueBatch) {
Y_UNIT_TEST(Order1) {
TLockFreeQueueBatch<unsigned> q;
{
TAutoPtr<TVector<unsigned>> v(new TVector<unsigned>);
v->push_back(0);
v->push_back(1);
q.EnqueueAll(v);
}
TVector<unsigned> r;
q.DequeueAllSingleConsumer(&r);
UNIT_ASSERT_VALUES_EQUAL(2u, r.size());
for (unsigned i = 0; i < 2; ++i) {
UNIT_ASSERT_VALUES_EQUAL(i, r[i]);
}
r.clear();
q.DequeueAllSingleConsumer(&r);
UNIT_ASSERT_VALUES_EQUAL(0u, r.size());
}
Y_UNIT_TEST(Order2) {
TLockFreeQueueBatch<unsigned> q;
{
TAutoPtr<TVector<unsigned>> v(new TVector<unsigned>);
v->push_back(0);
v->push_back(1);
q.EnqueueAll(v);
}
{
TAutoPtr<TVector<unsigned>> v(new TVector<unsigned>);
v->push_back(2);
v->push_back(3);
v->push_back(4);
q.EnqueueAll(v);
}
TVector<unsigned> r;
q.DequeueAllSingleConsumer(&r);
UNIT_ASSERT_VALUES_EQUAL(5u, r.size());
for (unsigned i = 0; i < 5; ++i) {
UNIT_ASSERT_VALUES_EQUAL(i, r[i]);
}
r.clear();
q.DequeueAllSingleConsumer(&r);
UNIT_ASSERT_VALUES_EQUAL(0u, r.size());
}
}
|