Search in sources :

Example 1 with DEVICE_UPDATED

use of org.onosproject.net.device.DeviceEvent.Type.DEVICE_UPDATED 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)

Aggregations

Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Capture (org.easymock.Capture)1 EasyMock.anyObject (org.easymock.EasyMock.anyObject)1 EasyMock.capture (org.easymock.EasyMock.capture)1 EasyMock.createNiceMock (org.easymock.EasyMock.createNiceMock)1