forked from zeromq/jeromq
/
TestYQueue.java
66 lines (51 loc) · 1.96 KB
/
TestYQueue.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
61
62
63
64
65
66
/*
Copyright (c) 2007-2012 iMatix Corporation
Copyright (c) 2011 250bpm s.r.o.
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package zmq;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
public class TestYQueue {
@Test
public void testReuse() {
// yqueue has a first empty entry
YQueue<Msg> p = new YQueue<Msg>(Msg.class, 3);
p.push();
Msg m1 = new Msg(1);
Msg m2 = new Msg(2);
Msg m3 = new Msg(3);
Msg m4 = new Msg(4);
Msg m5 = new Msg(5);
Msg m6 = new Msg(6);
Msg m7 = new Msg(7);
m7.put("1234567".getBytes(),0);
p.back(m1);
assertThat(p.back_pos(), is(0L));
p.push();
p.back(m2); p.push(); // might allocated new chunk
p.back(m3); p.push();
assertThat(p.back_pos(), is(3L));
assertThat(p.front_pos(), is(0L));
p.pop();
p.pop();
p.pop(); // offer the old chunk
assertThat(p.front_pos(), is(3L));
p.back(m4); p.push();
p.back(m5); p.push();// might reuse the old chunk
p.back(m6); p.push();
assertThat(p.back_pos(), is(0L));
}
}