org.apache.jmeter.control.LoopController Java Examples

The following examples show how to use org.apache.jmeter.control.LoopController. 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: JmxThreadGroup.java    From postman2jmx with MIT License 6 votes vote down vote up
public static ThreadGroup newInstance(LoopController loopController) {
    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());
    threadGroup.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());
    threadGroup.setName("Http URL/API Test");
    threadGroup.setEnabled(true);
    threadGroup.setSamplerController(loopController);
    threadGroup.setNumThreads(1);
    threadGroup.setRampUp(1);
    threadGroup.setScheduler(false);
    threadGroup.setDuration(0);
    threadGroup.setDelay(0);
    threadGroup.setComment("");
    threadGroup.setProperty(ThreadGroup.ON_SAMPLE_ERROR, "continue");
    return threadGroup;
}
 
Example #2
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
@Test
public void runDebugEngine() throws Exception {
    TestProvider prov = new TestProvider();

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(88, hook.cnt);
}
 
Example #3
Source File: SteppingThreadGroupGui.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void modifyTestElement(TestElement te) {
    super.configureTestElement(te);

    if (te instanceof SteppingThreadGroup) {
        SteppingThreadGroup tg = (SteppingThreadGroup) te;
        tg.setProperty(SteppingThreadGroup.NUM_THREADS, totalThreads.getText());
        tg.setThreadGroupDelay(initialDelay.getText());
        tg.setInUserCount(incUserCount.getText());
        tg.setInUserCountBurst(incUserCountBurst.getText());
        tg.setInUserPeriod(incUserPeriod.getText());
        tg.setOutUserCount(decUserCount.getText());
        tg.setOutUserPeriod(decUserPeriod.getText());
        tg.setFlightTime(flightTime.getText());
        tg.setRampUp(rampUp.getText());
        tg.setSamplerController((LoopController) loopPanel.createTestElement());

        refreshPreview();
    }
}
 
Example #4
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 #5
Source File: UltimateThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testScheduleThread() {
    System.out.println("scheduleThread");
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());
    JMeterThread thread = new JMeterThread(hashtree, null, null);

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

    instance.scheduleThread(thread);

    assertTrue(thread.getStartTime() > 0);
    assertTrue(thread.getEndTime() > thread.getStartTime());
}
 
Example #6
Source File: DirectoryListingConfigTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testThreadStopping() throws Exception {
    DirectoryListingConfig config = new DirectoryListingConfig();

    File rootDir = TestDirectoryListingConfigActionTest.createFileTree();

    setDirectoryConfig(config, rootDir.getAbsolutePath(), VARIABLE_NAME, true, false, false, false, true, false);

    final HashTree hashTree = new HashTree();
    hashTree.add(new LoopController());

    JMeterThread thread = new JMeterThread(hashTree, null, null);
    JMeterContextService.getContext().setThread(thread);

    testFlow(config);

    try {
        config.iterationStart(null);
    } catch (JMeterStopThreadException ex) {
        assertEquals("All files in the directory have been passed.", ex.getMessage());
    }
}
 
Example #7
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 #8
Source File: AbstractSimpleThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testFlow() {
    JMeterUtils.setProperty(AbstractSimpleThreadGroup.THREAD_GROUP_DISTRIBUTED_PREFIX_PROPERTY_NAME, "distprefix");
    final AbstractSimpleThreadGroupImpl tg = new AbstractSimpleThreadGroupImpl();
    tg.setName("TGName");
    LoopController looper = new LoopController();
    looper.setLoops(-1);
    tg.setSamplerController(looper);
    tg.setNumThreads(1);
    ListedHashTree listedHashTree = ArrivalsThreadGroupTest.getListedHashTree(tg, false);
    tg.start(0, null, listedHashTree, null);

    for (Map.Entry<JMeterThread, Thread> entry : tg.getAllThreads().entrySet()) {
        assertEquals("distprefix-TGName 0-1", entry.getValue().getName());
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
                tg.tellThreadsToStop();
                tg.waitThreadsStopped();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).start();

    tg.verifyThreadsStopped();
}
 
Example #9
Source File: UltimateThreadGroupGui.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private JPanel createControllerPanel() {
    loopPanel = new LoopControlPanel(false);
    LoopController looper = (LoopController) loopPanel.createTestElement();
    looper.setLoops(-1);
    looper.setContinueForever(true);
    loopPanel.configure(looper);
    return loopPanel;
}
 
Example #10
Source File: UltimateThreadGroupGui.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyTestElement(TestElement tg) {
    if (grid.isEditing()) {
        grid.getCellEditor().stopCellEditing();
    }

    if (tg instanceof UltimateThreadGroup) {
        UltimateThreadGroup utg = (UltimateThreadGroup) tg;
        CollectionProperty rows = JMeterPluginsUtils.tableModelRowsToCollectionProperty(tableModel, UltimateThreadGroup.DATA_PROPERTY);
        utg.setData(rows);
        utg.setSamplerController((LoopController) loopPanel.createTestElement());
    }
    super.configureTestElement(tg);
}
 
Example #11
Source File: SteppingThreadGroupGui.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private JPanel createControllerPanel() {
    loopPanel = new LoopControlPanel(false);
    LoopController looper = (LoopController) loopPanel.createTestElement();
    looper.setLoops(-1);
    looper.setContinueForever(true);
    loopPanel.configure(looper);
    return loopPanel;
}
 
Example #12
Source File: AbstractSimpleThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testThreadFinished() {
    System.out.println("threadFinished");
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());
    JMeterThread thread = new JMeterThread(hashtree, null, null);
    AbstractSimpleThreadGroup instance = new AbstractSimpleThreadGroupImpl();
    instance.threadFinished(thread);
}
 
Example #13
Source File: TestJMeterUtils.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public static void createJmeterEnv() {
    JMeterUtils.setJMeterHome(getTempDir());

    File dst = new File(JMeterUtils.getJMeterHome() + "/ss.props");
    InputStream src = DirectoryAnchor.class.getResourceAsStream("/kg/apc/jmeter/bin/saveservice.properties");
    try {
        Files.copy(src, dst.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        throw new RuntimeException("Failed to copy file " + src + " to " + dst, e);
    }

    JMeterUtils.loadJMeterProperties(dst.getAbsolutePath());
    JMeterUtils.setLocale(new Locale("ignoreResources"));

    JMeterTreeModel jMeterTreeModel = new JMeterTreeModel();
    JMeterTreeListener jMeterTreeListener = new JMeterTreeListener();
    jMeterTreeListener.setModel(jMeterTreeModel);
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    StandardJMeterEngine engine = new EmulatorJmeterEngine();
    JMeterThreadMonitor monitor = new EmulatorThreadMonitor();
    JMeterContextService.getContext().setEngine(engine);
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());
    JMeterThread thread = new JMeterThread(hashtree, monitor, null);
    thread.setThreadName("test thread");
    JMeterContextService.getContext().setThread(thread);
    ThreadGroup threadGroup = new org.apache.jmeter.threads.ThreadGroup();
    threadGroup.setName("test thread group");
    JMeterContextService.getContext().setThreadGroup(threadGroup);
    JMeterUtils.setProperty("sample_variables", "TEST1,TEST2,TEST3"); // for Flexible File Writer Test
    JMeterUtils.setProperty("saveservice_properties", "/ss.props");
    JMeterUtils.setProperty("upgrade_properties", "/ss.props");
    JMeterUtils.setProperty("sampleresult.default.encoding", "UTF-8"); // enable multibyte
}
 
Example #14
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runVariablesInControllers() throws Exception {
    TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/loops.jmx", "loops.jmx");

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    TestSampleListener listener = new TestSampleListener();
    testTree.add(testTree.getArray()[0], listener);

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(12, hook.cnt);

    assertEquals(3, listener.events.size());
}
 
Example #15
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runVariablesInAssertions() throws Exception {
    TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/debug.jmx", "debug.jmx");

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    TestSampleListener listener = new TestSampleListener();
    testTree.add(testTree.getArray()[0], listener);

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(4, hook.cnt);

    assertEquals(1, listener.events.size());
    SampleEvent event = listener.events.get(0);
    SampleResult result = event.getResult();
    AssertionResult[] assertionResults = result.getAssertionResults();
    assertEquals(1, assertionResults.length);

    AssertionResult assertionRes = assertionResults[0];
    assertNull(assertionRes.getFailureMessage());
}
 
Example #16
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runVariablesDebugEngine() throws Exception {
    TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/vars.jmx", "vars.jmx");

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    TestSampleListener listener = new TestSampleListener();
    testTree.add(testTree.getArray()[0], listener);

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(8, hook.cnt);

    assertEquals(3, listener.events.size());
    for (SampleEvent event : listener.events) {
        SampleResult res = event.getResult();
        String label = res.getSampleLabel();
        assertTrue("Label: " + label + " must end with '123'", label.endsWith("123"));
        assertFalse("Variable ${VAR} must be changed to '123' value. label: " + label, label.contains("${VAR}"));
        assertTrue("label: '" + label + "' response: '" + res.getResponseMessage() +"'", res.isSuccessful());
    }
}
 
Example #17
Source File: JmxLoopController.java    From postman2jmx with MIT License 5 votes vote down vote up
public static LoopController newInstance() {
    LoopController loopController = new LoopController();
    loopController.setEnabled(true);
    loopController.setLoops(5);
    loopController.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());
    loopController.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());

    return loopController;
}
 
Example #18
Source File: TestUtilities.java    From jmeter-prometheus-plugin with Apache License 2.0 5 votes vote down vote up
public static void createJmeterEnv() {
  	
      JMeterUtils.setJMeterHome("src/test/resources");
      JMeterUtils.setLocale(Locale.ENGLISH);
      JMeterUtils.loadJMeterProperties("src/test/resources/bin/jmeter.properties");
      
      try {
	SaveService.loadProperties();
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}

      JMeterTreeModel jMeterTreeModel = new JMeterTreeModel();
      JMeterTreeListener jMeterTreeListener = new JMeterTreeListener();
      jMeterTreeListener.setModel(jMeterTreeModel);
      
      JMeterContextService.getContext().setVariables(new JMeterVariables());
      StandardJMeterEngine engine = new StandardJMeterEngine();
      JMeterContextService.getContext().setEngine(engine);
      
      JMeterThreadMonitor monitor = new NOOPThreadMonitor();
      
      
      HashTree hashtree = new HashTree();
      hashtree.add(new LoopController());
      
      JMeterThread thread = new JMeterThread(hashtree, monitor, null);
      thread.setThreadName("test thread");
      JMeterContextService.getContext().setThread(thread);
      
      
      ThreadGroup tg1 = new ThreadGroup();
      tg1.setName("tg1");
      JMeterContextService.getContext().setThreadGroup(tg1);
      
  }
 
Example #19
Source File: DebuggingThreadGroup.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
public DebuggingThreadGroup() {
    super();
    setDelay(0);
    setNumThreads(1);
    setRampUp(0);
    LoopController ctl = new LoopController();
    ctl.setContinueForever(true);
    ctl.setLoops(-1);
    setSamplerController(ctl);
}
 
Example #20
Source File: JmeterTestPlanTask.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
private void createThreadGroupHashTree(int appIndex, Properties amsJmeterProperties, HashTree amsTestPlanTree, TestPlan amsTestPlan) {

    AppGetMetric appGetMetric = appGetMetrics.get(appIndex);
    String app = appGetMetric.getApp();
    int interval = appGetMetric.getInterval();

    //Read and validate AMS information.
    String[] amsHostPort = amsJmeterProperties.getProperty("ams-host-port").split(":");
    String amsHost = amsHostPort[0];
    String amsPath = amsJmeterProperties.getProperty("ams-path");
    int amsPort = Integer.valueOf(amsHostPort[1]);
    int numLoops = Integer.valueOf(amsJmeterProperties.getProperty("num-get-calls-per-app"));

    LoopController loopController = createLoopController(app + " GET loop controller", numLoops, false);
    for (GetMetricRequestInfo request : appGetMetric.getMetricRequests()) {

      ThreadGroup threadGroup = createThreadGroup(app + " GET threadGroup", 1, 0, loopController);

      HashTree threadGroupHashTree = amsTestPlanTree.add(amsTestPlan, threadGroup);
      Map<String, String> parametersMap = getAppSpecificParameters(app, request, amsJmeterProperties);

      HTTPSampler sampler = createGetSampler("GET " + app + " metrics", amsHost, amsPort, amsPath, null, parametersMap);

      if (numLoops > 1) {
        threadGroupHashTree.add(createConstantTimer(interval));
      }

      threadGroupHashTree.add(sampler);
    }
  }
 
Example #21
Source File: JmeterTestPlanTask.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
private LoopController createLoopController(String name, int numLoops, boolean continueForever) {
  LoopController loopController = new LoopController();
  loopController.setLoops(numLoops);
  loopController.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());
  loopController.initialize();
  loopController.setContinueForever(continueForever);
  loopController.setName(name);
  return loopController;
}
 
Example #22
Source File: CustomTreeClonerTest.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private HashTree createTestTree(ThroughputController controller, ConfigTestElement configTestElement) {
    HashTree controllerNode = new HashTree();
    controllerNode.add(controller, configTestElement);


    LoopController loopController = new LoopController();
    HashTree loopNode = new HashTree();
    loopNode.add(loopController, controllerNode);

    HashTree hashTree = new HashTree();
    hashTree.add(loopNode);
    return hashTree;
}
 
Example #23
Source File: JmeterTestPlanTask.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
private ThreadGroup createThreadGroup(String name, int numThreads, int rampUp, LoopController loopController) {
  ThreadGroup threadGroup = new ThreadGroup();
  threadGroup.setName(name);
  threadGroup.setNumThreads(numThreads);
  threadGroup.setRampUp(rampUp);
  threadGroup.setSamplerController(loopController);
  threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());
  return threadGroup;
}
 
Example #24
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 #25
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private LoopController getLoopController(int loops) {
    LoopController ctl = new LoopControllerTracked();
    ctl.setName("Top Loop");
    ctl.setLoops(loops);
    ctl.setContinueForever(false);
    return ctl;
}
 
Example #26
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private HashTree createTestTree(ConfigTestElement configTestElement) {
    HashTree hashTree = new HashTree();

    LoopController loopController = new LoopController();

    HashTree loopNode = new HashTree();
    loopNode.add(loopController, configTestElement);

    hashTree.add(loopNode);
    return hashTree;
}
 
Example #27
Source File: WebSocketSamplerTest.java    From jmeter-websocket with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    JMeterUtils.setJMeterHome("src/test/resources/");
    JMeterUtils.loadJMeterProperties("src/test/resources/jmeter.properties");
    JMeterUtils.setProperty("saveservice_properties", "saveservice.properties");
    JMeterUtils.setProperty("search_paths", "ApacheJMeter_functions-2.9.jar");
    JMeterUtils.setLocale(Locale.JAPAN);
    
    JMeterEngine engine = new StandardJMeterEngine();
    HashTree config = new ListedHashTree();
    TestPlan testPlan = new TestPlan("websocket test");
    testPlan.setFunctionalMode(false);
    testPlan.setSerialized(false);
    testPlan.setProperty(new BooleanProperty(TestElement.ENABLED, true));
    testPlan.setUserDefinedVariables(new Arguments());

    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(300);
    threadGroup.setRampUp(20);
    threadGroup.setDelay(0);
    threadGroup.setDuration(0);
    threadGroup.setProperty(new StringProperty(ThreadGroup.ON_SAMPLE_ERROR, "continue"));
    threadGroup.setScheduler(false);
    threadGroup.setName("Group1");
    threadGroup.setProperty(new BooleanProperty(TestElement.ENABLED, true));

    LoopController controller = new LoopController();
    controller.setLoops(10);
    controller.setContinueForever(false);
    controller.setProperty(new BooleanProperty(TestElement.ENABLED, true));
    threadGroup.setProperty(new TestElementProperty(ThreadGroup.MAIN_CONTROLLER, controller));

    CSVDataSet csvDataSet = new CSVDataSet();
    csvDataSet.setProperty(new StringProperty("filename", "src/test/resources/users.csv"));
    csvDataSet.setProperty(new StringProperty("variableNames", "USER_NAME"));
    csvDataSet.setProperty(new StringProperty("delimiter", ","));
    csvDataSet.setProperty(new StringProperty("shareMode", "shareMode.all"));
    csvDataSet.setProperty("quoted", false);
    csvDataSet.setProperty("recycle", true);
    csvDataSet.setProperty("stopThread", false);

    WebSocketSampler sampler = new WebSocketSampler();
    sampler.setName("WebSocket Test");
    sampler.setProperty(new BooleanProperty(TestElement.ENABLED, true));
    sampler.addNonEncodedArgument("name", "${USER_NAME}", "=");
    sampler.setContentEncoding("UTF-8");
    sampler.setProtocol("ws");
    sampler.setDomain("localhost");
    sampler.setPort(9090);
    sampler.setPath("/", "UTF-8");
    sampler.setSendMessage("${__RandomString(50,ABCDEFGHIJKLMNOPQRSTUVWXYZ)}");
    sampler.setRecvMessage("\"name\":\"${USER_NAME}\"");

    OnceOnlyController onceOnlyController = new OnceOnlyController();

    Summariser summariser = new Summariser();

    HashTree tpConfig = config.add(testPlan);
    HashTree tgConfig = tpConfig.add(threadGroup);
    HashTree oocConfig = tgConfig.add(onceOnlyController);
    oocConfig.add(csvDataSet);

    UniformRandomTimer randomTimer = new UniformRandomTimer();
    randomTimer.setRange(3000);
    HashTree samplerConfig = tgConfig.add(sampler);
    samplerConfig.add(summariser);
    tgConfig.add(randomTimer);

    engine.configure(config);
    engine.runTest();
}
 
Example #28
Source File: ConcurrencyThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
private Object[] createTestPlan() {
    JMeterContextService.getContext().setVariables(new JMeterVariables());

    TestSampleListener listener = new TestSampleListener();

    DebugSampler sampler = new DebugSampler();
    sampler.setName("Sampler");

    ConstantTimer timer = new ConstantTimer();
    timer.setDelay("2000");
    timer.setName("timer");

    LoopController loopController = new LoopController();
    loopController.setContinueForever(true);
    loopController.setLoops(-1);
    loopController.setName("loop c");

    ConcurrencyThreadGroupExt ctg = new ConcurrencyThreadGroupExt();
    ctg.setName("CTG");
    ctg.setRampUp("5");
    ctg.setTargetLevel("3");
    ctg.setSteps("1");
    ctg.setHold("10"); // TODO: increase this value for debugging
    ctg.setIterationsLimit("");
    ctg.setUnit("S");


    ListedHashTree loopTree = new ListedHashTree();
    loopTree.add(loopController, timer);
    loopTree.add(loopController, sampler);
    loopTree.add(loopController, listener);

    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(ctg, loopTree);
    TestCompiler compiler = new TestCompiler(hashTree);
    // this hashTree can be save to *jmx
    hashTree.traverse(compiler);

    return new Object[] {
            hashTree,
            ctg
    };
}
 
Example #29
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;
    }
}
 
Example #30
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();
}