/** Initialize the thread. */ public void prepare() throws BenchmarkException { try { scenario.prepare(); } catch (Exception e) { String msg = "Scenario init() method call failed: " + scenario.getClass(); logger.debug(msg, e); throw new BenchmarkException(msg, e); } }
/** Run operations until we are done. */ public void run() { if (logger.isDebugEnabled()) logger.debug("Starting thread: " + Thread.currentThread().getName()); long start = System.currentTimeMillis(); long end; iterationCount = 0; try { String boundType = wrapper.getBound(); if (ConfigWrapper.METHOD_ITERATIONS.equals(boundType)) { long testIterations = wrapper.getIterations(); if (logger.isDebugEnabled()) { logger.debug("Running scenario using iterations: iterations=" + testIterations); } while (iterationCount < testIterations) { iterationCount++; logger.debug("Invoking next iteration, count=" + iterationCount); try { scenario.iterate(iterationCount); } catch (SQLException e) { this.sqlExceptionCount++; if (logger.isDebugEnabled()) logger.debug("Caught SQLException in scenario", e); } } logger.debug("Iteration count exceeded; terminating iterations"); } else if (ConfigWrapper.METHOD_DURATION.equals(boundType)) { long testDurationMillis = wrapper.getDuration() * 1000; if (logger.isDebugEnabled()) { logger.debug( "Running scenario using duration in seconds: duration=" + testDurationMillis / 1000); } end = System.currentTimeMillis(); while ((end - start) < testDurationMillis) { iterationCount++; logger.debug("Invoking next iteration, count=" + iterationCount); try { scenario.iterate(iterationCount); } catch (SQLException e) { this.sqlExceptionCount++; if (logger.isDebugEnabled()) logger.debug("Caught SQLException in scenario", e); } end = System.currentTimeMillis(); } logger.debug("Time limit exceeded; terminating iterations"); } else throw new BenchmarkException("Unrecognized bound type: " + boundType); } catch (Exception e) { logger.error( "Scenario thread " + Thread.currentThread().getName() + " failed with exception", e); exception = e; } end = System.currentTimeMillis(); this.elapsed = end - start; if (logger.isDebugEnabled()) logger.debug("Ending thread: " + Thread.currentThread().getName()); }