blob: 9546f6e36dbcb86d683500d7d9eef7141c617bc6 [file] [log] [blame]
Toshio Koide515ba842014-08-20 11:53:37 -07001package net.onrc.onos.core.flowmanager;
2
3import static org.easymock.EasyMock.createMock;
4import static org.easymock.EasyMock.expect;
5import static org.easymock.EasyMock.replay;
6import static org.hamcrest.Matchers.is;
7import static org.junit.Assert.assertThat;
8import net.onrc.onos.api.flowmanager.FlowId;
9import net.onrc.onos.core.util.IdBlock;
10import net.onrc.onos.core.util.IdBlockAllocator;
11
12import org.junit.Before;
13import org.junit.Test;
14
15/**
16 * Tests {@link FlowIdGeneratorWithIdBlockAllocator} class.
17 */
18public class FlowIdGeneratorWithIdBlockAllocatorTest {
19 private IdBlockAllocator allocator;
20 private FlowIdGeneratorWithIdBlockAllocator flowIdGenerator;
21
22 @Before
23 public void setUp() {
24 allocator = createMock(IdBlockAllocator.class);
25
26 }
27
28 /**
29 * Tests generated FlowId sequences using two {@link IdBlock blocks}.
30 */
31 @Test
32 public void testIds() {
33 expect(allocator.allocateUniqueIdBlock())
34 .andReturn(new IdBlock(0, 3))
35 .andReturn(new IdBlock(4, 3));
36
37 replay(allocator);
38 flowIdGenerator = new FlowIdGeneratorWithIdBlockAllocator(allocator);
39
40 assertThat(flowIdGenerator.getNewId(), is(new FlowId(0L)));
41 assertThat(flowIdGenerator.getNewId(), is(new FlowId(1L)));
42 assertThat(flowIdGenerator.getNewId(), is(new FlowId(2L)));
43
44 assertThat(flowIdGenerator.getNewId(), is(new FlowId(4L)));
45 assertThat(flowIdGenerator.getNewId(), is(new FlowId(5L)));
46 assertThat(flowIdGenerator.getNewId(), is(new FlowId(6L)));
47 }
48}