use of org.onosproject.net.resource.ResourceAllocation in project onos by opennetworkinglab.
the class ContinuousResourceAllocationTest method testReleaseWhenDifferentConsumerIsSpecified.
@Test
public void testReleaseWhenDifferentConsumerIsSpecified() {
ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
ResourceConsumer consumer = IntentId.valueOf(1);
ResourceConsumer otherConsumer = IntentId.valueOf(2);
ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
ImmutableList<ResourceAllocation> allocations = sut.release(request, otherConsumer.consumerId()).allocations();
assertThat(allocations.size(), is(1));
assertThat(allocations.get(0).resource().equals(allocated), is(true));
}
use of org.onosproject.net.resource.ResourceAllocation in project onos by opennetworkinglab.
the class ContinuousResourceAllocationTest method testAllocateDifferentValue.
@Test
public void testAllocateDifferentValue() {
ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
ResourceConsumer consumer = IntentId.valueOf(1);
ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(200).bps());
ContinuousResourceAllocation newValue = sut.allocate(new ResourceAllocation(request, consumer));
assertThat(newValue.allocations().size(), is(2));
assertThat(newValue.allocations(), hasItem(new ResourceAllocation(allocated, consumer)));
assertThat(newValue.allocations(), hasItem(new ResourceAllocation(request, consumer)));
}
use of org.onosproject.net.resource.ResourceAllocation in project onos by opennetworkinglab.
the class ContinuousResourceAllocationTest method testHasEnoughResourceWhenLargeResourceIsRequested.
@Test
public void testHasEnoughResourceWhenLargeResourceIsRequested() {
ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
ResourceConsumer consumer = IntentId.valueOf(1);
ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(600).bps());
assertThat(sut.hasEnoughResource(request), is(false));
}
use of org.onosproject.net.resource.ResourceAllocation in project onos by opennetworkinglab.
the class ContinuousResourceAllocationTest method testHasEnoughResourceWhenExactResourceIsRequested.
@Test
public void testHasEnoughResourceWhenExactResourceIsRequested() {
ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
ResourceConsumer consumer = IntentId.valueOf(1);
ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
assertThat(sut.hasEnoughResource(request), is(true));
}
use of org.onosproject.net.resource.ResourceAllocation in project onos by opennetworkinglab.
the class ContinuousResourceAllocationTest method testReleaseWhenAllocatedResourceIsRequested.
@Test
public void testReleaseWhenAllocatedResourceIsRequested() {
ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
ResourceConsumer consumer = IntentId.valueOf(1);
ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
ContinuousResourceAllocation released = sut.release(request, consumer.consumerId());
assertThat(released.allocations().isEmpty(), is(true));
}
Aggregations