alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.core.impl; |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.hamcrest.Matchers; |
| 20 | import org.junit.Assert; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.core.IdBlock; |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 24 | |
| 25 | /** |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | * Suites of test of {@link org.onosproject.core.impl.BlockAllocatorBasedIdGenerator}. |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 27 | */ |
| 28 | public class IdBlockAllocatorBasedIdGeneratorTest { |
| 29 | private IdBlockAllocator allocator; |
| 30 | private BlockAllocatorBasedIdGenerator sut; |
| 31 | |
| 32 | @Before |
| 33 | public void setUp() { |
| 34 | allocator = EasyMock.createMock(IdBlockAllocator.class); |
| 35 | |
| 36 | } |
| 37 | |
| 38 | /** |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | * Tests generated IntentId sequences using two {@link org.onosproject.core.IdBlock blocks}. |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 40 | */ |
| 41 | @Test |
| 42 | public void testIds() { |
| 43 | EasyMock.expect(allocator.allocateUniqueIdBlock()) |
| 44 | .andReturn(new IdBlock(0, 3)) |
| 45 | .andReturn(new IdBlock(4, 3)); |
| 46 | |
| 47 | EasyMock.replay(allocator); |
| 48 | sut = new BlockAllocatorBasedIdGenerator(allocator); |
| 49 | |
| 50 | Assert.assertThat(sut.getNewId(), Matchers.is(0L)); |
| 51 | Assert.assertThat(sut.getNewId(), Matchers.is(1L)); |
| 52 | Assert.assertThat(sut.getNewId(), Matchers.is(2L)); |
| 53 | |
| 54 | Assert.assertThat(sut.getNewId(), Matchers.is(4L)); |
| 55 | Assert.assertThat(sut.getNewId(), Matchers.is(5L)); |
| 56 | Assert.assertThat(sut.getNewId(), Matchers.is(6L)); |
| 57 | } |
| 58 | } |