Search in sources :

Example 1 with MastershipServiceAdapter

use of org.onosproject.mastership.MastershipServiceAdapter in project onos by opennetworkinglab.

the class MastershipProxyManagerTest method testProxyManager.

@Test
public void testProxyManager() throws Exception {
    TestClusterCommunicationServiceFactory clusterCommunicatorFactory = new TestClusterCommunicationServiceFactory();
    NodeId a = NodeId.nodeId("a");
    NodeId b = NodeId.nodeId("b");
    DeviceId deviceId = DeviceId.deviceId("a");
    Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
    ProxyInterfaceImpl proxyInterface1 = new ProxyInterfaceImpl();
    MastershipProxyManager proxyManager1 = new MastershipProxyManager();
    proxyManager1.clusterService = new ClusterServiceAdapter() {

        @Override
        public ControllerNode getLocalNode() {
            return new DefaultControllerNode(a, IpAddress.valueOf(0));
        }
    };
    proxyManager1.clusterCommunicator = clusterCommunicatorFactory.newCommunicationService(a);
    proxyManager1.mastershipService = new MastershipServiceAdapter() {

        @Override
        public NodeId getMasterFor(DeviceId deviceId) {
            return b;
        }
    };
    proxyManager1.activate();
    proxyManager1.registerProxyService(ProxyInterface.class, proxyInterface1, serializer);
    ProxyInterfaceImpl proxyInterface2 = new ProxyInterfaceImpl();
    MastershipProxyManager proxyManager2 = new MastershipProxyManager();
    proxyManager2.clusterService = new ClusterServiceAdapter() {

        @Override
        public ControllerNode getLocalNode() {
            return new DefaultControllerNode(b, IpAddress.valueOf(0));
        }
    };
    proxyManager2.clusterCommunicator = clusterCommunicatorFactory.newCommunicationService(b);
    proxyManager2.mastershipService = new MastershipServiceAdapter() {

        @Override
        public NodeId getMasterFor(DeviceId deviceId) {
            return b;
        }
    };
    proxyManager2.activate();
    proxyManager2.registerProxyService(ProxyInterface.class, proxyInterface2, serializer);
    MastershipProxyFactory<ProxyInterface> proxyFactory1 = proxyManager1.getProxyFactory(ProxyInterface.class, serializer);
    assertEquals("Hello world!", proxyFactory1.getProxyFor(deviceId).sync("Hello world!"));
    assertEquals(1, proxyInterface2.syncCalls.get());
    assertEquals("Hello world!", proxyFactory1.getProxyFor(deviceId).async("Hello world!").join());
    assertEquals(1, proxyInterface2.asyncCalls.get());
    MastershipProxyFactory<ProxyInterface> proxyFactory2 = proxyManager2.getProxyFactory(ProxyInterface.class, serializer);
    assertEquals("Hello world!", proxyFactory2.getProxyFor(deviceId).sync("Hello world!"));
    assertEquals(2, proxyInterface2.syncCalls.get());
    assertEquals("Hello world!", proxyFactory2.getProxyFor(deviceId).async("Hello world!").join());
    assertEquals(2, proxyInterface2.asyncCalls.get());
    proxyManager1.deactivate();
    proxyManager2.deactivate();
}
Also used : DeviceId(org.onosproject.net.DeviceId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) MastershipServiceAdapter(org.onosproject.mastership.MastershipServiceAdapter) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 ClusterServiceAdapter (org.onosproject.cluster.ClusterServiceAdapter)1 ControllerNode (org.onosproject.cluster.ControllerNode)1 DefaultControllerNode (org.onosproject.cluster.DefaultControllerNode)1 NodeId (org.onosproject.cluster.NodeId)1 MastershipServiceAdapter (org.onosproject.mastership.MastershipServiceAdapter)1 DeviceId (org.onosproject.net.DeviceId)1 Serializer (org.onosproject.store.service.Serializer)1