Search in sources :

Example 1 with ProActiveRuntimeImpl

use of org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl in project scheduling by ow2-proactive.

the class topologyConcurrencyTest method action.

@Test
public void action() throws Exception {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();
    Logger.getLogger(TopologyManager.class).setLevel(Level.DEBUG);
    PAResourceManagerProperties.RM_TOPOLOGY_PINGER.updateProperty(HostsPinger.class.getName());
    PAResourceManagerProperties.RM_TOPOLOGY_ENABLED.updateProperty("true");
    PAResourceManagerProperties.RM_TOPOLOGY_DISTANCE_ENABLED.updateProperty("false");
    final ProActiveRuntimeImpl runtime = mock(ProActiveRuntimeImpl.class);
    when(runtime.getVMInformation()).thenReturn(new DummyVMInfo());
    final TopologyManager manager = new TopologyManager();
    List<Callable<Boolean>> calls = new ArrayList<>(total);
    // first set of tasks, add nodes and remove them
    for (int i = 0; i < total; i++) {
        final int j = i;
        calls.add(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                try {
                    int index = j - (j % collisionSize);
                    Node node = new NodeImpl(runtime, baseUrl + index);
                    if ((j % (collisionSize / 2)) == 0) {
                        manager.addNode(node);
                    } else {
                        // more remove than add, to try to reproduce empty list problems
                        manager.removeNode(node);
                    }
                    // launch some selections on the node just added or removed to trigger ConcurrentModficationExceptions if any
                    NodeSet set = manager.getHandler(TopologyDescriptor.SINGLE_HOST).select(1, Collections.singletonList(node));
                    System.out.println(set);
                } catch (Exception e) {
                    e.printStackTrace();
                    return false;
                }
                return true;
            }
        });
    }
    List<Future<Boolean>> futures = s.invokeAll(calls);
    for (Future<Boolean> fut : futures) {
        Assert.assertTrue(fut.get());
    }
    calls = new ArrayList<>(nbThreads * nodeFactor);
    // second set of task remove all nodes created
    for (int i = 0; i < total; i += collisionSize) {
        final int j = i;
        calls.add(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                try {
                    int index = j;
                    Node node = new NodeImpl(runtime, baseUrl + index);
                    manager.removeNode(node);
                    NodeSet set = manager.getHandler(TopologyDescriptor.SINGLE_HOST).select(1, Collections.singletonList(node));
                    System.out.println(set);
                } catch (Exception e) {
                    e.printStackTrace();
                    return false;
                }
                return true;
            }
        });
    }
    futures = s.invokeAll(calls);
    for (Future<Boolean> fut : futures) {
        Assert.assertTrue(fut.get());
    }
    System.out.println(manager.getTopology().getHosts());
    // finally verify that the nodes on host structure is empty (null)
    Assert.assertNull(manager.getNodesOnHost(DummyVMInfo.address));
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) NodeImpl(org.objectweb.proactive.core.node.NodeImpl) Node(org.objectweb.proactive.core.node.Node) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) TopologyManager(org.ow2.proactive.resourcemanager.selection.topology.TopologyManager) HostsPinger(org.ow2.proactive.resourcemanager.frontend.topology.pinging.HostsPinger) Future(java.util.concurrent.Future) ProActiveRuntimeImpl(org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 Future (java.util.concurrent.Future)1 Test (org.junit.Test)1 Node (org.objectweb.proactive.core.node.Node)1 NodeImpl (org.objectweb.proactive.core.node.NodeImpl)1 ProActiveRuntimeImpl (org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl)1 HostsPinger (org.ow2.proactive.resourcemanager.frontend.topology.pinging.HostsPinger)1 TopologyManager (org.ow2.proactive.resourcemanager.selection.topology.TopologyManager)1 NodeSet (org.ow2.proactive.utils.NodeSet)1