Java Code Examples for org.apache.jorphan.collections.HashTree#add()

The following examples show how to use org.apache.jorphan.collections.HashTree#add() . 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: JMeterThreadParallelTest.java    From jmeter-bzm-plugins with Apache License 2.0 7 votes vote down vote up
@Test
public void testStopParentThread() {
    DummyThreadGroup monitor = new DummyThreadGroup();
    ListenerNotifier listenerNotifier = new ListenerNotifier();

    HashTree tree = new HashTree();
    LoopControllerExt loopControllerExt = new LoopControllerExt();
    tree.add(loopControllerExt);

    JMeterThreadExt parentThread = new JMeterThreadExt(tree, monitor, listenerNotifier);
    parentThread.setThreadGroup(monitor);
    JMeterContextService.getContext().setThread(parentThread);

    JMeterThreadParallel parallel = new JMeterThreadParallel(tree, monitor, listenerNotifier, true);
    parallel.setThreadGroup(monitor);
    loopControllerExt.thread = parallel;
    parallel.run();

    assertTrue(parentThread.isStopped);
}
 
Example 2
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 3
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 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: StudentProfileLNPTest.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected ListedHashTree getLnpTestPlan() {
    ListedHashTree testPlan = new ListedHashTree(JMeterElements.testPlan());
    HashTree threadGroup = testPlan.add(
            JMeterElements.threadGroup(NUMBER_OF_USER_ACCOUNTS, RAMP_UP_PERIOD, 1));

    threadGroup.add(JMeterElements.csvDataSet(getPathToTestDataFile(getCsvConfigPath())));
    threadGroup.add(JMeterElements.cookieManager());
    threadGroup.add(JMeterElements.defaultSampler());
    threadGroup.add(JMeterElements.onceOnlyController())
            .add(JMeterElements.loginSampler());

    // Add HTTP sampler for test endpoint
    threadGroup.add(JMeterElements.httpGetSampler(getTestEndpoint()));

    return testPlan;
}
 
Example 6
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 7
Source File: InstructorStudentEnrollmentLNPTest.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected ListedHashTree getLnpTestPlan() {
    ListedHashTree testPlan = new ListedHashTree(JMeterElements.testPlan());
    HashTree threadGroup = testPlan.add(
            JMeterElements.threadGroup(NUM_INSTRUCTORS, RAMP_UP_PERIOD, 1));

    threadGroup.add(JMeterElements.csvDataSet(getPathToTestDataFile(getCsvConfigPath())));
    threadGroup.add(JMeterElements.cookieManager());
    threadGroup.add(JMeterElements.defaultSampler());

    threadGroup.add(JMeterElements.onceOnlyController())
            .add(JMeterElements.loginSampler())
            .add(JMeterElements.csrfExtractor("csrfToken"));

    // Add HTTP sampler for test endpoint
    HeaderManager headerManager = JMeterElements.headerManager(getRequestHeaders());
    threadGroup.add(JMeterElements.httpSampler(getTestEndpoint(), PUT, "${enrollData}"))
            .add(headerManager);

    return testPlan;
}
 
Example 8
Source File: FeedbackSessionViewLNPTest.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected ListedHashTree getLnpTestPlan() {
    ListedHashTree testPlan = new ListedHashTree(JMeterElements.testPlan());
    HashTree threadGroup = testPlan.add(
            JMeterElements.threadGroup(NUMBER_OF_USER_ACCOUNTS, RAMP_UP_PERIOD, 1));
    threadGroup.add(JMeterElements.csvDataSet(getPathToTestDataFile(getCsvConfigPath())));
    threadGroup.add(JMeterElements.cookieManager());
    threadGroup.add(JMeterElements.defaultSampler());
    threadGroup.add(JMeterElements.onceOnlyController())
            .add(JMeterElements.loginSampler());

    // Add HTTP samplers for test endpoint
    String getSessionsPath = "webapi/student?courseid=${courseId}";
    threadGroup.add(JMeterElements.httpSampler(getSessionsPath, GET, null));

    String getSessionDetailsPath = "webapi/session?courseid=${courseId}&fsname=${fsname}&intent=STUDENT_SUBMISSION";
    threadGroup.add(JMeterElements.httpSampler(getSessionDetailsPath, GET, null));

    String getQuestionsPath = "webapi/questions?courseid=${courseId}&fsname=${fsname}&intent=STUDENT_SUBMISSION";
    threadGroup.add(JMeterElements.httpSampler(getQuestionsPath, GET, null));

    return testPlan;
}
 
Example 9
Source File: JMeterRecorder.java    From jsflight with Apache License 2.0 6 votes vote down vote up
private void placeAndProcessTestElements(HashTree hashTree, List<TestElement> samples)
{
    for (TestElement element : samples)
    {
        List<TestElement> descendants = findAndRemoveHeaderManagers(element);
        HashTree parent = hashTree.add(element);
        descendants.forEach(parent::add);

        if (element instanceof HTTPSamplerBase)
        {
            HTTPSamplerBase http = (HTTPSamplerBase)element;

            LOG.info("Start sampler processing");
            scriptProcessor.processScenario(http, parent, vars, this);
            LOG.info("Stop sampler processing");
        }
    }
}
 
Example 10
Source File: InstructorSessionResultLNPTest.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
private void addLoadQuestionPanelController(HashTree threadGroup, Map<String, String> argumentsMap) {
    HashTree loadQuestionPanelController = threadGroup.add(JMeterElements.genericController());

    loadQuestionPanelController.add(JMeterElements.defaultSampler(argumentsMap));

    for (int i = 1; i <= NUMBER_OF_QUESTIONS; i++) {
        String getSessionResultPath = String.format("webapi/result?questionid=${feedbackQuestion_%d}", i);
        loadQuestionPanelController.add(JMeterElements.httpGetSampler(getSessionResultPath));
    }
}
 
Example 11
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 12
Source File: InstructorSessionResultLNPTest.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
private void addLoadSectionsController(HashTree threadGroup, Map<String, String> sectionsArgumentsMap) {
    HashTree loadSectionsController = threadGroup.add(JMeterElements.genericController());

    loadSectionsController.add(JMeterElements.defaultSampler(sectionsArgumentsMap));

    String getSectionsPath = "webapi/course/sections";
    loadSectionsController.add(JMeterElements.httpGetSampler(getSectionsPath));
}
 
Example 13
Source File: Http2JMeter.java    From jsflight with Apache License 2.0 5 votes vote down vote up
public void addAuthHttpSample(HashTree txTree, String login)
{
    HTTPSampler sample = new HTTPSampler();
    sample.setProperty(TestElement.GUI_CLASS, "HttpTestSampleGui");
    sample.setDomain("${host}");
    sample.setProperty(HTTPSampler.PORT, "${port}");
    sample.setMethod("GET");
    sample.setPath("/sd/operator?processAs=" + login);
    sample.setFollowRedirects(true);
    sample.setName("Auth " + login);
    txTree.add(sample);
}
 
Example 14
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 15
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 16
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 17
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 18
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 19
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 20
Source File: InstructorSessionResultLNPTest.java    From teammates with GNU General Public License v2.0 3 votes vote down vote up
private void addLoadSectionPanelController(HashTree threadGroup, Map<String, String> argumentsMap) {
    HashTree loadSectionPanelController = threadGroup.add(
            JMeterElements.foreachController("sectionNumber", "sectionNumber"));

    loadSectionPanelController.add(JMeterElements.defaultSampler(argumentsMap));

    String getSessionResultPath = "webapi/result?frgroupbysection=Section ${sectionNumber}";

    loadSectionPanelController.add(JMeterElements.httpGetSampler(getSessionResultPath));
}