Search in sources :

Example 6 with TestEventDispatcher

use of org.onosproject.common.event.impl.TestEventDispatcher in project onos by opennetworkinglab.

the class UpgradeManagerTest method createUpgradeManager.

/**
 * Creates a new upgrade manager to test.
 *
 * @param version the local node version
 * @param state the initial upgrade state
 * @param versions a list of controller node versions
 * @return the activated upgrade manager
 */
@SuppressWarnings("unchecked")
private UpgradeManager createUpgradeManager(Version version, Upgrade state, List<Version> versions) {
    UpgradeManager upgradeManager = new UpgradeManager();
    injectEventDispatcher(upgradeManager, new TestEventDispatcher());
    upgradeManager.membershipService = new MembershipServiceAdapter() {

        @Override
        public MembershipGroup getLocalGroup() {
            return getGroups().stream().filter(group -> group.version().equals(version)).findFirst().get();
        }

        @Override
        public Collection<MembershipGroup> getGroups() {
            AtomicInteger nodeCounter = new AtomicInteger();
            Map<Version, Set<Member>> groups = Maps.newHashMap();
            versions.stream().forEach(version -> {
                groups.computeIfAbsent(version, k -> Sets.newHashSet()).add(new Member(NodeId.nodeId(String.valueOf(nodeCounter.getAndIncrement())), version));
            });
            return Maps.transformEntries(groups, MembershipGroup::new).values();
        }
    };
    upgradeManager.clusterService = new ClusterServiceAdapter() {

        @Override
        public Set<ControllerNode> getNodes() {
            AtomicInteger nodeCounter = new AtomicInteger();
            return versions.stream().map(v -> {
                int nodeId = nodeCounter.getAndIncrement();
                return new DefaultControllerNode(NodeId.nodeId(String.valueOf(nodeId)), IpAddress.valueOf("127.0.0.1"), nodeId);
            }).collect(Collectors.toSet());
        }

        @Override
        public ControllerNode getNode(NodeId nodeId) {
            return getNodes().stream().filter(node -> node.id().equals(nodeId)).findFirst().orElse(null);
        }

        @Override
        public Version getVersion(NodeId nodeId) {
            return versions.get(Integer.parseInt(nodeId.id()));
        }
    };
    upgradeManager.versionService = new VersionServiceAdapter() {

        @Override
        public Version version() {
            return version;
        }
    };
    upgradeManager.coordinationService = new CoordinationServiceAdapter() {

        @Override
        public <V> AtomicValueBuilder<V> atomicValueBuilder() {
            return new AtomicValueBuilder<V>() {

                @Override
                public AsyncAtomicValue<V> build() {
                    return new AsyncAtomicValueAdapter() {

                        @Override
                        public AtomicValue asAtomicValue() {
                            return new AtomicValueAdapter() {

                                private Object value = state;

                                @Override
                                public void set(Object value) {
                                    this.value = value;
                                }

                                @Override
                                public Object get() {
                                    return value;
                                }

                                @Override
                                public boolean compareAndSet(Object expect, Object update) {
                                    if ((value == null && expect == null) || (value != null && value.equals(expect))) {
                                        value = update;
                                        return true;
                                    }
                                    return false;
                                }
                            };
                        }
                    };
                }
            };
        }
    };
    upgradeManager.activate();
    return upgradeManager;
}
Also used : Arrays(java.util.Arrays) NetTestTools.injectEventDispatcher(org.onosproject.net.NetTestTools.injectEventDispatcher) Member(org.onosproject.cluster.Member) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) MembershipGroup(org.onosproject.cluster.MembershipGroup) TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) AtomicValue(org.onosproject.store.service.AtomicValue) AtomicValueBuilder(org.onosproject.store.service.AtomicValueBuilder) Upgrade(org.onosproject.upgrade.Upgrade) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Version(org.onosproject.core.Version) Assert.fail(org.junit.Assert.fail) AsyncAtomicValue(org.onosproject.store.service.AsyncAtomicValue) IpAddress(org.onlab.packet.IpAddress) NodeId(org.onosproject.cluster.NodeId) VersionServiceAdapter(org.onosproject.core.VersionServiceAdapter) AtomicValueAdapter(org.onosproject.store.service.AtomicValueAdapter) ClusterEvent(org.onosproject.cluster.ClusterEvent) CoordinationServiceAdapter(org.onosproject.store.service.CoordinationServiceAdapter) Collection(java.util.Collection) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) AsyncAtomicValueAdapter(org.onosproject.store.service.AsyncAtomicValueAdapter) Sets(com.google.common.collect.Sets) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) MembershipServiceAdapter(org.onosproject.cluster.MembershipServiceAdapter) Set(java.util.Set) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) AtomicValue(org.onosproject.store.service.AtomicValue) AsyncAtomicValue(org.onosproject.store.service.AsyncAtomicValue) AsyncAtomicValue(org.onosproject.store.service.AsyncAtomicValue) CoordinationServiceAdapter(org.onosproject.store.service.CoordinationServiceAdapter) Version(org.onosproject.core.Version) Member(org.onosproject.cluster.Member) TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) MembershipServiceAdapter(org.onosproject.cluster.MembershipServiceAdapter) AtomicValueBuilder(org.onosproject.store.service.AtomicValueBuilder) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) AtomicValueAdapter(org.onosproject.store.service.AtomicValueAdapter) AsyncAtomicValueAdapter(org.onosproject.store.service.AsyncAtomicValueAdapter) AsyncAtomicValueAdapter(org.onosproject.store.service.AsyncAtomicValueAdapter) MembershipGroup(org.onosproject.cluster.MembershipGroup) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) NodeId(org.onosproject.cluster.NodeId) Collection(java.util.Collection) VersionServiceAdapter(org.onosproject.core.VersionServiceAdapter) Map(java.util.Map)

Example 7 with TestEventDispatcher

use of org.onosproject.common.event.impl.TestEventDispatcher in project onos by opennetworkinglab.

the class WorkPartitionManagerTest method setUp.

@Before
public void setUp() {
    leadershipService = createMock(LeadershipService.class);
    leadershipService.addListener(anyObject(LeadershipEventListener.class));
    expectLastCall().andDelegateTo(new TestLeadershipService());
    for (int i = 0; i < WorkPartitionManager.NUM_PARTITIONS; i++) {
        expect(leadershipService.runForLeadership(ELECTION_PREFIX + i)).andReturn(null).times(1);
    }
    partitionManager = new WorkPartitionManager().withScheduledExecutor(new NullScheduledExecutor());
    partitionManager.clusterService = new TestClusterService();
    partitionManager.localNodeId = MY_NODE_ID;
    partitionManager.leadershipService = leadershipService;
    partitionManager.eventDispatcher = new TestEventDispatcher();
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) LeadershipService(org.onosproject.cluster.LeadershipService) NullScheduledExecutor(org.onlab.junit.NullScheduledExecutor) LeadershipEventListener(org.onosproject.cluster.LeadershipEventListener) Before(org.junit.Before)

Example 8 with TestEventDispatcher

use of org.onosproject.common.event.impl.TestEventDispatcher in project onos by opennetworkinglab.

the class VirtualNetworkFlowObjectiveManagerTest method setUp.

@Before
public void setUp() throws Exception {
    virtualNetworkManagerStore = new DistributedVirtualNetworkStore();
    CoreService coreService = new TestCoreService();
    TestUtils.setField(virtualNetworkManagerStore, "coreService", coreService);
    TestUtils.setField(virtualNetworkManagerStore, "storageService", storageService);
    virtualNetworkManagerStore.activate();
    flowObjectiveStore = new SimpleVirtualFlowObjectiveStore();
    TestUtils.setField(flowObjectiveStore, "storageService", storageService);
    flowObjectiveStore.activate();
    flowRuleStore = new SimpleVirtualFlowRuleStore();
    flowRuleStore.activate();
    manager = new VirtualNetworkManager();
    manager.store = virtualNetworkManagerStore;
    TestUtils.setField(manager, "coreService", coreService);
    providerRegistryService = new VirtualProviderManager();
    providerRegistryService.registerProvider(flowRuleProvider);
    eventDeliveryService = new TestEventDispatcher();
    NetTestTools.injectEventDispatcher(manager, eventDeliveryService);
    appId = new TestApplicationId("FlowRuleManagerTest");
    testDirectory = new TestServiceDirectory().add(VirtualNetworkStore.class, virtualNetworkManagerStore).add(CoreService.class, coreService).add(EventDeliveryService.class, eventDeliveryService).add(VirtualProviderRegistryService.class, providerRegistryService).add(VirtualNetworkFlowRuleStore.class, flowRuleStore).add(VirtualNetworkFlowObjectiveStore.class, flowObjectiveStore);
    TestUtils.setField(manager, "serviceDirectory", testDirectory);
    manager.activate();
    vnet1 = setupVirtualNetworkTopology(manager, TID1);
    vnet2 = setupVirtualNetworkTopology(manager, TID2);
    service1 = new VirtualNetworkFlowObjectiveManager(manager, vnet1.id());
    service2 = new VirtualNetworkFlowObjectiveManager(manager, vnet2.id());
}
Also used : SimpleVirtualFlowRuleStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowRuleStore) TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) SimpleVirtualFlowObjectiveStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowObjectiveStore) VirtualNetworkFlowObjectiveStore(org.onosproject.incubator.net.virtual.VirtualNetworkFlowObjectiveStore) VirtualProviderRegistryService(org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService) CoreService(org.onosproject.core.CoreService) TestApplicationId(org.onosproject.TestApplicationId) DistributedVirtualNetworkStore(org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) VirtualProviderManager(org.onosproject.incubator.net.virtual.impl.provider.VirtualProviderManager) Before(org.junit.Before)

Example 9 with TestEventDispatcher

use of org.onosproject.common.event.impl.TestEventDispatcher in project onos by opennetworkinglab.

the class VirtualNetworkFlowRuleManagerTest method setUp.

@Before
public void setUp() throws Exception {
    virtualNetworkManagerStore = new DistributedVirtualNetworkStore();
    CoreService coreService = new TestCoreService();
    TestUtils.setField(virtualNetworkManagerStore, "coreService", coreService);
    TestUtils.setField(virtualNetworkManagerStore, "storageService", new TestStorageService());
    virtualNetworkManagerStore.activate();
    flowRuleStore = new SimpleVirtualFlowRuleStore();
    providerRegistryService = new VirtualProviderManager();
    providerRegistryService.registerProvider(provider);
    manager = new VirtualNetworkManager();
    manager.store = virtualNetworkManagerStore;
    TestUtils.setField(manager, "coreService", coreService);
    eventDeliveryService = new TestEventDispatcher();
    NetTestTools.injectEventDispatcher(manager, eventDeliveryService);
    appId = new TestApplicationId("FlowRuleManagerTest");
    testDirectory = new TestServiceDirectory().add(VirtualNetworkStore.class, virtualNetworkManagerStore).add(CoreService.class, coreService).add(VirtualProviderRegistryService.class, providerRegistryService).add(EventDeliveryService.class, eventDeliveryService).add(VirtualNetworkFlowRuleStore.class, flowRuleStore);
    TestUtils.setField(manager, "serviceDirectory", testDirectory);
    manager.activate();
    vnet1 = setupVirtualNetworkTopology(manager, TID1);
    vnet2 = setupVirtualNetworkTopology(manager, TID2);
    vnetFlowRuleService1 = new VirtualNetworkFlowRuleManager(manager, vnet1.id());
    vnetFlowRuleService2 = new VirtualNetworkFlowRuleManager(manager, vnet2.id());
    vnetFlowRuleService1.addListener(listener1);
    vnetFlowRuleService2.addListener(listener2);
    vnetFlowRuleService1.operationsService = MoreExecutors.newDirectExecutorService();
    vnetFlowRuleService2.operationsService = MoreExecutors.newDirectExecutorService();
    vnetFlowRuleService1.deviceInstallers = MoreExecutors.newDirectExecutorService();
    vnetFlowRuleService2.deviceInstallers = MoreExecutors.newDirectExecutorService();
    providerService1 = (VirtualFlowRuleProviderService) providerRegistryService.getProviderService(vnet1.id(), VirtualFlowRuleProvider.class);
    providerService2 = (VirtualFlowRuleProviderService) providerRegistryService.getProviderService(vnet2.id(), VirtualFlowRuleProvider.class);
}
Also used : SimpleVirtualFlowRuleStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowRuleStore) TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) TestStorageService(org.onosproject.store.service.TestStorageService) VirtualProviderRegistryService(org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService) CoreService(org.onosproject.core.CoreService) TestApplicationId(org.onosproject.TestApplicationId) VirtualNetworkFlowRuleStore(org.onosproject.incubator.net.virtual.VirtualNetworkFlowRuleStore) DistributedVirtualNetworkStore(org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) VirtualNetworkStore(org.onosproject.incubator.net.virtual.VirtualNetworkStore) DistributedVirtualNetworkStore(org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore) VirtualProviderManager(org.onosproject.incubator.net.virtual.impl.provider.VirtualProviderManager) Before(org.junit.Before)

Example 10 with TestEventDispatcher

use of org.onosproject.common.event.impl.TestEventDispatcher in project onos by opennetworkinglab.

the class VirtualNetworkGroupManagerTest method setUp.

@Before
public void setUp() throws Exception {
    virtualNetworkManagerStore = new DistributedVirtualNetworkStore();
    CoreService coreService = new TestCoreService();
    TestUtils.setField(virtualNetworkManagerStore, "coreService", coreService);
    TestUtils.setField(virtualNetworkManagerStore, "storageService", new TestStorageService());
    virtualNetworkManagerStore.activate();
    groupStore = new SimpleVirtualGroupStore();
    providerRegistryService = new VirtualProviderManager();
    providerRegistryService.registerProvider(provider);
    manager = new VirtualNetworkManager();
    manager.store = virtualNetworkManagerStore;
    TestUtils.setField(manager, "coreService", coreService);
    eventDeliveryService = new TestEventDispatcher();
    injectEventDispatcher(manager, eventDeliveryService);
    appId = new TestApplicationId("VirtualGroupManagerTest");
    testDirectory = new TestServiceDirectory().add(VirtualNetworkStore.class, virtualNetworkManagerStore).add(CoreService.class, coreService).add(VirtualProviderRegistryService.class, providerRegistryService).add(EventDeliveryService.class, eventDeliveryService).add(VirtualNetworkGroupStore.class, groupStore);
    TestUtils.setField(manager, "serviceDirectory", testDirectory);
    manager.activate();
    vnet1 = setupVirtualNetworkTopology(manager, TID1);
    vnet2 = setupVirtualNetworkTopology(manager, TID2);
    groupManager1 = new VirtualNetworkGroupManager(manager, vnet1.id());
    groupManager2 = new VirtualNetworkGroupManager(manager, vnet2.id());
    groupManager1.addListener(listener1);
    groupManager2.addListener(listener2);
    providerService1 = (VirtualGroupProviderService) providerRegistryService.getProviderService(vnet1.id(), VirtualGroupProvider.class);
    providerService2 = (VirtualGroupProviderService) providerRegistryService.getProviderService(vnet2.id(), VirtualGroupProvider.class);
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) TestStorageService(org.onosproject.store.service.TestStorageService) VirtualProviderRegistryService(org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService) CoreService(org.onosproject.core.CoreService) TestApplicationId(org.onosproject.TestApplicationId) DistributedVirtualNetworkStore(org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore) SimpleVirtualGroupStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualGroupStore) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) VirtualNetworkStore(org.onosproject.incubator.net.virtual.VirtualNetworkStore) DistributedVirtualNetworkStore(org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore) VirtualProviderManager(org.onosproject.incubator.net.virtual.impl.provider.VirtualProviderManager) VirtualNetworkGroupStore(org.onosproject.incubator.net.virtual.VirtualNetworkGroupStore) Before(org.junit.Before)

Aggregations

TestEventDispatcher (org.onosproject.common.event.impl.TestEventDispatcher)41 Before (org.junit.Before)39 TestStorageService (org.onosproject.store.service.TestStorageService)18 TestServiceDirectory (org.onlab.osgi.TestServiceDirectory)13 DistributedVirtualNetworkStore (org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore)13 CoreService (org.onosproject.core.CoreService)8 ComponentConfigAdapter (org.onosproject.cfg.ComponentConfigAdapter)6 VirtualProviderManager (org.onosproject.incubator.net.virtual.impl.provider.VirtualProviderManager)6 DefaultDriver (org.onosproject.net.driver.DefaultDriver)6 TestApplicationId (org.onosproject.TestApplicationId)4 ClusterServiceAdapter (org.onosproject.cluster.ClusterServiceAdapter)4 VirtualProviderRegistryService (org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService)4 SimpleVirtualFlowRuleStore (org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowRuleStore)4 DriverRegistryManager (org.onosproject.net.driver.impl.DriverRegistryManager)4 ClusterService (org.onosproject.cluster.ClusterService)3 VirtualNetworkStore (org.onosproject.incubator.net.virtual.VirtualNetworkStore)3 SimpleVirtualFlowObjectiveStore (org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowObjectiveStore)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Semaphore (java.util.concurrent.Semaphore)2