Search in sources :

Example 31 with DiscreteResource

use of org.onosproject.net.resource.DiscreteResource in project onos by opennetworkinglab.

the class EncodableDiscreteResourcesTest method testSerializeInstanceContainingEmptyEncodedDiscreteResources.

@Test
public void testSerializeInstanceContainingEmptyEncodedDiscreteResources() {
    DiscreteResource device = Resources.discrete(DeviceId.deviceId("a")).resource();
    List<PortNumber> ports = IntStream.range(0, 1).mapToObj(PortNumber::portNumber).collect(Collectors.toList());
    List<VlanId> vlans = IntStream.range(0, 2).mapToObj(x -> VlanId.vlanId((short) x)).collect(Collectors.toList());
    Set<DiscreteResource> originalResources = Stream.concat(ports.stream(), vlans.stream()).map(device::child).collect(Collectors.toSet());
    DiscreteResources sut = EncodableDiscreteResources.of(originalResources);
    Set<DiscreteResource> portOnlyResources = ports.stream().map(device::child).collect(Collectors.toSet());
    DiscreteResources other = EncodableDiscreteResources.of(portOnlyResources);
    DiscreteResources diff = sut.difference(other);
    byte[] bytes = serializer.encode(diff);
    assertThat(serializer.decode(bytes), is(diff));
}
Also used : IntStream(java.util.stream.IntStream) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Resources(org.onosproject.net.resource.Resources) VlanId(org.onlab.packet.VlanId) PortNumber(org.onosproject.net.PortNumber) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) DeviceId(org.onosproject.net.DeviceId) DiscreteResource(org.onosproject.net.resource.DiscreteResource) DiscreteResource(org.onosproject.net.resource.DiscreteResource) PortNumber(org.onosproject.net.PortNumber) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test)

Example 32 with DiscreteResource

use of org.onosproject.net.resource.DiscreteResource in project onos by opennetworkinglab.

the class EncodableDiscreteResourcesTest method testAdd.

@Test
public void testAdd() {
    DiscreteResource res1 = Resources.discrete(DeviceId.deviceId("a"), PortNumber.portNumber(1)).resource();
    DiscreteResource res2 = Resources.discrete(DeviceId.deviceId("a"), PortNumber.portNumber(2)).resource();
    DiscreteResources sut = EncodableDiscreteResources.of(ImmutableSet.of(res1));
    DiscreteResources other = EncodableDiscreteResources.of(ImmutableSet.of(res2));
    DiscreteResources expected = EncodableDiscreteResources.of(ImmutableSet.of(res1, res2));
    assertThat(sut.add(other), is(expected));
}
Also used : DiscreteResource(org.onosproject.net.resource.DiscreteResource) Test(org.junit.Test)

Example 33 with DiscreteResource

use of org.onosproject.net.resource.DiscreteResource in project onos by opennetworkinglab.

the class EncodedDiscreteResourcesTest method testDifference.

@Test
public void testDifference() {
    DiscreteResource res1 = Resources.discrete(DID, PN, VID1).resource();
    DiscreteResource res2 = Resources.discrete(DID, PN, VID2).resource();
    DiscreteResource res3 = Resources.discrete(DID, PN, VID3).resource();
    EncodedDiscreteResources sut = EncodedDiscreteResources.of(ImmutableSet.of(res1, res2), new VlanIdCodec());
    EncodedDiscreteResources other = EncodedDiscreteResources.of(ImmutableSet.of(res1, res3), new VlanIdCodec());
    assertThat(sut.difference(other), is(EncodedDiscreteResources.of(ImmutableSet.of(res2), new VlanIdCodec())));
}
Also used : DiscreteResource(org.onosproject.net.resource.DiscreteResource) Test(org.junit.Test)

Example 34 with DiscreteResource

use of org.onosproject.net.resource.DiscreteResource in project onos by opennetworkinglab.

the class EncodedDiscreteResourcesTest method testContains.

@Test
public void testContains() {
    DiscreteResource res1 = Resources.discrete(DID, PN, VID1).resource();
    DiscreteResource res2 = Resources.discrete(DID, PN, VID2).resource();
    DiscreteResource res3 = Resources.discrete(DID, PN, VID3).resource();
    Set<DiscreteResource> resources = ImmutableSet.of(res1, res2);
    EncodedDiscreteResources sut = EncodedDiscreteResources.of(resources, new VlanIdCodec());
    assertThat(sut.contains(res1), is(true));
    assertThat(sut.contains(res3), is(false));
}
Also used : DiscreteResource(org.onosproject.net.resource.DiscreteResource) Test(org.junit.Test)

Example 35 with DiscreteResource

use of org.onosproject.net.resource.DiscreteResource in project onos by opennetworkinglab.

the class EncodedDiscreteResourcesTest method testAdd.

@Test
public void testAdd() {
    DiscreteResource res1 = Resources.discrete(DID, PN, VID1).resource();
    DiscreteResource res2 = Resources.discrete(DID, PN, VID2).resource();
    DiscreteResource res3 = Resources.discrete(DID, PN, VID3).resource();
    EncodedDiscreteResources sut = EncodedDiscreteResources.of(ImmutableSet.of(res1, res2), new VlanIdCodec());
    EncodedDiscreteResources other = EncodedDiscreteResources.of(ImmutableSet.of(res1, res3), new VlanIdCodec());
    assertThat(sut.add(other), is(EncodedDiscreteResources.of(ImmutableSet.of(res1, res2, res3), new VlanIdCodec())));
}
Also used : DiscreteResource(org.onosproject.net.resource.DiscreteResource) Test(org.junit.Test)

Aggregations

DiscreteResource (org.onosproject.net.resource.DiscreteResource)47 Test (org.junit.Test)38 Resource (org.onosproject.net.resource.Resource)6 ImmutableSet (com.google.common.collect.ImmutableSet)4 Set (java.util.Set)4 ContinuousResource (org.onosproject.net.resource.ContinuousResource)4 Resources (org.onosproject.net.resource.Resources)4 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 Optional (java.util.Optional)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 PortNumber (org.onosproject.net.PortNumber)3 ResourceConsumerId (org.onosproject.net.resource.ResourceConsumerId)3 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 VlanId (org.onlab.packet.VlanId)2 DeviceId (org.onosproject.net.DeviceId)2