Java Code Examples for org.apache.jmeter.threads.JMeterThread#setThreadName()

The following examples show how to use org.apache.jmeter.threads.JMeterThread#setThreadName() . 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: AbstractSimpleThreadGroup.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private JMeterThread makeThread(int groupNum,
                                ListenerNotifier notifier, ListedHashTree threadGroupTree,
                                StandardJMeterEngine engine, int threadNum,
                                JMeterContext context) { // N.B. Context needs to be fetched in the correct thread
    boolean onErrorStopTest = getOnErrorStopTest();
    boolean onErrorStopTestNow = getOnErrorStopTestNow();
    boolean onErrorStopThread = getOnErrorStopThread();
    boolean onErrorStartNextLoop = getOnErrorStartNextLoop();

    String groupName = getName();
    String distributedPrefix = JMeterUtils.getPropDefault(THREAD_GROUP_DISTRIBUTED_PREFIX_PROPERTY_NAME, "");
    final String threadName = distributedPrefix + (distributedPrefix.isEmpty() ? "" : "-") + groupName + " " + groupNum + "-" + (threadNum + 1);

    final JMeterThread jmeterThread = new JMeterThread(cloneTree(threadGroupTree), this, notifier);
    jmeterThread.setThreadNum(threadNum);
    jmeterThread.setThreadGroup(this);
    jmeterThread.setInitialContext(context);
    jmeterThread.setThreadName(threadName);
    jmeterThread.setEngine(engine);
    jmeterThread.setOnErrorStopTest(onErrorStopTest);
    jmeterThread.setOnErrorStopTestNow(onErrorStopTestNow);
    jmeterThread.setOnErrorStopThread(onErrorStopThread);
    jmeterThread.setOnErrorStartNextLoop(onErrorStartNextLoop);
    return jmeterThread;
}
 
Example 2
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void underLoop() throws Exception {
    EmulSampler payload = new EmulSampler();
    payload.setName("payload");

    ParallelSampler sam = new ParallelSampler();
    sam.threadStarted();
    sam.setName("Parallel Sampler");
    sam.addTestElement(payload);

    LoopController ctl = getLoopController(5);
    ctl.addTestElement(sam);

    JMeterThread thr = new JMeterThread(new HashTree(ctl), sam, sam.notifier);
    thr.setThreadName("root");
    thr.setThreadGroup(new DummyThreadGroup());
    JMeterContextService.getContext().setThread(thr);

    addToContext(sam, thr);
    addToContext(payload, thr);

    sam.setRunningVersion(true);
    ctl.setRunningVersion(true);
    payload.setRunningVersion(true);
    thr.run();
    assertEquals(5, EmulSampler.count.get());
}
 
Example 3
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testThreadSafeCookieManager() throws Exception {
    CookieManager cookieManager = new CookieManager();
    Cookie c = new Cookie();
    c.setName("name");
    c.setValue("value");
    c.setDomain("blazedemo.com");
    c.setPath("");
    cookieManager.add(c);
    HashTree hashtree = createTestTree(cookieManager);

    TestPlan testPlan = new TestPlan();
    HashTree testPlanHashTree = new HashTree();
    testPlanHashTree.put(testPlan, hashtree);

    StandardJMeterEngine engine = new StandardJMeterEngine();
    engine.configure(testPlanHashTree);

    EmulatorThreadMonitor monitor = new EmulatorThreadMonitor();
    JMeterThread thread = new JMeterThread(hashtree, monitor, null);
    thread.setThreadName("test thread");
    JMeterContextService.getContext().setThread(thread);

    ParallelSampler parallel = new ParallelSampler();
    parallel.testStarted();

    Field field = StandardJMeterEngine.class.getDeclaredField("test");
    field.setAccessible(true);
    HashTree testTree = (HashTree) field.get(engine);

    assertTrue("CookieManager should be changed to ThreadSafeCookieManager", testTree.toString().contains("ThreadSafeCookieManager"));
    ListedHashTree loop = (ListedHashTree) (testTree.values().toArray()[0]);
    ListedHashTree threadSafeManager = ((ListedHashTree) (loop.values().toArray()[0]));

    CookieManager mgr = (CookieManager) threadSafeManager.getArray()[0];
    assertTrue(mgr instanceof ThreadSafeCookieManager);
    assertEquals(1, mgr.getCookieCount());
    JMeterProperty property = mgr.getCookies().get(0);
    assertEquals("name", property.getName());
    assertEquals("blazedemo.com\tTRUE\t\tFALSE\t0\tname\tvalue", property.getStringValue());
}
 
Example 4
Source File: UltimateThreadGroupGui.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
private void updateChart(UltimateThreadGroup tg) {
    tg.testStarted();
    model.clear();
    GraphRowSumValues row = new GraphRowSumValues();
    row.setColor(Color.RED);
    row.setDrawLine(true);
    row.setMarkerSize(AbstractGraphRow.MARKER_SIZE_NONE);
    row.setDrawThickLines(true);

    final HashTree hashTree = new HashTree();
    hashTree.add(new LoopController());
    JMeterThread thread = new JMeterThread(hashTree, null, null);

    long now = System.currentTimeMillis();

    chart.setxAxisLabelRenderer(new DateTimeRenderer(DateTimeRenderer.HHMMSS, now - 1)); //-1 because row.add(thread.getStartTime() - 1, 0)
    chart.setForcedMinX(now);

    row.add(now, 0);

    // users in
    int numThreads = tg.getNumThreads();
    log.debug("Num Threads: " + numThreads);
    for (int n = 0; n < numThreads; n++) {
        thread.setThreadNum(n);
        thread.setThreadName(Integer.toString(n));
        tg.scheduleThread(thread, now);
        row.add(thread.getStartTime() - 1, 0);
        row.add(thread.getStartTime(), 1);
    }

    tg.testStarted();
    // users out
    for (int n = 0; n < tg.getNumThreads(); n++) {
        thread.setThreadNum(n);
        thread.setThreadName(Integer.toString(n));
        tg.scheduleThread(thread, now);
        row.add(thread.getEndTime() - 1, 0);
        row.add(thread.getEndTime(), -1);
    }

    model.put("Expected parallel users count", row);
    chart.invalidateCache();
    chart.repaint();
}