public JMeterThreadParallel(HashTree test, JMeterThreadMonitor monitor, ListenerNotifier notifier, boolean generateParent) { super(test, monitor, notifier); this.generateParent = generateParent; parentThread = JMeterContextService.getContext().getThread(); if (parentThread == null) { throw new NullPointerException(); } try { copyCompilerFromParent(); } catch (IllegalAccessException | NoSuchFieldException e) { throw new RuntimeException(e); } }
/** * Update the worker thread jmeter context with the main thread one * @param isInit if true the context a full copy is done, if false only update is done */ private void syncContext(boolean isInit) { // jmeter context synchronisation JMeterContext current = JMeterContextService.getContext(); JMeterContext ctx = this.getThreadContext(); if (isInit) { current.setCurrentSampler(ctx.getCurrentSampler()); current.setEngine(ctx.getEngine()); current.setRestartNextLoop(ctx.isRestartNextLoop()); current.setSamplingStarted(ctx.isSamplingStarted()); current.setThread(ctx.getThread()); current.setThreadGroup(ctx.getThreadGroup()); current.setThreadNum(ctx.getThreadNum()); } current.setVariables(ctx.getVariables()); current.setPreviousResult(ctx.getPreviousResult()); //current.getSamplerContext().putAll(ctx.getSamplerContext()); }
private HashTree getSubTree(TestElement te) { try { Field field = JMeterThread.class.getDeclaredField("testTree"); field.setAccessible(true); JMeterThread parentThread = JMeterContextService.getContext().getThread(); if (parentThread == null) { log.error("Current thread is null."); throw new NullPointerException(); } HashTree testTree = (HashTree) field.get(parentThread); SearchByClass<?> searcher = new SearchByClass<>(te.getClass()); testTree.traverse(searcher); return searcher.getSubTree(te); } catch (ReflectiveOperationException ex) { log.warn("Can not get sub tree for Test element " + te.getName(), ex); return null; } }
/** * Update the worker thread jmeter context with the main thread one * @param isInit if true the context a full copy is done, if false only update is done */ private void syncContext(boolean isInit) { // jmeter context synchronisation JMeterContext current = JMeterContextService.getContext(); JMeterContext ctx = this.getThreadContext(); if (isInit) { current.setCurrentSampler(ctx.getCurrentSampler()); current.setEngine(ctx.getEngine()); current.setRestartNextLoop(ctx.isRestartNextLoop()); current.setSamplingStarted(ctx.isSamplingStarted()); current.setThread(ctx.getThread()); current.setThreadGroup(ctx.getThreadGroup()); current.setThreadNum(ctx.getThreadNum()); } current.setVariables(ctx.getVariables()); current.setPreviousResult(ctx.getPreviousResult()); //current.getSamplerContext().putAll(ctx.getSamplerContext()); } @Override
@Override public long delay() { double nextEvent; EventProducer events = getEventProducer(); synchronized (events) { nextEvent = events.next(); } long delay = (long) (nextEvent * TimeUnit.SECONDS.toMillis(1) + testStarted - System.currentTimeMillis()); if (log.isDebugEnabled()) { log.debug("Calculated delay is {}", delay); } delay = Math.max(0, delay); long endTime = getThreadContext().getThread().getEndTime(); if (endTime > 0 && System.currentTimeMillis() + delay > endTime) { throw new JMeterStopThreadException("The thread is scheduled to stop in " + (System.currentTimeMillis() - endTime) + " ms" + " and the throughput timer generates a delay of " + delay + "." + " JMeter (as of 4.0) does not support interrupting of sleeping threads, thus terminating the thread manually." ); } return delay; }
/** * Update the worker thread jmeter context with the main thread one * @param isInit if true the context a full copy is done, if false only update is done */ private void syncContext(boolean isInit) { // jmeter context synchronisation JMeterContext current = JMeterContextService.getContext(); JMeterContext ctx = this.getThreadContext(); if (isInit) { current.setCurrentSampler(ctx.getCurrentSampler()); current.setEngine(ctx.getEngine()); current.setRestartNextLoop(ctx.isRestartNextLoop()); current.setSamplingStarted(ctx.isSamplingStarted()); current.setThread(ctx.getThread()); current.setThreadGroup(ctx.getThreadGroup()); current.setThreadNum(ctx.getThreadNum()); } current.setVariables(ctx.getVariables()); current.setPreviousResult(ctx.getPreviousResult()); //current.getSamplerContext().putAll(ctx.getSamplerContext()); }
/** * Adjust delay so that initialDelay does not exceed end of test * @param initialDelay initial delay in millis * @return initialDelay or adjusted delay */ public long adjustDelay(final long initialDelay) { JMeterThread thread = JMeterContextService.getContext().getThread(); long endTime = thread != null ? thread.getEndTime() : 0; return adjustDelay(initialDelay, endTime); }
public void startNextLoop() { JMeterThread thread = JMeterContextService.getContext().getThread(); if (owner instanceof ArrivalsThreadGroup) { getOwnerAsArrivals().abandonFact(thread, iterationNo); } if (!moveToPool(thread)) { setDone(true); } }
public void startNextLoop() { JMeterThread thread = JMeterContextService.getContext().getThread(); if (owner instanceof ArrivalsThreadGroup) { getOwnerAsArrivals().abandonFact(thread, iterationNo); if (!moveToPool(thread)) { setDone(true); } } else { reInitialize(); } }
@Override public Sampler next() { if (!owner.isRunning()) { setDone(true); } else if (!hasArrived) { if (owner.isLimitReached()) { throw new IllegalStateException("Should not have more iterations"); } hasArrived = true; iterationNo++; if (owner instanceof ArrivalsThreadGroup) { getOwnerAsArrivals().arrivalFact(JMeterContextService.getContext().getThread(), iterationNo); } } return super.next(); }
@Override public Sampler next() { if (owner.isLimitReached()) { setDone(true); } else if (!hasArrived) { if (owner.isLimitReached()) { throw new IllegalStateException("Should not have more iterations"); } hasArrived = true; iterationNo++; if (owner instanceof ArrivalsThreadGroup) { getOwnerAsArrivals().arrivalFact(JMeterContextService.getContext().getThread(), iterationNo); } } return super.next(); }
log.info(MSG_STOP_CURRENT_THREAD, getName()); context.getThread().stop(); } else if (target == TEST) { if (action == STOP_NOW) { log.info(MSG_STOP_CURRENT_THREAD, getName()); context.getThread().stop(); if(log.isInfoEnabled()) { log.info("Stopping all threads now from element {}", getName()); log.info(MSG_STOP_CURRENT_THREAD, getName()); context.getThread().stop(); if(log.isInfoEnabled()) { log.info("Stopping all threads from element {}", getName());
@Override public Sampler next() { if (owner.isLimitReached()) { setDone(true); } else if (!hasArrived) { if (owner.isLimitReached()) { throw new IllegalStateException("Should not have more iterations"); } hasArrived = true; iterationNo++; if (owner instanceof ArrivalsThreadGroup) { getOwnerAsArrivals().arrivalFact(JMeterContextService.getContext().getThread(), iterationNo); } } return super.next(); }
public void startNextLoop() { JMeterThread thread = JMeterContextService.getContext().getThread(); if (owner instanceof ArrivalsThreadGroup) { getOwnerAsArrivals().abandonFact(thread, iterationNo); if (!moveToPool(thread)) { setDone(true); } } else { reInitialize(); } }
public void initialize() throws Exception { URI uri = getUri(); WebSocketClient webSocketClient = webSocketClientFactory.newWebSocketClient(); final WebSocketSampler parent = this; final String threadName = JMeterContextService.getContext().getThread().getThreadName(); final Pattern regex = (getRecvMessage() != null) ? Pattern.compile(getRecvMessage()) : null; Future<WebSocket.Connection> futureConnection = webSocketClient.open(uri, new WebSocket.OnTextMessage() { @Override public void onMessage(String s) { synchronized (parent) { if (regex == null || regex.matcher(s).find()) { responseMessage = s; parent.notify(); } } } @Override public void onOpen(Connection connection) { log.debug("Connect " + threadName); } @Override public void onClose(int i, String s) { log.debug("Disconnect " + threadName); } }); connection = futureConnection.get(); samplerConnections.add(connection); initialized = true; } @Override
@Override protected Sampler nextIsNull() throws NextIsNullException { JMeterThread thread = JMeterContextService.getContext().getThread(); if (owner instanceof ArrivalsThreadGroup) { getOwnerAsArrivals().completionFact(thread, iterationNo); } long iLimit = owner.getIterationsLimitAsLong(); if (owner.isLimitReached()) { log.info("Test limit reached, thread is done: " + thread.getThreadName()); setDone(true); return null; } else if (iLimit > 0 && iterationNo >= iLimit) { log.info("Iteration limit reached, thread is done: " + thread.getThreadName()); setDone(true); return null; } else if (owner instanceof ConcurrencyThreadGroup && ((ConcurrencyThreadGroup) owner).tooMuchConcurrency()) { log.info("Need to decrease concurrency, thread is done: " + thread.getThreadName()); setDone(true); return null; } else if (owner instanceof ArrivalsThreadGroup) { moveToPool(thread); return super.nextIsNull(); } else { reInitialize(); return next(); } }
@Override protected Sampler nextIsNull() throws NextIsNullException { JMeterThread thread = JMeterContextService.getContext().getThread(); if (owner instanceof ArrivalsThreadGroup) { getOwnerAsArrivals().completionFact(thread, iterationNo); } long iLimit = owner.getIterationsLimitAsLong(); if (owner.isLimitReached()) { log.info("Test limit reached, thread is done: " + thread.getThreadName()); setDone(true); return null; } else if (iLimit > 0 && iterationNo >= iLimit) { log.info("Iteration limit reached, thread is done: " + thread.getThreadName()); setDone(true); return null; } else if (owner instanceof ConcurrencyThreadGroup && ((ConcurrencyThreadGroup) owner).tooMuchConcurrency()) { log.info("Need to decrease concurrency, thread is done: " + thread.getThreadName()); setDone(true); return null; } else if (owner instanceof ArrivalsThreadGroup) { moveToPool(thread); return super.nextIsNull(); } else { reInitialize(); return next(); } }
@Override protected Sampler nextIsNull() throws NextIsNullException { JMeterThread thread = JMeterContextService.getContext().getThread(); if (owner instanceof ArrivalsThreadGroup) { getOwnerAsArrivals().completionFact(thread, iterationNo); } long iLimit = owner.getIterationsLimitAsLong(); if (owner.isLimitReached()) { log.info("Test limit reached, thread is done: " + thread.getThreadName()); setDone(true); return null; } else if (iLimit > 0 && iterationNo >= iLimit) { log.info("Iteration limit reached, thread is done: " + thread.getThreadName()); setDone(true); return null; } else if (owner instanceof ConcurrencyThreadGroup && ((ConcurrencyThreadGroup) owner).tooMuchConcurrency()) { log.info("Need to decrease concurrency, thread is done: " + thread.getThreadName()); setDone(true); return null; } else if (owner instanceof ArrivalsThreadGroup) { moveToPool(thread); return super.nextIsNull(); } else { reInitialize(); return next(); } }