Clover coverage report -
Coverage timestamp: Sat Jul 7 2007 16:41:13 CEST
file stats: LOC: 165   Methods: 6
NCLOC: 116   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RemoteTestRunManager.java 100% 79.1% 100% 83.1%
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.test;
 8   
 9    import java.rmi.RemoteException;
 10    import jtr.assigner.MissingStdParameterException;
 11    import jtr.assigner.UnknownAssignmentPolicyException;
 12    import jtr.config.TestConfig;
 13    import jtr.enterprise.LocatorException;
 14    import jtr.pool.RunnerPool;
 15    import jtr.remote.pool.RemoteRunnerPoolFiller;
 16    import jtr.remote.utils.RmiUtil;
 17    import jtr.runners.IRunnerCreationException;
 18    import jtr.runners.IRunnerParameterized;
 19    import jtr.runners.IRunnerPooled;
 20    import jtr.test.SystemProperties;
 21    import jtr.test.TestFailedException;
 22    import jtr.test.TestOutcomeTable;
 23    import jtr.test.TestRunManager;
 24   
 25    /**
 26    * This specialization of the <code>TestRunManager</code> class is able to locally launch
 27    * test-configurations received by remote JTR-nodes.
 28    *
 29    * @author frusso
 30    * @version 4.0
 31    * @since 4.0
 32    */
 33    public class RemoteTestRunManager extends TestRunManager {
 34   
 35    /**
 36    * Constructor. Requires a test-configuration and a description of the JTR-node
 37    * acting as server class-loader.
 38    *
 39    * @param tc The test-configuration
 40    * @param serverCL the server class-loader
 41    * @param testOutcomeCollector
 42    */
 43  1 public RemoteTestRunManager(TestConfig tc, final NodeInfo serverCL, final NodeInfo testOutcomeCollector) {
 44  1 super(tc);
 45  1 this.serverCL = serverCL;
 46  1 this.testOutcomeCollector = testOutcomeCollector;
 47  1 this.hostNode = new NodeInfo(SystemProperties.TEST_GW_SERVICE_NAME);
 48  1 super.testOutcomeTable = new TestOutcomeTable(hostNode);
 49    }
 50   
 51  1 public void startTest() throws TestFailedException {
 52  1 try {
 53  1 logger.debug("Starting test...");
 54  1 pool = initializePool(testConfig);
 55  1 logger.debug("Pool initialized...");
 56  1 initialPoolSize = pool.size();
 57  1 logger.debug("Initial pool size is " + initialPoolSize + ", starting the threads...");
 58  1 testOutcomeTable.setStartTime();
 59  1 startThreads();
 60  1 logger.debug("... threads all started");
 61    } catch (IRunnerCreationException e) {
 62  0 String msg = "The test failed at run " + partialCount + " due to an IRunnerCreationException";
 63  0 TestFailedException tfe = new TestFailedException(msg, e);
 64  0 logger.fatal(msg, tfe);
 65  0 throw tfe;
 66    } catch (UnknownAssignmentPolicyException e) {
 67  0 String msg = "The test failed at run " + partialCount + " due to an UnknownAssignmentPolicyException";
 68  0 TestFailedException tfe = new TestFailedException(msg, e);
 69  0 logger.fatal(msg, tfe);
 70  0 throw tfe;
 71    } catch (MissingStdParameterException e) {
 72  0 String msg = "The test failed at run " + partialCount + " due to a MissingStdParameterException";
 73  0 TestFailedException tfe = new TestFailedException(msg, e);
 74  0 logger.fatal(msg, tfe);
 75  0 throw tfe;
 76    }
 77    }
 78   
 79  1 protected RunnerPool initializePool(TestConfig testConfig) throws IRunnerCreationException, UnknownAssignmentPolicyException {
 80  1 RunnerPool pool = new RunnerPool(this);
 81  1 logger.debug("Pool of IRunners created...");
 82  1 RemoteRunnerPoolFiller.fillPool(testConfig, pool, serverCL);
 83  1 logger.debug("... and filled in");
 84  1 return pool;
 85    }
 86   
 87    /**
 88    * Starts all the <code>IRunner</code>s for the current epoch of the
 89    * current test
 90    */
 91  50 protected synchronized void startThreads() {
 92  50 logger.info("Starting run # " + partialCount);
 93  50 logger.info("ThreadGroup " + runnersThreadGroup.getName() + " active-threads count before run " + partialCount + " is: " + runnersThreadGroup.activeCount());
 94  50 System.gc();
 95  50 IRunnerPooled[] runners = pool.removeAll();
 96  50 for (int i = 0; i < runners.length; i++) {
 97    /**
 98    * @todo TO BE IMPROVED!
 99    */
 100  2450 if (partialCount == 0) {
 101  49 runners[i].setTestOutcomeTable(testOutcomeTable);
 102  49 logger.info("Set outcomeTable for IRunner " + runners[i].getName());
 103    }
 104  2450 runners[i].setEpoch(partialCount);
 105  2450 Thread thRunner = new Thread(runnersThreadGroup, runners[i], runners[i].getName());
 106   
 107    // the runner must be assigned to the class-loader used for its instantiation
 108  2450 thRunner.setContextClassLoader(runners[i].getClass().getClassLoader());
 109   
 110    // let's launch the runner
 111  2450 thRunner.start();
 112  2450 logger.debug("Created & started thread [" + i + "] " + thRunner.getName());
 113    }
 114  50 logger.debug("ThreadGroup " + runnersThreadGroup.getName() + " active-threads count after starting run " + partialCount + " is: " + runnersThreadGroup.activeCount());
 115  50 partialCount++;
 116  50 runners = null;
 117    }
 118   
 119  2450 public synchronized void backIntoPool(IRunnerParameterized pRunner) {
 120  2450 if (partialCount < epochs) {
 121    // we have (epochs-partialCount) epochs left...
 122  2401 synchronized (pool) {
 123  2401 logger.debug("Received a request for putting an IRunner back into the pool for the next global run");
 124  2401 pool.add(handleReinitialization(pRunner));
 125  2401 logger.debug("Put back into the pool");
 126  2401 if (pool.size() == initialPoolSize) {
 127    // all the irunner-threads are back into the pool, let's
 128    // start the new epoch
 129  49 logger.info("Pool size has grown to " + initialPoolSize + " (the initial pool size)" + "Total run number not reached yet (" + partialCount + " of " + epochs
 130    + "): starting the next one...");
 131  49 startThreads();
 132    }
 133    }
 134    } else {
 135    // epochs are over
 136    // let's put the runner back into the pool without reinitializing
 137    // its parameters
 138  49 pool.add(pRunner);
 139  49 if (++completedRunners != initialPoolSize) {
 140  48 logger.info("Total run number reached (" + partialCount + " of " + epochs + "). Test not completed: " + completedRunners + "/" + initialPoolSize
 141    + " threads are back into the pool, waiting for other " + (initialPoolSize - completedRunners) + " threads");
 142    } else {
 143  1 testOutcomeTable.setEndTime();
 144  1 logger.info("Total run number reached (" + partialCount + " of " + epochs + "): test completed!");
 145  1 disposeResources();
 146  1 sendTestOutcome(testOutcomeTable);
 147    }
 148    }
 149    }
 150   
 151  1 private void sendTestOutcome(TestOutcomeTable outcome) {
 152  1 try {
 153  1 TestOutcomeCollector collector = (TestOutcomeCollector) RmiUtil.lookupServer(testOutcomeCollector);
 154  1 collector.provideTestOutcome(hostNode,outcome);
 155    } catch (RemoteException e) {
 156  0 logger.error("Unable to provide the test outcome to "+SystemProperties.TEST_OUTCOME_COLLECTOR_SERVICE_NAME,e);
 157    } catch (LocatorException e) {
 158  0 logger.fatal("Unable to connect to "+testOutcomeCollector,e);
 159    }
 160    }
 161   
 162    private NodeInfo serverCL;
 163    private NodeInfo testOutcomeCollector;
 164    private NodeInfo hostNode;
 165    }