Example #1
0
  @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));
  }
Example #2
0
 public void freeMac(long mac) {
   Range range = findIncludingRange(mac);
   if (range == null) {
     customMacs.remove(mac);
   } else {
     range.freeMac(mac);
   }
 }
Example #3
0
  @Test
  public void testFreeMac() throws Exception {
    final List<Long> allocatedMacs = rangeOf10Macs.allocateMacs(NUMBER_OF_MACS);
    assertThat(allocatedMacs.size(), is(NUMBER_OF_MACS));
    assertThat(rangeOf10Macs.getAvailableCount(), is(0));

    for (int i = 1; i <= NUMBER_OF_MACS; i++) {
      rangeOf10Macs.freeMac(allocatedMacs.remove(0));
      assertThat(rangeOf10Macs.getAvailableCount(), is(i));
    }
  }
Example #4
0
 @Test(expected = IllegalArgumentException.class)
 public void testFailWhenReturningMacOutsideOfRange() throws Exception {
   rangeOf10Macs.freeMac(MAC_OUTSIDE_OF_RANGE);
 }
Example #5
0
 /**
  * *
  *
  * <p>method obtains mac from pool, assert expectation, and return it back.
  *
  * @param range range of macs
  * @param expectedMac mac, which we expect to be returned from {@code range.allocateMacs(1)}
  */
 private void allocateAndFreeMacAndExpectGivenMac(Range range, long expectedMac) {
   Long mac = range.allocateMacs(1).get(0);
   assertThat(mac, is(expectedMac));
   range.freeMac(mac);
 }