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

The following examples show how to use org.apache.jmeter.threads.JMeterThread#setThreadNum() . 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: SteppingThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testScheduleThreadIntegerOverflow() {
    System.out.println("scheduleThreadIntegerOverflow");
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());
    JMeterThread thread = new JMeterThread(hashtree, null, null);
    SteppingThreadGroup instance = new SteppingThreadGroup();
    int numThreads = 3;
    instance.setNumThreads(numThreads);
    int inUserCount = 1;
    instance.setInUserCount("" + inUserCount);
    instance.setInUserCountBurst("0");
    int inUserPeriod = 224985600;
    instance.setInUserPeriod("" + inUserPeriod);
    instance.setRampUp("0");
    instance.setThreadGroupDelay("0");
    int flightTime = 33;
    instance.setFlightTime("" + flightTime);

    thread.setThreadNum(0);
    instance.scheduleThread(thread);

    assertEquals(1000L * ((inUserCount + 1) * inUserPeriod + inUserCount * flightTime), thread.getEndTime() - thread.getStartTime());

}
 
Example 3
Source File: UltimateThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testScheduleThreadAll() {
    System.out.println("scheduleThreadAll");
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());

    CollectionProperty prop = JMeterPluginsUtils.tableModelRowsToCollectionProperty(dataModel, UltimateThreadGroup.DATA_PROPERTY);
    instance.setData(prop);
    instance.testStarted();

    for (int n = 0; n < instance.getNumThreads(); n++) {
        JMeterThread thread = new JMeterThread(hashtree, null, null);
        thread.setThreadNum(n);
        instance.scheduleThread(thread);
    }
}
 
Example 4
Source File: SteppingThreadGroupGui.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
private void updateChart(SteppingThreadGroup tg) {
    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();

    // test start
    chart.setxAxisLabelRenderer(new DateTimeRenderer(DateTimeRenderer.HHMMSS, now - 1)); //-1 because row.add(thread.getStartTime() - 1, 0)
    row.add(now, 0);
    row.add(now + tg.getThreadGroupDelayAsInt(), 0);

    int numThreads = tg.getNumThreads();

    // users in
    for (int n = 0; n < numThreads; n++) {
        thread.setThreadNum(n);
        tg.scheduleThread(thread, now);
        row.add(thread.getStartTime() - 1, 0);
        row.add(thread.getStartTime(), 1);
    }

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

    model.put("Expected Active Users Count", row);
    chart.invalidateCache();
    chart.repaint();
}
 
Example 5
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();
}
 
Example 6
Source File: SteppingThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
/**
 * Test of scheduleThread method, of class SteppingThreadGroup.
 */
@Test
public void testScheduleThread() {
    System.out.println("scheduleThread");
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());
    JMeterThread thread = new JMeterThread(hashtree, null, null);
    SteppingThreadGroup instance = new SteppingThreadGroup();
    instance.setNumThreads(15);
    instance.setInUserCount("5");
    instance.setInUserCountBurst("10");
    instance.setInUserPeriod("30");
    instance.setRampUp("10");
    instance.setThreadGroupDelay("5");
    instance.setFlightTime("60");

    long s1 = -1, s2;
    for (int n = 0; n < 10; n++) {
        thread.setThreadNum(n);
        instance.scheduleThread(thread);
        s2 = thread.getStartTime();
        if (s1 >= 0) {
            assertEquals(1000, s2 - s1);
        }
        s1 = s2;
    }

    thread.setThreadNum(10);
    instance.scheduleThread(thread);
    s2 = thread.getStartTime();
    assertEquals(31000, s2 - s1);
    s1 = s2;

    for (int n = 11; n < 15; n++) {
        thread.setThreadNum(n);
        instance.scheduleThread(thread);
        s2 = thread.getStartTime();
        if (s1 >= 0) {
            assertEquals(2000, s2 - s1);
        }
        s1 = s2;
    }
}