Search in sources :

Example 1 with DeviceStoreDelegate

use of org.onosproject.net.device.DeviceStoreDelegate in project onos by opennetworkinglab.

the class GossipDeviceStoreTest method testEvents.

// If Delegates should be called only on remote events,
// then Simple* should never call them, thus not test required.
// TODO add test for Port events when we have them
@Ignore("Ignore until Delegate spec. is clear.")
@Test
public final void testEvents() throws InterruptedException {
    final CountDownLatch addLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkAdd = event -> {
        assertEquals(DEVICE_ADDED, event.type());
        assertDevice(DID1, SW1, event.subject());
        addLatch.countDown();
    };
    final CountDownLatch updateLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkUpdate = event -> {
        assertEquals(DEVICE_UPDATED, event.type());
        assertDevice(DID1, SW2, event.subject());
        updateLatch.countDown();
    };
    final CountDownLatch removeLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkRemove = event -> {
        assertEquals(DEVICE_REMOVED, event.type());
        assertDevice(DID1, SW2, event.subject());
        removeLatch.countDown();
    };
    DeviceDescription description = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID);
    deviceStore.setDelegate(checkAdd);
    deviceStore.createOrUpdateDevice(PID, DID1, description);
    assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS));
    DeviceDescription description2 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID);
    deviceStore.unsetDelegate(checkAdd);
    deviceStore.setDelegate(checkUpdate);
    deviceStore.createOrUpdateDevice(PID, DID1, description2);
    assertTrue("Update event fired", updateLatch.await(1, TimeUnit.SECONDS));
    deviceStore.unsetDelegate(checkUpdate);
    deviceStore.setDelegate(checkRemove);
    deviceStore.removeDevice(DID1);
    assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS));
}
Also used : DeviceClockServiceAdapter(org.onosproject.net.device.DeviceClockServiceAdapter) Arrays(java.util.Arrays) EasyMock.capture(org.easymock.EasyMock.capture) BiFunction(java.util.function.BiFunction) PortNumber(org.onosproject.net.PortNumber) DeviceStore(org.onosproject.net.device.DeviceStore) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) DEVICE_REMOVED(org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) StorageService(org.onosproject.store.service.StorageService) EasyMock.reset(org.easymock.EasyMock.reset) Port(org.onosproject.net.Port) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Map(java.util.Map) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) SWITCH(org.onosproject.net.Device.Type.SWITCH) Assert.fail(org.junit.Assert.fail) DeviceId.deviceId(org.onosproject.net.DeviceId.deviceId) DeviceStoreDelegate(org.onosproject.net.device.DeviceStoreDelegate) DeviceDescription(org.onosproject.net.device.DeviceDescription) NodeId(org.onosproject.cluster.NodeId) AfterClass(org.junit.AfterClass) Device(org.onosproject.net.Device) Set(java.util.Set) PORT_REMOVED(org.onosproject.net.device.DeviceEvent.Type.PORT_REMOVED) Sets(com.google.common.collect.Sets) CountDownLatch(java.util.concurrent.CountDownLatch) DeviceClockService(org.onosproject.net.device.DeviceClockService) List(java.util.List) Annotations(org.onosproject.net.Annotations) SparseAnnotations(org.onosproject.net.SparseAnnotations) Assert.assertFalse(org.junit.Assert.assertFalse) EasyMock.createNiceMock(org.easymock.EasyMock.createNiceMock) DeviceEvent(org.onosproject.net.device.DeviceEvent) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) DEVICE_AVAILABILITY_CHANGED(org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED) ChassisId(org.onlab.packet.ChassisId) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) DEVICE_ADDED(org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) KryoNamespace(org.onlab.util.KryoNamespace) Function(java.util.function.Function) ControllerNode(org.onosproject.cluster.ControllerNode) PortDescription(org.onosproject.net.device.PortDescription) Timestamp(org.onosproject.store.Timestamp) ACTIVE(org.onosproject.cluster.ControllerNode.State.ACTIVE) EasyMock.replay(org.easymock.EasyMock.replay) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Before(org.junit.Before) IpAddress(org.onlab.packet.IpAddress) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Capture(org.easymock.Capture) StaticClusterService(org.onosproject.store.cluster.StaticClusterService) MastershipRole(org.onosproject.net.MastershipRole) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) IOException(java.io.IOException) EasyMock.expect(org.easymock.EasyMock.expect) DefaultAnnotations.union(org.onosproject.net.DefaultAnnotations.union) ClusterMessage(org.onosproject.store.cluster.messaging.ClusterMessage) PORT_ADDED(org.onosproject.net.device.DeviceEvent.Type.PORT_ADDED) TimeUnit(java.util.concurrent.TimeUnit) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) MastershipServiceAdapter(org.onosproject.mastership.MastershipServiceAdapter) EasyMock.verify(org.easymock.EasyMock.verify) PORT_UPDATED(org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) DEVICE_UPDATED(org.onosproject.net.device.DeviceEvent.Type.DEVICE_UPDATED) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceStoreDelegate(org.onosproject.net.device.DeviceStoreDelegate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with DeviceStoreDelegate

use of org.onosproject.net.device.DeviceStoreDelegate in project onos by opennetworkinglab.

the class SimpleDeviceStoreTest method testEvents.

// If Delegates should be called only on remote events,
// then Simple* should never call them, thus not test required.
// TODO add test for Port events when we have them
@Ignore("Ignore until Delegate spec. is clear.")
@Test
public final void testEvents() throws InterruptedException {
    final CountDownLatch addLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkAdd = event -> {
        assertEquals(DEVICE_ADDED, event.type());
        assertDevice(DID1, SW1, event.subject());
        addLatch.countDown();
    };
    final CountDownLatch updateLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkUpdate = event -> {
        assertEquals(DEVICE_UPDATED, event.type());
        assertDevice(DID1, SW2, event.subject());
        updateLatch.countDown();
    };
    final CountDownLatch removeLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkRemove = event -> {
        assertEquals(DEVICE_REMOVED, event.type());
        assertDevice(DID1, SW2, event.subject());
        removeLatch.countDown();
    };
    DeviceDescription description = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID);
    deviceStore.setDelegate(checkAdd);
    deviceStore.createOrUpdateDevice(PID, DID1, description);
    assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS));
    DeviceDescription description2 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID);
    deviceStore.unsetDelegate(checkAdd);
    deviceStore.setDelegate(checkUpdate);
    deviceStore.createOrUpdateDevice(PID, DID1, description2);
    assertTrue("Update event fired", updateLatch.await(1, TimeUnit.SECONDS));
    deviceStore.unsetDelegate(checkUpdate);
    deviceStore.setDelegate(checkRemove);
    deviceStore.removeDevice(DID1);
    assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS));
}
Also used : Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) PortNumber(org.onosproject.net.PortNumber) HashMap(java.util.HashMap) DeviceStore(org.onosproject.net.device.DeviceStore) NetTestTools.assertAnnotationsEquals(org.onosproject.net.NetTestTools.assertAnnotationsEquals) Port(org.onosproject.net.Port) Map(java.util.Map) After(org.junit.After) SWITCH(org.onosproject.net.Device.Type.SWITCH) PortDescription(org.onosproject.net.device.PortDescription) DeviceId.deviceId(org.onosproject.net.DeviceId.deviceId) DeviceStoreDelegate(org.onosproject.net.device.DeviceStoreDelegate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Before(org.junit.Before) DeviceDescription(org.onosproject.net.device.DeviceDescription) AfterClass(org.junit.AfterClass) Device(org.onosproject.net.Device) Set(java.util.Set) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.device.DeviceEvent.Type) Sets(com.google.common.collect.Sets) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) Ignore(org.junit.Ignore) SparseAnnotations(org.onosproject.net.SparseAnnotations) DeviceEvent(org.onosproject.net.device.DeviceEvent) Assert(org.junit.Assert) DeviceId(org.onosproject.net.DeviceId) ChassisId(org.onlab.packet.ChassisId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DeviceStoreDelegate(org.onosproject.net.device.DeviceStoreDelegate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Iterables (com.google.common.collect.Iterables)2 Sets (com.google.common.collect.Sets)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 After (org.junit.After)2 AfterClass (org.junit.AfterClass)2 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 ChassisId (org.onlab.packet.ChassisId)2 IOException (java.io.IOException)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 CompletableFuture (java.util.concurrent.CompletableFuture)1