/** * 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()); }
public String execute() { if (isDynamic || permanentResults == null) { JMeterContext context = JMeterContextService.getContext(); SampleResult previousResult = context.getPreviousResult(); Sampler currentSampler = context.getCurrentSampler(); return execute(previousResult, currentSampler); } return permanentResults; // $NON-NLS-1$ }
@Override public void run() { try { // Copy in ThreadStarter thread context from calling Thread JMeterContextService.getContext().setVariables(this.context.getVariables()); supplyActiveThreads(); } catch (InterruptedException e) { log.debug("Interrupted", e); } log.debug("Thread starter has done its job"); }
private void injectVariables(JMeterThread jmThread, JMeterContext threadContext) { if (threadContext != null && threadContext.getVariables() != null) { try { Class<JMeterThread> cls = JMeterThread.class; Field vars = cls.getDeclaredField("threadVars"); vars.setAccessible(true); vars.set(jmThread, threadContext.getVariables()); } catch (Throwable ex) { log.warn("Cannot inject variables into parallel thread ", ex); } } }
JMeterVariables vars = jmctx.getVariables(); bshInterpreter.set("prev", jmctx.getPreviousResult());//$NON-NLS-1$ bshInterpreter.set("props", JMeterUtils.getJMeterProperties()); bshInterpreter.set("vars", vars);//$NON-NLS-1$
JMeterVariables vars = jmctx.getVariables(); bindings.put("vars", vars); // $NON-NLS-1$ (this name is fixed) Properties props = JMeterUtils.getJMeterProperties(); Sampler sampler = jmctx.getCurrentSampler(); bindings.put("sampler", sampler); // $NON-NLS-1$ (this name is fixed) SampleResult prev = jmctx.getPreviousResult(); bindings.put("prev", prev); // $NON-NLS-1$ (this name is fixed)
threadContext.setVariables(threadVars); threadContext.setThreadNum(getThreadNum()); threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE); threadContext.setThread(this); threadContext.setThreadGroup(threadGroup); threadContext.setEngine(engine); testTree.traverse(compiler); if (scheduler) { threadContext.setSamplingStarted(true);
break; case CSVDataSetBeanInfo.SHARE_GROUP: alias = fileName+"@"+System.identityHashCode(context.getThreadGroup()); break; case CSVDataSetBeanInfo.SHARE_THREAD: alias = fileName+"@"+System.identityHashCode(context.getThread()); break; default: JMeterVariables threadVars = context.getVariables(); String[] lineValues = {}; try {
} else { log.info("End of file reached: " + getFileName()); if (JMeterContextService.getContext().getThread() != null) { JMeterContextService.getContext().getThread().stop(); final JMeterVariables vars = JMeterContextService.getContext().getVariables(); if (vars != null) { vars.put(getVarName(), rawData);
CompoundVariable function = new CompoundVariable(functionCall); JMeterContext threadContext = JMeterContextService.getContext(); threadContext.setVariables(jMeterVariables); threadContext.setThreadNum(1); threadContext.getVariables().put(JMeterThread.LAST_SAMPLE_OK, "true"); ThreadGroup threadGroup = new ThreadGroup(); threadGroup.setName("FunctionHelper-Dialog-ThreadGroup"); threadContext.setThreadGroup(threadGroup);
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); } }
/** * Create additional SampleEvent in NON Parent Mode */ protected void notifyListeners() { // TODO could these be done earlier (or just once?) JMeterContext threadContext = getThreadContext(); JMeterVariables threadVars = threadContext.getVariables(); SamplePackage pack = (SamplePackage) threadVars.getObject(JMeterThread.PACKAGE_OBJECT); if (pack == null) { // If child of TransactionController is a ThroughputController and TPC does // not sample its children, then we will have this // TODO Should this be at warn level ? log.warn("Could not fetch SamplePackage"); } else { SampleEvent event = new SampleEvent(res, threadContext.getThreadGroup().getName(),threadVars, true); // We must set res to null now, before sending the event for the transaction, // so that we can ignore that event in our sampleOccured method res = null; lnf.notifyListeners(event, pack.getSampleListeners()); } }
public void process() { JMeterContext threadContext = getThreadContext(); String responseString = threadContext.getPreviousResult().getResponseDataAsString(); try { threadContext.getPreviousResult().setResponseData(serialize2(responseString).getBytes("UTF-8")); } catch (Exception e) { log.info("Error while formating response xml - " + e.getMessage()); } }
JMeterTreeListener jMeterTreeListener = new JMeterTreeListener(); jMeterTreeListener.setModel(jMeterTreeModel); JMeterContextService.getContext().setVariables(new JMeterVariables()); StandardJMeterEngine engine = new EmulatorJmeterEngine(); JMeterThreadMonitor monitor = new EmulatorThreadMonitor(); JMeterContextService.getContext().setEngine(engine); HashTree hashtree = new HashTree(); hashtree.add(new LoopController()); JMeterThread thread = new JMeterThread(hashtree, monitor, null); thread.setThreadName("test thread"); JMeterContextService.getContext().setThread(thread); ThreadGroup threadGroup = new org.apache.jmeter.threads.ThreadGroup(); threadGroup.setName("test thread group"); JMeterContextService.getContext().setThreadGroup(threadGroup); JMeterUtils.setProperty("sample_variables", "TEST1,TEST2,TEST3"); // for Flexible File Writer Test JMeterUtils.setProperty("saveservice_properties", "/ss.props");
Sampler sam = context.getCurrentSampler(); SampleResult res = context.getPreviousResult(); HTTPSamplerBase sampler; HTTPSampleResult result; } else { log.info("No further matches found, stopping test"); context.getEngine().askThreadsToStop();
log.info(MSG_STOP_CURRENT_THREAD, getName()); context.getThread().stop(); } else if (target == TEST) { if (action == STOP_NOW) { context.getThread().stop(); if(log.isInfoEnabled()) { log.info("Stopping all threads now from element {}", getName()); context.getEngine().stopTest(); } else { if(log.isInfoEnabled()) { log.info(MSG_STOP_CURRENT_THREAD, getName()); context.getThread().stop(); if(log.isInfoEnabled()) { log.info("Stopping all threads from element {}", getName()); context.getEngine().askThreadsToStop(); context.setTestLogicalAction(TestLogicalAction.START_NEXT_ITERATION_OF_THREAD); } else if (action == START_NEXT_ITERATION_CURRENT_LOOP) { log.info("Switching to next loop iteration from element {}", getName()); context.setTestLogicalAction(TestLogicalAction.START_NEXT_ITERATION_OF_CURRENT_LOOP); } else if (action == BREAK_CURRENT_LOOP) { log.info("Breaking current loop from element {}", getName()); context.setTestLogicalAction(TestLogicalAction.BREAK_CURRENT_LOOP);
private EventProducer getEventProducer() { AbstractThreadGroup tg = getThreadContext().getThreadGroup(); Long seed = randomSeed == null || randomSeed == 0 ? null : randomSeed; return groupEvents.computeIfAbsent(tg, x -> new ConstantPoissonProcessGenerator( () -> PreciseThroughputTimer.this.getThroughput() / throughputPeriod, batchSize, batchThreadDelay, this, exactLimit, allowedThroughputSurplus, seed, true)); }
private void removeThreadGroupFromEngine(AbstractThreadGroup group) { try { StandardJMeterEngine engine = JMeterContextService.getContext().getEngine(); Field groupsField = StandardJMeterEngine.class.getDeclaredField("groups"); groupsField.setAccessible(true); List<AbstractThreadGroup> groups = (List<AbstractThreadGroup>) groupsField.get(engine); groups.remove(group); } catch (ReflectiveOperationException ex) { log.warn("Can not remove DummyThreadGroup from engine", ex); } }
StringBuilder sb = new StringBuilder(75); res.setSuccessful(true); Sampler sampler = context.getPreviousSampler(); SampleResult sr = context.getPreviousResult(); String jmsSelector = getJMSSelector(); if (JMSSampler.PREV_SAMPLER.equals(jmsSelector)
/** * Helper for testing outside of JMeter */ public static void main(String[] args) { LoadGenerator generator = new LoadGenerator(); // Mock out JMeter environment JMeterVariables variables = new JMeterVariables(); JMeterContextService.getContext().setVariables(variables); generator.setFileName("config1.json"); generator.setVariableName("kafka_message"); generator.iterationStart(null); for (Map.Entry<String, Object> entry : variables.entrySet()) { System.out.println(entry.getKey() + " : " + entry.getValue()); } } }