@Override public Object getObject(String key) { return variables.getObject(key); }
public static MongoDB getMongoDB(String source) { Object mongoSource = JMeterContextService.getContext().getVariables().getObject(source); if(mongoSource == null) { throw new IllegalStateException("mongoSource is null"); } else { if(mongoSource instanceof MongoDB) { return (MongoDB)mongoSource; } else { throw new IllegalStateException("Variable:"+ source +" is not a MongoDB instance, class:"+mongoSource.getClass()); } } }
/** * {@inheritDoc} */ @Override public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { JMeterVariables vars = getVariables(); String res = ((CompoundVariable) values[0]).execute().trim(); if (vars != null) { Object var = vars.getObject(res); if (var != null) { return "1"; } } return "0"; }
/** * Configure the UserToken so that the SSL context is reused * See <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=57804">Bug 57804</a> * @param jMeterVariables {@link JMeterVariables} * @param localContext {@link HttpContext} */ private void setupClientContextBeforeSample(JMeterVariables jMeterVariables, HttpContext localContext) { Object userToken = null; // During recording JMeterContextService.getContext().getVariables() is null if(jMeterVariables != null) { userToken = jMeterVariables.getObject(JMETER_VARIABLE_USER_TOKEN); } if(userToken != null) { log.debug("Found user token:{} as JMeter variable:{}, storing it in HttpContext", userToken, JMETER_VARIABLE_USER_TOKEN); localContext.setAttribute(HttpClientContext.USER_TOKEN, userToken); } else { // It would be better to create a ClientSessionManager that would compute this value // for now it can be Thread.currentThread().getName() but must be changed when we would change // the Thread per User model String userId = Thread.currentThread().getName(); log.debug("Storing in HttpContext the user token: {}", userId); localContext.setAttribute(HttpClientContext.USER_TOKEN, userId); } }
/** * {@inheritDoc} */ @Override public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { JMeterVariables vars = getVariables(); String res = ((CompoundVariable) values[0]).execute().trim(); if (vars != null) { Object var = vars.getObject(res); if (var != null) { return "1"; } } return "0"; }
private WebDriver getWebDriver() { return (WebDriver) getThreadContext().getVariables().getObject(WebDriverConfig.BROWSER); }
/** * Get access to MongoDB object * @param varName String MongoDB source * @param dbName Mongo DB database name * @param login name to use for login * @param password password to use for login * @return {@link DB} */ public static DB getDBFromSource(String varName, String dbName, String login, String password) { MongoDB mongodb = (MongoDB) JMeterContextService.getContext().getVariables().getObject(varName); if(mongodb==null) { throw new IllegalStateException("You didn't define variable:"+varName +" using MongoDB Source Config (property:MongoDB Source)"); } return mongodb.getDB(dbName, login, password); } }
/** * Check if there are any matching entries * * @return whether any entries in the list */ private boolean emptyList() { JMeterContext context = getThreadContext(); StringBuilder builder = new StringBuilder( getInputVal().length()+getSeparator().length()+3); String inputVariable = builder.append(getInputVal()) .append(getSeparator()) .append(Integer.toString(loopCount+1)).toString(); if (context.getVariables().getObject(inputVariable) != null) { return false; } if (log.isDebugEnabled()) { log.debug("{} No entries found - null first entry: {}", getName(), inputVariable); } return true; }
JMeterContextService.getContext().getVariables().getObject(poolName); if (poolObject == null) { throw new SQLException("No pool found named: '" + poolName + "', ensure Variable Name matches Variable Name of JDBC Connection Configuration");
@Override public void testEnded() { if(log.isDebugEnabled()) { log.debug(getTitle() + " testEnded"); } ((MongoDB)getThreadContext().getVariables().getObject(getSource())).clear(); }
/** * Gets a textual description about the pools configuration. * * @param poolName * Pool name * @return Connection information on {@code poolName} or a short message, * when the JMeter object specified by {@code poolName} is not a * pool * @throws SQLException * when an error occurs, while gathering information about the * connection */ public static String getConnectionInfo(String poolName) throws SQLException{ Object poolObject = JMeterContextService.getContext().getVariables().getObject(poolName); if (poolObject instanceof DataSourceComponentImpl) { DataSourceComponentImpl pool = (DataSourceComponentImpl) poolObject; return pool.getConnectionInfo(); } else { return "Object:" + poolName + " is not of expected type '" + DataSourceComponentImpl.class.getName() + "'"; } }
/** * Tests that JMeterVariables contain inputVal_<count>, if not we can stop iterating */ private boolean endOfArguments() { JMeterContext context = getThreadContext(); String inputVariable = getInputVal() + getSeparator() + (loopCount + 1); if (context.getVariables().getObject(inputVariable) != null) { if(log.isDebugEnabled()) { log.debug("{} : Found in vars:{}, not end of Arguments", getName(), inputVariable); } return false; } if(log.isDebugEnabled()) { log.debug("{} : Did not find in vars:{}, End of Arguments reached", getName(), inputVariable); } return true; }
/** * {@inheritDoc} */ @Override public boolean isDone() { if (loopCount >= getEndIndex()) { return true; } JMeterContext context = getThreadContext(); StringBuilder builder = new StringBuilder( getInputVal().length()+getSeparator().length()+3); String inputVariable = builder.append(getInputVal()) .append(getSeparator()) .append(Integer.toString(loopCount+1)).toString(); final JMeterVariables variables = context.getVariables(); final Object currentVariable = variables.getObject(inputVariable); if (currentVariable != null) { variables.putObject(getReturnVal(), currentVariable); if (log.isDebugEnabled()) { log.debug("{} : Found in vars:{}, isDone:{}", getName(), inputVariable, Boolean.FALSE); } return false; } return super.isDone(); }
Object message_val = JMeterContextService.getContext().getVariables().getObject(msg_val_placeHolder); ProducerRecord<String, Object> producerRecord; try { if (key_message_flag) { Object message_key = JMeterContextService.getContext().getVariables().getObject(msg_key_placeHolder); producerRecord = new ProducerRecord<String, Object>(topic, message_key.toString(), message_val); } else {
@Override public void testStarted() { this.setRunningVersion(true); TestBeanHelper.prepare(this); JMeterVariables variables = getThreadContext().getVariables(); String poolName = getDataSource(); if(JOrphanUtils.isBlank(poolName)) { throw new IllegalArgumentException("Variable Name must not be empty for element:"+getName()); } else if (variables.getObject(poolName) != null) { log.error("JDBC data source already defined for: {}", poolName); } else { String maxPool = getPoolMax(); perThreadPoolSet = Collections.synchronizedSet(new HashSet<BasicDataSource>()); if (maxPool.equals("0")){ // i.e. if we want per thread pooling variables.putObject(poolName, new DataSourceComponentImpl()); // pool will be created later } else { BasicDataSource src = initPool(maxPool); synchronized(this){ dbcpDataSource = src; variables.putObject(poolName, new DataSourceComponentImpl(dbcpDataSource)); } } } }
/** * 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()); } }
if(getThreadContext().getVariables().getObject(getSource()) != null) { if(log.isWarnEnabled()) { log.warn(getSource() + " has already been defined.");
JMeterVariables vars = JMeterContextService.getContext().getVariables(); DigestParameters digestParameters = (DigestParameters) vars.getObject(DIGEST_PARAMETERS); if(digestParameters!=null) { DigestScheme digestAuth = (DigestScheme) authCache.get(targetHost);