Java Code Examples for org.apache.jmeter.threads.JMeterVariables#putObject()

The following examples show how to use org.apache.jmeter.threads.JMeterVariables#putObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlainTextConfigElement.java    From pepper-box with Apache License 2.0 6 votes vote down vote up
/**
 * For every JMeter sample, iterationStart method gets invoked, it initializes load generator and for each iteration sets new message as JMeter variable
 *
 * @param loopIterationEvent
 */
@Override
public void iterationStart(LoopIterationEvent loopIterationEvent) {

    //Check if load generator is instantiated
    if (generator == null) {

        try {

            //instantiate plaintext load generator
            generator = new PlaintTextLoadGenerator(getJsonSchema());

        } catch (Exception e) {
            log.error("Failed to create PlaintTextLoadGenerator instance", e);
        }

    }

    //For ever iteration put message in jmeter variables
    JMeterVariables variables = JMeterContextService.getContext().getVariables();
    variables.putObject(placeHolder, generator.nextMessage());
}
 
Example 2
Source File: SerializedConfigElement.java    From pepper-box with Apache License 2.0 6 votes vote down vote up
/**
 * For every JMeter sample, iterationStart method gets invoked, it initializes load generator and for each iteration sets new message as JMeter variable
 *
 * @param loopIterationEvent
 */
@Override
public void iterationStart(LoopIterationEvent loopIterationEvent) {

    try {
        //Check if load generator is instantiated
        if (generator == null) {

            //instantiate serialized load generator
            generator = new SerializedLoadGenerator(className, objProperties);

        }

        //For ever iteration put message in jmeter variables
        JMeterVariables variables = JMeterContextService.getContext().getVariables();
        variables.putObject(placeHolder, generator.nextMessage());
    } catch (Exception e) {
        log.error("Failed to create PlaintTextLoadGenerator instance", e);
    }
}
 
Example 3
Source File: WebDriverSamplerTest.java    From jmeter-plugins-webdriver with Apache License 2.0 5 votes vote down vote up
@Before
public void createSampler() {
    browser = Mockito.mock(WebDriver.class);
    when(browser.getPageSource()).thenReturn("page source");
    when(browser.getCurrentUrl()).thenReturn("http://google.com.au");
    variables = new JMeterVariables();
    variables.putObject(WebDriverConfig.BROWSER, browser);
    JMeterContextService.getContext().setVariables(variables);
    sampler = new WebDriverSampler();
}
 
Example 4
Source File: PrometheusMetricsConfig.java    From jmeter-prometheus-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void testStarted() {
	this.setRunningVersion(true);
	this.makeNewCollectors();
	JMeterVariables variables = getThreadContext().getVariables();

	
	log.debug("Test started, adding {} collectors to variables", this.collectors.size());
	
	for (Entry<BaseCollectorConfig, Collector> entry : this.collectors.entrySet()) {
		BaseCollectorConfig cfg = entry.getKey(); 
		variables.putObject(cfg.getMetricName(), entry.getValue());
		log.debug("Added ({},{}) to variables.", entry.getKey(), entry.getValue().toString());
	}
	}
 
Example 5
Source File: CassandraConnection.java    From jmeter-cassandra with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation") // call to TestBeanHelper.prepare() is intentional
public void testStarted() {
    this.setRunningVersion(true);
    TestBeanHelper.prepare(this);
    JMeterVariables variables = getThreadContext().getVariables();
    LoadBalancingPolicy loadBalancingPolicy = null;

    if (loadBalancer.contentEquals(DC_AWARE_ROUND_ROBIN)) {
        // in driver v2.0.2+, we can use the default constructor on
        // dcawareroundrobinpolicy
        if (localDataCenter.isEmpty()) {
            loadBalancingPolicy = new DCAwareRoundRobinPolicy();
        }   else {
            loadBalancingPolicy = new DCAwareRoundRobinPolicy(localDataCenter);
        }
    } else if (loadBalancer.contentEquals(WHITELIST)) {
        loadBalancingPolicy = new WhiteListPolicy(new RoundRobinPolicy(), contactPointsIS);
    } else if (loadBalancer.contentEquals(ROUND_ROBIN)) {
        loadBalancingPolicy = new RoundRobinPolicy();
    } else if (loadBalancer.contentEquals(DC_TOKEN_AWARE)) {
        loadBalancingPolicy = new TokenAwarePolicy(new DCAwareRoundRobinPolicy());
    } else if (loadBalancer.contentEquals(DEFAULTLOADBALANCER)) {
        loadBalancingPolicy = null;
    }

    Session session = CassandraSessionFactory.createSession(sessionName, contactPointsI, keyspace, username, password, loadBalancingPolicy);

    variables.putObject(sessionName, session);
}