@Test public void testAssigningMacWithAllowedDuplicates() throws Exception { assertThat(rangeOf10Macs.use(MAC_FROM_RANGE, true), is(true)); assertThat(rangeOf10Macs.getAvailableCount(), is(NUMBER_OF_MACS - 1)); assertThat(rangeOf10Macs.use(MAC_FROM_RANGE, true), is(true)); assertThat(rangeOf10Macs.getAvailableCount(), is(NUMBER_OF_MACS - 1)); assertThat(rangeOf10Macs.isAllocated(MAC_FROM_RANGE), is(true)); }
@Test public void testFreeMacDuplicityAllowed() throws Exception { // Allocate one mac twice. assertThat(rangeOf10Macs.use(MAC_FROM_RANGE, true), is(true)); assertThat(rangeOf10Macs.isAllocated(MAC_FROM_RANGE), is(true)); assertThat(rangeOf10Macs.use(MAC_FROM_RANGE, true), is(true)); assertThat(rangeOf10Macs.isAllocated(MAC_FROM_RANGE), is(true)); // Check decreasing of duplicity usage. rangeOf10Macs.freeMac(MAC_FROM_RANGE); assertThat(rangeOf10Macs.isAllocated(MAC_FROM_RANGE), is(true)); rangeOf10Macs.freeMac(MAC_FROM_RANGE); assertThat(rangeOf10Macs.isAllocated(MAC_FROM_RANGE), is(false)); }
private boolean useMac(long mac, boolean allowDuplicates) { Range range = findIncludingRange(mac); if (range == null) { return customMacs.add(mac, allowDuplicates); } else { return range.use(mac, allowDuplicates); } }
/** * test that MACs arent returned in leftmost-available order. Instead, we're returning macs from * left to right, noting last scan position. That means that if we obtain and return mac from/to * pool, we'll obtain this MAC again only after all other free macs were used. */ @Test public void testOrderOrAcquiredMACs() { Range range = new Range(0, 5); List<Integer> usedMacs = Arrays.asList(0, 2, 4); for (int i = 0; i < 5; i++) { boolean usedMac = usedMacs.contains(i); if (usedMac) { boolean allowDuplicates = false; range.use(i, allowDuplicates); } } for (Integer expectedUnallocatedMac : Arrays.asList(1, 3, 5, 1, 3, 5, 1)) { allocateAndFreeMacAndExpectGivenMac(range, expectedUnallocatedMac); } }
@Test(expected = IllegalArgumentException.class) public void testFailWhenUsingMacOutsideOfRange() throws Exception { rangeOf10Macs.use(MAC_OUTSIDE_OF_RANGE, false); }