Toshio Koide | 515ba84 | 2014-08-20 11:53:37 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.flowmanager; |
| 2 | |
| 3 | import static org.easymock.EasyMock.createMock; |
| 4 | import static org.easymock.EasyMock.expect; |
| 5 | import static org.easymock.EasyMock.replay; |
| 6 | import static org.hamcrest.Matchers.is; |
| 7 | import static org.junit.Assert.assertThat; |
| 8 | import net.onrc.onos.api.flowmanager.FlowId; |
| 9 | import net.onrc.onos.core.util.IdBlock; |
| 10 | import net.onrc.onos.core.util.IdBlockAllocator; |
| 11 | |
| 12 | import org.junit.Before; |
| 13 | import org.junit.Test; |
| 14 | |
| 15 | /** |
| 16 | * Tests {@link FlowIdGeneratorWithIdBlockAllocator} class. |
| 17 | */ |
| 18 | public 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 | } |