Search in sources :

Example 1 with DummyComponent

use of alma.managertest.DummyComponent in project ACS by ACS-Community.

the class managerClientTest method testGetManyComponents.

public void testGetManyComponents() {
    final String compNameHeader = "DUMMY_COMP_";
    final AtomicInteger sequenceNumber = new AtomicInteger(0);
    totalComponents = 20000;
    totalContainers = 60;
    nThreads = 10;
    class ComponentGetter implements Callable<Boolean> {

        int components, containers;

        ComponentGetter(int components, int containers) {
            this.components = components;
            this.containers = containers;
        }

        public Boolean call() throws Exception {
            int j;
            String compName, contName;
            ComponentSpec corbaSpec = new ComponentSpec();
            corbaSpec.component_type = "IDL:alma/managertest/DummyComponent:1.0";
            corbaSpec.component_code = COMPONENT_SPEC_ANY.value;
            for (int i = 0; i < components; i++) {
                j = sequenceNumber.getAndIncrement();
                compName = compNameHeader + (j + 1);
                contName = "javaContainer" + (j % containers + 1);
                corbaSpec.component_name = compName;
                corbaSpec.container_name = contName;
                //we just loose this reference
                try {
                    ComponentInfo cInfo = null;
                    //Using AcsManagerProxy directly to set the value of Container
                    cInfo = m_acsManagerProxy.get_dynamic_component(m_acsManagerProxy.getManagerHandle(), corbaSpec, false);
                    DummyComponent d = DummyComponentHelper.narrow(cInfo.reference);
                    if (d == null)
                        return false;
                    d.doNothing();
                } catch (Exception e) {
                //do nothing, keep trying other components
                }
            //TODO:here we can give maybe the comp number to see when the program crashed?
            //double ret = d.returnAttributeValue(5);
            //if (ret != 5) return false; 
            }
            return true;
        }
    }
    ExecutorService pool = Executors.newFixedThreadPool(totalComponents, getContainerServices().getThreadFactory());
    CountDownLatch synchCreationStart = new CountDownLatch(totalComponents);
    List<Future<Boolean>> results = new ArrayList<Future<Boolean>>();
    //Components must be multiple of the threads
    try {
        for (int i = 0; i < nThreads; i++) {
            results.add(pool.submit(new ComponentGetter(totalComponents / nThreads, totalContainers)));
        }
        pool.shutdown();
        int n = 0;
        while (!pool.isTerminated()) {
            n++;
            Thread.sleep(60 * 1000);
            m_logger.info("Waiting 60 seconds more. Total now is " + n + " minutes.");
        }
        //}
        for (Future<Boolean> future : results) {
            try {
                Boolean threadResult = future.get();
                if (!threadResult)
                    m_logger.info("The thead couldn't get a reference");
                m_logger.info("CARLI b=" + threadResult);
                assertTrue(threadResult);
            } catch (ExecutionException ex) {
                m_logger.info("Unexpected exception 1" + ex.getCause().toString());
            } catch (Throwable thr) {
                m_logger.info("Unexpected exception 2" + thr.toString());
            }
        }
    } catch (InterruptedException e) {
        assertTrue(false);
        m_logger.info("A timeout occurs when waiting the tasks to finish execution" + e);
    } finally {
        try {
            //sleep 1 minute
            Thread.sleep(60 * 1000);
        } catch (InterruptedException e) {
        }
        //release all components
        for (int i = 0; i < totalComponents; i++) {
            getContainerServices().releaseComponent(compNameHeader + i);
        }
        assertTrue(false);
    }
}
Also used : ArrayList(java.util.ArrayList) ComponentSpec(si.ijs.maci.ComponentSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) Callable(java.util.concurrent.Callable) DummyComponent(alma.managertest.DummyComponent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ComponentInfo(si.ijs.maci.ComponentInfo) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

DummyComponent (alma.managertest.DummyComponent)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ComponentInfo (si.ijs.maci.ComponentInfo)1 ComponentSpec (si.ijs.maci.ComponentSpec)1