org.apache.jmeter.threads.ThreadGroup Java Examples

The following examples show how to use org.apache.jmeter.threads.ThreadGroup. 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: 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 #3
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 #4
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 #5
Source File: DebuggerDialogBase.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    int selRow = tree.getRowForLocation(e.getX(), e.getY());

    if (tree.getPathForLocation(e.getX(), e.getY()) != null) {
        final TreePath currentPath = tree.getPathForLocation(e.getX(), e.getY());

        if (selRow != -1 && currentPath != null) {
            if (isRightClick(e)) {
                if (tree.getSelectionCount() < 2) {
                    tree.setSelectionPath(currentPath);
                }
                final JMeterTreeNode node = (JMeterTreeNode) currentPath.getLastPathComponent();
                TestElement te = (TestElement) node.getUserObject();
                if (te instanceof ConfigElement || te instanceof TestPlan || te instanceof ThreadGroup || te instanceof WorkBench) {
                    log.debug("No breakpoint possible for " + te);
                    return;
                }
                JPopupMenu popup = getPopup(te);
                popup.pack();
                popup.show(tree, e.getX(), e.getY());
                popup.setVisible(true);
                popup.requestFocusInWindow();
            }
        }
    }
}
 
Example #6
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 #7
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test(timeout=3000)
public void testStartNextIteration() {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();

    TestAction action = new TestAction();
    action.setAction(3);

    DebugSampler samplerBefore = new DebugSampler();
    samplerBefore.setName("samplerBefore");

    DebugSampler samplerAfter = new DebugSampler();
    samplerAfter.setName("samplerAfter");

    WhileController whileController = new WhileController();

    ParallelSampler sampler = new ParallelSampler();
    sampler.setGenerateParent(true);
    LoopController loop = new LoopController();
    loop.setLoops(2);
    loop.setContinueForever(false);

    // parallel subtree
    ListedHashTree parallelTree = new ListedHashTree();
    parallelTree.add(samplerBefore);
    parallelTree.add(action);

    // while subtree
    ListedHashTree whileTree = new ListedHashTree();
    whileTree.add(whileController, parallelTree);

    // parallel Sampler subtree
    ListedHashTree parallelSamplerTree = new ListedHashTree();
    parallelSamplerTree.add(sampler, whileTree);

    // TG sub tree
    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(1);
    threadGroup.setSamplerController(loop);

    ListedHashTree loopTree = new ListedHashTree();
    loopTree.add(threadGroup, parallelSamplerTree);
    loopTree.add(threadGroup, samplerAfter);
    loopTree.add(threadGroup, listener);

    TestCompiler compiler = new TestCompiler(loopTree);
    loopTree.traverse(compiler);

    ListenerNotifier notifier = new ListenerNotifier();

    JMeterThread thread = new JMeterThread(loopTree, threadGroup, notifier);
    thread.setThreadGroup(threadGroup);
    thread.setEngine(new StandardJMeterEngine());
    thread.setOnErrorStopThread(true);
    thread.run();

    assertEquals(2, listener.events.size());
}
 
Example #8
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test(timeout=3000)
public void testInfinityStopTest() {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();

    TestAction action = new TestAction();
    action.setAction(0);
    action.setTarget(2);

    WhileController whileController = new WhileController();

    ParallelSampler sampler = new ParallelSampler();
    sampler.setGenerateParent(true);
    LoopController loop = new LoopController();
    loop.setLoops(1);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, sampler);
    hashTree.add(sampler, listener);
    hashTree.add(sampler, whileController);
    hashTree.add(whileController, action);
    hashTree.add(whileController, listener);

    TestCompiler compiler = new TestCompiler(hashTree);
    hashTree.traverse(compiler);

    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(1);

    ListenerNotifier notifier = new ListenerNotifier();

    JMeterThread thread = new JMeterThread(hashTree, threadGroup, notifier);
    thread.setThreadGroup(threadGroup);
    thread.setOnErrorStopThread(true);
    thread.setEngine(new StandardJMeterEngine());
    thread.run();

    assertEquals(1, listener.events.size());
}
 
Example #9
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testNestedWSC() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());


    TestSampleListener listener = new TestSampleListener();

    // top WSC
    WeightedSwitchController topWSC = new WeightedSwitchController();
    PowerTableModel topPTM = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    topPTM.addRow(new String[]{"wsc1", "2"});
    topPTM.addRow(new String[]{"wsc2", "2"});
    topPTM.addRow(new String[]{"D_#1", "1"});
    topPTM.addRow(new String[]{"D_#2", "1"});
    topWSC.setData(topPTM);

    DebugSampler d1 = new DebugSampler();
    d1.setName("D_#1");
    DebugSampler d2 = new DebugSampler();
    d2.setName("D_#2");

    // first child WSC of top WSC
    WeightedSwitchController childWSC1 = new WeightedSwitchController();
    childWSC1.setName("wsc1");
    PowerTableModel childPTM1 = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    childPTM1.addRow(new String[]{"D1_#1", "1"});
    childPTM1.addRow(new String[]{"D1_#2", "1"});
    childWSC1.setData(childPTM1);

    DebugSampler d1_1 = new DebugSampler();
    d1_1.setName("D1_#1");
    DebugSampler d1_2 = new DebugSampler();
    d1_2.setName("D1_#2");

    // second child WSC of top WSC
    WeightedSwitchController childWSC2 = new WeightedSwitchController();
    childWSC2.setName("wsc2");
    PowerTableModel childPTM2 = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    childPTM2.addRow(new String[]{"D2_#1", "1"});
    childPTM2.addRow(new String[]{"D2_#2", "1"});
    childWSC2.setData(childPTM2);

    DebugSampler d2_1 = new DebugSampler();
    d2_1.setName("D2_#1");
    DebugSampler d2_2 = new DebugSampler();
    d2_2.setName("D2_#2");

    // main loop
    LoopController loop = new LoopController();
    loop.setLoops(6);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, childWSC1);
    hashTree.add(childWSC1, d1_1);
    hashTree.add(childWSC1, d1_2);
    hashTree.add(childWSC1, listener);
    hashTree.add(topWSC, childWSC2);
    hashTree.add(childWSC2, d2_1);
    hashTree.add(childWSC2, d2_2);
    hashTree.add(childWSC2, listener);
    hashTree.add(topWSC, d1);
    hashTree.add(topWSC, d2);

    TestCompiler compiler = new TestCompiler(hashTree);
    hashTree.traverse(compiler);

    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(1);

    ListenerNotifier notifier = new ListenerNotifier();

    JMeterThread thread = new JMeterThread(hashTree, threadGroup, notifier);
    thread.setThreadGroup(threadGroup);
    thread.setOnErrorStopThread(true);
    thread.run();

    assertEquals(6, listener.events.size());
    List<String> labels = new ArrayList<>();
    labels.add("D_#1");
    labels.add("D_#2");
    labels.add("D1_#1");
    labels.add("D1_#2");
    labels.add("D2_#1");
    labels.add("D2_#2");
    for (SampleEvent event : listener.events) {
        assertTrue(labels.contains(event.getResult().getSampleLabel()));
    }
}
 
Example #10
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testNestedSimpleControllers() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());


    TestSampleListener listener = new TestSampleListener();

    // top WSC
    WeightedSwitchController topWSC = new WeightedSwitchController();
    PowerTableModel topPTM = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    topPTM.addRow(new String[]{"ex1", "10"});
    topPTM.addRow(new String[]{"ex2", "20"});
    topWSC.setData(topPTM);


    // first child: simple controller
    GenericController ex1 = new GenericController();
    ex1.setName("ex1");
    DebugSampler example1_1 = new DebugSampler();
    example1_1.setName("example1_1");
    DebugSampler example1_2 = new DebugSampler();
    example1_2.setName("example1_2");

    // second child: simple controller
    GenericController ex2 = new GenericController();
    ex2.setName("ex2");
    DebugSampler example2_1 = new DebugSampler();
    example2_1.setName("example2_1");
    DebugSampler example2_2 = new DebugSampler();
    example2_2.setName("example2_2");

    // main loop
    LoopController loop = new LoopController();
    loop.setLoops(60);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, ex1);
    hashTree.add(ex1, example1_1);
    hashTree.add(ex1, example1_2);
    hashTree.add(ex1, listener);
    hashTree.add(topWSC, ex2);
    hashTree.add(ex2, example2_1);
    hashTree.add(ex2, example2_2);
    hashTree.add(ex2, listener);

    TestCompiler compiler = new TestCompiler(hashTree);
    hashTree.traverse(compiler);

    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(1);

    ListenerNotifier notifier = new ListenerNotifier();

    JMeterThread thread = new JMeterThread(hashTree, threadGroup, notifier);
    thread.setThreadGroup(threadGroup);
    thread.setOnErrorStopThread(true);
    thread.run();

    Map<String, Integer> totalResults = new HashMap<>();
    for (SampleEvent event : listener.events) {
        String label = event.getResult().getSampleLabel();
        if (totalResults.containsKey(label)) {
            totalResults.put(label, totalResults.get(label) + 1);
        } else {
            totalResults.put(label, 1);
        }
    }

    assertEquals(120, listener.events.size());
    assertEquals(20, (int) totalResults.get("example1_1"));
    assertEquals(20, (int) totalResults.get("example1_2"));
    assertEquals(40, (int) totalResults.get("example2_1"));
    assertEquals(40, (int) totalResults.get("example2_2"));
}
 
Example #11
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testNestedTransactionControllers() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());


    TestSampleListener listener = new TestSampleListener();

    // top WSC
    WeightedSwitchController topWSC = new WeightedSwitchController();
    PowerTableModel topPTM = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    topPTM.addRow(new String[]{"ex1", "10"});
    topPTM.addRow(new String[]{"ex2", "20"});
    topWSC.setData(topPTM);


    // first child: transaction controller
    TransactionController ex1 = new TransactionController();
    ex1.setName("ex1");
    DebugSampler example1_1 = new DebugSampler();
    example1_1.setName("example1_1");
    DebugSampler example1_2 = new DebugSampler();
    example1_2.setName("example1_2");

    // second child: transaction controller
    TransactionController ex2 = new TransactionController();
    ex2.setName("ex2");
    DebugSampler example2_1 = new DebugSampler();
    example2_1.setName("example2_1");
    DebugSampler example2_2 = new DebugSampler();
    example2_2.setName("example2_2");

    // main loop
    LoopController loop = new LoopController();
    loop.setLoops(3);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, ex1);
    hashTree.add(ex1, example1_1);
    hashTree.add(ex1, example1_2);
    hashTree.add(ex1, listener);
    hashTree.add(topWSC, ex2);
    hashTree.add(ex2, example2_1);
    hashTree.add(ex2, example2_2);
    hashTree.add(ex2, listener);

    TestCompiler compiler = new TestCompiler(hashTree);
    hashTree.traverse(compiler);

    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(1);

    ListenerNotifier notifier = new ListenerNotifier();

    JMeterThread thread = new JMeterThread(hashTree, threadGroup, notifier);
    thread.setThreadGroup(threadGroup);
    thread.setOnErrorStopThread(true);
    thread.run();

    Map<String, Integer> totalResults = new HashMap<>();
    for (SampleEvent event : listener.events) {
        String label = event.getResult().getSampleLabel();
        if (totalResults.containsKey(label)) {
            totalResults.put(label, totalResults.get(label) + 1);
        } else {
            totalResults.put(label, 1);
        }
    }

    assertEquals(9, listener.events.size());
    assertEquals(1, (int) totalResults.get("example1_1"));
    assertEquals(1, (int) totalResults.get("example1_2"));
    assertEquals(2, (int) totalResults.get("example2_1"));
    assertEquals(2, (int) totalResults.get("example2_2"));
    assertEquals(1, (int) totalResults.get("ex1")); // transaction result
    assertEquals(2, (int) totalResults.get("ex2")); // transaction result
}
 
Example #12
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testResetTransactionControllerUnderSimpleController() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());


    TestSampleListener listener = new TestSampleListener();

    // top WSC
    WeightedSwitchController topWSC = new WeightedSwitchController();
    PowerTableModel topPTM = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    topPTM.addRow(new String[]{"simple1", "100"});
    topPTM.addRow(new String[]{"simple2", "100"});
    topWSC.setData(topPTM);

    GenericController simple1 = new GenericController();
    simple1.setName("simple1");

    GenericController simple2 = new GenericController();
    simple2.setName("simple2");

    // first child: transaction controller
    TransactionController ex1 = new TransactionController();
    ex1.setName("ex1");
    DebugSampler example1_1 = new DebugSampler();
    example1_1.setName("example1_1");
    DebugSampler example1_2 = new DebugSampler();
    example1_2.setName("example1_2");

    // second child: transaction controller
    TransactionController ex2 = new TransactionController();
    ex2.setName("ex2");
    DebugSampler example2_1 = new DebugSampler();
    example2_1.setName("example2_1");
    DebugSampler example2_2 = new DebugSampler();
    example2_2.setName("example2_2");

    // main loop
    LoopController loop = new LoopController();
    loop.setLoops(4);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, simple1);
    hashTree.add(simple1, ex1);
    hashTree.add(ex1, example1_1);
    hashTree.add(ex1, example1_2);
    hashTree.add(ex1, listener);
    hashTree.add(topWSC, simple2);
    hashTree.add(simple2, ex2);
    hashTree.add(ex2, example2_1);
    hashTree.add(ex2, example2_2);
    hashTree.add(ex2, listener);

    TestCompiler compiler = new TestCompiler(hashTree);
    hashTree.traverse(compiler);

    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(1);

    ListenerNotifier notifier = new ListenerNotifier();

    JMeterThread thread = new JMeterThread(hashTree, threadGroup, notifier);
    thread.setThreadGroup(threadGroup);
    thread.setOnErrorStopThread(true);
    thread.run();

    Map<String, Integer> totalResults = new HashMap<>();
    for (SampleEvent event : listener.events) {
        String label = event.getResult().getSampleLabel();
        if (totalResults.containsKey(label)) {
            totalResults.put(label, totalResults.get(label) + 1);
        } else {
            totalResults.put(label, 1);
        }
    }

    assertEquals(12, listener.events.size());
    assertEquals(2, (int) totalResults.get("example1_1"));
    assertEquals(2, (int) totalResults.get("example1_2"));
    assertEquals(2, (int) totalResults.get("example2_1"));
    assertEquals(2, (int) totalResults.get("example2_2"));
    assertEquals(2, (int) totalResults.get("ex1")); // transaction result
    assertEquals(2, (int) totalResults.get("ex2")); // transaction result
}
 
Example #13
Source File: DebuggingThreadGroup.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
@Override
public ThreadGroup getOriginal() {
    return original;
}
 
Example #14
Source File: DebuggingThreadGroup.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
@Override
public void setOriginal(ThreadGroup orig) {
    original = orig;
}
 
Example #15
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();
}