Clover coverage report -
Coverage timestamp: Sat Jul 7 2007 16:41:13 CEST
file stats: LOC: 78   Methods: 1
NCLOC: 36   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RemoteRunnerPoolFiller.java 75% 94.1% 100% 90.9%
coverage coverage
 1    /**
 2    * JTRunner is free software; you can redistribute it and/or modify it under the
 3    * terms of the GNU General Public License as published by the Free Software
 4    * Foundation; either version 2, or (at your option) any later version.
 5    */
 6   
 7    package jtr.remote.pool;
 8   
 9    import java.util.HashMap;
 10    import java.util.Iterator;
 11    import jtr.assigner.UnknownAssignmentPolicyException;
 12    import jtr.config.RunnerConfig;
 13    import jtr.config.TestConfig;
 14    import jtr.pool.RunnerPool;
 15    import jtr.pool.RunnerPoolFiller;
 16    import jtr.remote.cl.JtrRmiClassLoader;
 17    import jtr.remote.test.NodeInfo;
 18    import jtr.runners.IRunner;
 19    import jtr.runners.IRunnerCreationException;
 20    import jtr.runners.RunnerCreator;
 21   
 22    /**
 23    * This class is in charge of instantiating new runners according to the
 24    * provided test-configuration and assiging them to the provided pool for
 25    * later execution.
 26    *
 27    * @author frusso
 28    * @version 4.0
 29    * @since 4.0
 30    */
 31    public class RemoteRunnerPoolFiller extends RunnerPoolFiller {
 32   
 33    /**
 34    * Fills the <code>RunnerPool</code> instance provided with all the required
 35    * runner instances, according to what stated in the <code>testConfig</code>
 36    * instance.
 37    *
 38    * @param testConfig
 39    * @param pool
 40    * @param serverCL
 41    */
 42  1 public static void fillPool(TestConfig testConfig, RunnerPool pool, NodeInfo serverCL) throws IRunnerCreationException, UnknownAssignmentPolicyException {
 43  1 HashMap<String,JtrRmiClassLoader> mem = new HashMap<String,JtrRmiClassLoader>();
 44    // save temporarly the current class-loader
 45  1 ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 46    // let's retrieve all the IRunners configurations
 47  1 Iterator runners = testConfig.getRunners().iterator();
 48  1 while (runners.hasNext()) {
 49  6 RunnerConfig runnerConfig = (RunnerConfig) runners.next();
 50  6 String fqn = runnerConfig.getRunnerFqn();
 51    // let's prepare the class-loader for the concrete runner
 52  6 JtrRmiClassLoader cl = null;
 53  6 if(!mem.containsKey(fqn)) {
 54  6 cl = new JtrRmiClassLoader(serverCL);
 55  6 mem.put(fqn,cl);
 56    } else {
 57  0 cl = mem.get(fqn);
 58    }
 59    // and temporarly set it as the current one in order to download
 60    // the runner's class definition
 61  6 Thread.currentThread().setContextClassLoader(cl);
 62    // runners instantiations
 63    // NOTE: the last argument is null since remotely started runners do not provide a per-run feedback to the active-node
 64  6 IRunner[] iRunners = (IRunner[]) RunnerCreator.create(runnerConfig.getRunnerFqn(), testConfig, runnerConfig.getCount(), null);
 65  6 Thread.currentThread().setContextClassLoader(originalCl);
 66    // let's retrive:
 67    // 1. the parameters assignment policy
 68    // 2. the actual assigner instance
 69    // and then let's perform the assignment
 70  6 runnerConfig.getAssignmetPolicy().getAssigner().assign(iRunners, runnerConfig);
 71    // let's add the runners associated with the current RunnerConfig to
 72    // the pool
 73  6 pool.addAll(iRunners);
 74    }
 75    // restore the original class-loader as the current one
 76  1 Thread.currentThread().setContextClassLoader(originalCl);
 77    }
 78    }