Java Code Examples for org.apache.jmeter.threads.JMeterContext#setVariables()

The following examples show how to use org.apache.jmeter.threads.JMeterContext#setVariables() . 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: PepperBoxSamplerTest.java    From pepper-box with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {

    zkServer = new EmbeddedZookeeper();

    String zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST +":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    //AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

    JMeterContext jmcx = JMeterContextService.getContext();
    jmcx.setVariables(new JMeterVariables());

}
 
Example 2
Source File: PepperBoxLoadGenTest.java    From pepper-box with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {

    zkServer = new EmbeddedZookeeper();

    String zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST +":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    //AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

    JMeterContext jmcx = JMeterContextService.getContext();
    jmcx.setVariables(new JMeterVariables());

}
 
Example 3
Source File: MonitoringResultsCollector.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
   * 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());
  }
 
Example 4
Source File: JMXMonCollector.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
   * 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());
  }
 
Example 5
Source File: RedisDataSetTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
    // Set up thread variables
    JMeterContext jmcx = JMeterContextService.getContext();
    jmcx.setVariables(new JMeterVariables());
    threadVars = jmcx.getVariables();

    // Create new mock RedisServer
    server = RedisServer.newRedisServer(6370);
    server.start();

    // Setup test data
    JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost", 6370);
    Jedis jedis = pool.getResource();

    jedis.rpush("testRecycleList", "12345678,1234","12345679,1235", "12345680,1236");
    jedis.rpush("testConsumeList", "12345678,1234","12345679,1235", "12345680,1236");
    jedis.sadd("testRecycleSet", "12345678,1234","12345679,1235", "12345680,1236");
    jedis.sadd("testConsumeSet", "12345678,1234","12345679,1235", "12345680,1236");

    jedis.shutdown();

}
 
Example 6
Source File: Base64EncodeTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() throws Exception {
    JMeterContext context = JMeterContextService.getContext();
    context.setVariables(new JMeterVariables());

    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("test string"));
    parameters.add(new CompoundVariable("b64enc_res"));
    Base64Encode instance = new Base64Encode();
    instance.setParameters(parameters);

    String res = instance.execute(null, null);
    Assert.assertEquals("dGVzdCBzdHJpbmc=", res);
    Assert.assertNotNull(context.getVariables().get("b64enc_res"));
}
 
Example 7
Source File: Base64DecodeTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() throws Exception {
    JMeterContext context = JMeterContextService.getContext();
    context.setVariables(new JMeterVariables());

    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("dGVzdCBzdHJpbmc="));
    parameters.add(new CompoundVariable("b64dec_res"));
    Base64Decode instance = new Base64Decode();
    instance.setParameters(parameters);

    String res = instance.execute(null, null);
    Assert.assertEquals("test string", res);
    Assert.assertNotNull(context.getVariables().get("b64dec_res"));
}
 
Example 8
Source File: CaseFormatTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	changeCase = new CaseFormat();
    result = new SampleResult();
    JMeterContext jmctx = JMeterContextService.getContext();
    String data = "dummy data";
    result.setResponseData(data, null);
    JMeterVariables vars = new JMeterVariables();
    jmctx.setVariables(vars);
    jmctx.setPreviousResult(result);
    params = new LinkedList<>();
}
 
Example 9
Source File: PepperBoxConfigElementTest.java    From pepper-box with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUp(){
    JMeterContext jmcx = JMeterContextService.getContext();
    jmcx.setVariables(new JMeterVariables());
}