Search in sources :

Example 1 with InstrumentedFutureTask

use of acs.benchmark.util.ConcurrentComponentAccessUtil.InstrumentedFutureTask in project ACS by ACS-Community.

the class StressStartComponents method testStartComponents.

/**
	 * The test concurrently starts {@link StressStartComponents#totComponentsToStart} components
	 * in {@link StressStartComponents#totThreads} threads.
	 * 
	 * @throws Exception
	 */
public void testStartComponents() throws Exception {
    startContainers();
    ContainerData[] containers = new ContainerData[startedContainers.size()];
    startedContainers.toArray(containers);
    // The names of the components to start and stop
    Vector<String> componentNames = new Vector<String>(totComponentsToStart);
    // Start the components
    Vector<Future<MountOperations>> tasks = new Vector<Future<MountOperations>>();
    // to cycle through containers in the array
    int c = 0;
    long startLoadTime = System.currentTimeMillis();
    for (int t = 0; t < totComponentsToStart; t++) {
        String name = componentNameTrailing + t;
        String contName = containers[c].name;
        c = (c + 1) % containers.length;
        logger.info("Starting " + name);
        ComponentSpec spec = new ComponentSpec(name, "IDL:alma/testManager/Mount:1.0", "mount", contName);
        tasks.add(componentAccessUtil.getDynamicComponentConcurrent(spec, MountOperations.class));
        componentNames.addElement(name);
    }
    assertEquals("The size of the names and the components to start does not match!", totComponentsToStart, componentNames.size());
    // wait for the termination of all the tasks
    int n = 1;
    logger.info("Waiting termination of " + tasks.size() + " tasks");
    for (Future<MountOperations> ft : tasks) {
        try {
            ft.get(5, TimeUnit.MINUTES);
            if (ft instanceof InstrumentedFutureTask<?>) {
                InstrumentedFutureTask ift = (InstrumentedFutureTask) ft;
                logTime("Component loaded in ", ift.getExecutionTime());
            }
            logger.info("A task got the component. Number of terminated tasks: " + n);
        } catch (ExecutionException ee) {
            logger.severe("Exception returned from task while getting component: " + ee.getMessage());
        } catch (CancellationException ce) {
            logger.warning("Task cancelled while getting component: " + ce.getMessage());
        } catch (TimeoutException te) {
            logger.severe("Timeout from task while getting component: " + te.getMessage());
        } finally {
            n++;
        }
    }
    long endLoadTime = System.currentTimeMillis();
    logTime("The threads got all the components in ", endLoadTime - startLoadTime);
    // In this case a message is logged and will trigger a failure in the tat test
    if (endLoadTime - startLoadTime > 120 * 1000) {
        logTime(AcsLogLevel.WARNING, "It seems that the load time of the components was too slow (expected<2min): ", endLoadTime - startLoadTime);
    }
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
    }
    assertEquals("Num of requested components mismatch", totComponentsToStart, adminOperations.getNumOfRequestedComps());
    assertEquals("Num of activated component mismatch", totComponentsToStart, adminOperations.getNumOfActivatedComps());
    logger.info("Releasing components");
    // release all the components in parallel
    long startTime = System.currentTimeMillis();
    // Randomly sort the collection to randomly relase components
    Collections.shuffle(componentNames);
    componentAccessUtil.releaseComponents(componentNames, true);
    long endTime = System.currentTimeMillis();
    logTime("Components released in ", endTime - startTime);
    // In this case a message is logged and will trigger a failure in the tat test
    if (endTime - startTime > 120 * 1000) {
        logTime(AcsLogLevel.WARNING, "It seems that the unload time of the components was too slow (expected<2min): ", endTime - startTime);
    }
    // Wait for th ennotification of componentes releases deactivations before shutting down
    // the containers
    startTime = System.currentTimeMillis();
    while (adminOperations.getNumOfDeactivatedComps() != totComponentsToStart && System.currentTimeMillis() < startTime + 120000) {
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            continue;
        }
    }
    if (adminOperations.getNumOfDeactivatedComps() != totComponentsToStart) {
        logger.log(AcsLogLevel.ERROR, "Deactivated " + adminOperations.getNumOfDeactivatedComps() + " instead of " + totComponentsToStart);
    } else {
        logger.log(AcsLogLevel.INFO, "All components deactivated");
    }
    startTime = System.currentTimeMillis();
    while (adminOperations.getNumOfReleasedComps() != totComponentsToStart && System.currentTimeMillis() < startTime + 120000) {
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            continue;
        }
    }
    if (adminOperations.getNumOfReleasedComps() != totComponentsToStart) {
        logger.log(AcsLogLevel.ERROR, "Released " + adminOperations.getNumOfReleasedComps() + " instead of " + totComponentsToStart);
    } else {
        logger.log(AcsLogLevel.INFO, "All components released");
    }
    logger.info("Stopping containers");
    // Stop containers
    startTime = System.currentTimeMillis();
    stopContainers();
    endTime = System.currentTimeMillis();
    logTime("Containers stopped in ", endTime - startTime);
}
Also used : ComponentSpec(si.ijs.maci.ComponentSpec) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) InstrumentedFutureTask(acs.benchmark.util.ConcurrentComponentAccessUtil.InstrumentedFutureTask) CancellationException(java.util.concurrent.CancellationException) MountOperations(alma.testManager.MountOperations) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Vector(java.util.Vector) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

InstrumentedFutureTask (acs.benchmark.util.ConcurrentComponentAccessUtil.InstrumentedFutureTask)1 MountOperations (alma.testManager.MountOperations)1 Vector (java.util.Vector)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 ComponentSpec (si.ijs.maci.ComponentSpec)1