@Override public void awaitStart() { int waitingTime = doRampUp(); int threadNumber = 0; if (Grinder.grinder != null) { threadNumber = Math.max(Grinder.grinder.getThreadNumber(), 0); } synchronized (m_threadEventCondition) { m_numberAwaitingStart++; m_numberRunning++; m_threadEventCondition.notifyAll(); } if (Grinder.grinder != null) { Grinder.grinder.getLogger().info("thread-{} is invoked after {} ms sleep", threadNumber, waitingTime); } // m_started.await(true); }
/** * Get this thread unique id among all threads in the all agents. * * @return unique id b/w from 0 to total thread count. * @since 3.2.3 */ public static int getThreadUniqId() { InternalScriptContext grinder = getGrinderInstance(); GrinderProperties properties = grinder.getProperties(); if (properties != null) { int totalProcessCount = properties.getInt("grinder.processes", 1); int totalThreadCount = properties.getInt("grinder.threads", 1); int agentNumber = grinder.getAgentNumber(); int processNumber = grinder.getProcessNumber(); int threadNumber = grinder.getThreadNumber(); // Calc the current thread's unique id return (agentNumber * totalProcessCount * totalThreadCount) + (processNumber * totalThreadCount) + threadNumber; } return 0; }
@Override public void evaluate() throws Throwable { if (checkRun(Grinder.grinder.getRunNumber())) { statement.evaluate(); } }
private boolean isScriptValidation() { try { return Grinder.grinder.getProperties().getBoolean("grinder.script.validation", false); } catch (Exception e) { return false; } }
@Override public void testFailure(Failure failure) throws Exception { // Skip Generic Shutdown... It's not failure. Throwable rootCause = exceptionProcessor.getRootCause(failure.getException()); if (exceptionProcessor.isGenericShutdown(rootCause)) { return; } Grinder.grinder.getLogger().error(failure.getMessage(), exceptionProcessor.filterException(rootCause)); // In case of exception, set test failed. try { StatisticsForTest forLastTest = Grinder.grinder.getStatistics().getForLastTest(); if (forLastTest != null) { forLastTest.setSuccess(false); } } catch (Throwable t) { noOp(); } } });
@BeforeThread public void beforeThread() throws InvalidContextException { grinder.getStatistics().setDelayReports(true); }
private static InternalScriptContext getGrinderInstance() { InternalScriptContext grinder = Grinder.grinder; if (grinder == null || grinder.getThreadNumber() == -1) { throw new RuntimeException("This method should be called in the worker thread context."); } return grinder; }
/** * Creates a new <code>Test</code> instance. * * @param number Test number. * @param description Test description. */ public Test(int number, String description) { m_number = number; m_description = description; m_registeredTest = Grinder.grinder.getTestRegistry().register(this); }
/** * Get the process count per an agent. * * @return process assigned per an agent */ public static int getProcessCount() { return getGrinderInstance().getProperties().getInt("grinder.processes", 1); }
@Test @RunRate(10) public void doTest2() throws Exception { grinder.getStatistics().setDelayReports(true); HTTPResponse result = request.GET("http://www.google.co.kr"); if (result.getStatusCode() != 200) { grinder.getStatistics().getForLastTest().setSuccess(false); } else { grinder.getStatistics().getForLastTest().setSuccess(true); } }
private int doRampUp(int rampUpInterval, int rampUpStep, int rampUpInitialThread, int rampUpInitialSleep) { int threadNumber = 0; int waitingTime; if (Grinder.grinder != null) { threadNumber = Math.max(Grinder.grinder.getThreadNumber(), 0); } try { waitingTime = getWaitingTime(rampUpInterval, rampUpStep, rampUpInitialThread, rampUpInitialSleep, threadNumber); if (waitingTime != 0) { if (Grinder.grinder != null) { Grinder.grinder.getLogger().info("thread-{} is sleeping {} ms for ramp-up", threadNumber, waitingTime); } sleeper.sleepNormal(waitingTime, 0); } return waitingTime; } catch (Sleeper.ShutdownException e) { throw new RuntimeException(e); } }
/** * Get the total agent count. * * @return agent count. */ public static int getAgentCount() { return getGrinderInstance().getProperties().getInt("grinder.agents", 1); }
@RunRate(50) @Test public void doTest() throws Exception { HTTPResponse result = request.GET("http://www.naver.com"); if (result.getStatusCode() != 200) { grinder.getStatistics().getForLastTest().setSuccess(false); } else { grinder.getStatistics().getForLastTest().setSuccess(true); } }
/** * Get the thread count per a process. * * @return thread count assigned per a process */ public static int getThreadCount() { return getGrinderInstance().getProperties().getInt("grinder.threads", 1); } }
protected int doRampUp() { InternalScriptContext grinder = Grinder.grinder; if (grinder != null) { GrinderProperties properties = grinder.getProperties(); int rampUpInterval = properties.getInt(GRINDER_PROP_THREAD_INCREMENT_INTERVAL, 0); int rampUpStep = properties.getInt(GRINDER_PROP_THREAD_INCREMENT, 0); int rampUpInitialThread = properties.getInt(GRINDER_PROP_INITIAL_PROCESS, 0); int rampUpInitialSleep = properties.getInt(GRINDER_PROP_INITIAL_THREAD_SLEEP_TIME, 0); return doRampUp(rampUpInterval, rampUpStep, rampUpInitialThread, rampUpInitialSleep); } return 0; }