org.apache.jorphan.collections.ListedHashTree Java Examples

The following examples show how to use org.apache.jorphan.collections.ListedHashTree. 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: ConcurrencyThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 25000)
public void testSetDoneThreadsAfterHold() throws Exception {
    Object[] objects = createTestPlan();
    ListedHashTree hashTree = (ListedHashTree) objects[0];
    ConcurrencyThreadGroupExt ctg = (ConcurrencyThreadGroupExt) objects[1];
    ListenerNotifier notifier = new ListenerNotifier();

    long startTime = System.currentTimeMillis();
    ctg.start(1, notifier, hashTree, new StandardJMeterEngine());

    Thread threadStarter = ctg.getThreadStarter();
    threadStarter.join();
    long endTime = System.currentTimeMillis();

    // wait when all thread stopped
    Thread.sleep(5000);

    assertTrue((endTime - startTime) < 20000);
    //  ALL threads must be stopped
    assertEquals(0, ctg.getNumberOfThreads());
}
 
Example #2
Source File: ConcurrencyThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testCachingOfProperties() throws InterruptedException {
    Object[] objects = createTestPlan();
    ListedHashTree hashTree = (ListedHashTree) objects[0];
    ConcurrencyThreadGroupExt ctg = (ConcurrencyThreadGroupExt) objects[1];
    
    ConcurrencyThreadStarter starter = new ConcurrencyThreadStarter(0, new ListenerNotifier(), 
            hashTree, new StandardJMeterEngine(), ctg);
    long lastCachedTime = starter.getLastCachedTime();
    Thread.sleep(ConcurrencyThreadStarter.CACHING_VALIDITY_MS / 2); // NOSONAR Intentional
    starter.checkNeedsPropertiesReloading(System.currentTimeMillis());
    assertEquals(lastCachedTime, starter.getLastCachedTime());
    Thread.sleep(ConcurrencyThreadStarter.CACHING_VALIDITY_MS * 2); // NOSONAR Intentional
    starter.checkNeedsPropertiesReloading(System.currentTimeMillis());
    assertNotEquals(lastCachedTime, starter.getLastCachedTime());
}
 
Example #3
Source File: CustomTreeClonerTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlow() throws Exception {
    final CookieManager manager = new CookieManager();
    final ThroughputController controller = new ThroughputController();

    CustomTreeCloner cloner = new CustomTreeCloner();
    HashTree tree = createTestTree(controller, manager);
    tree.traverse(cloner);

    ListedHashTree clonedTree = cloner.getClonedTree();
    ListedHashTree loop = (ListedHashTree) clonedTree.values().toArray()[0];

    Object actualController = loop.keySet().toArray()[0];
    assertTrue("This links should be to the same instance", controller == actualController);

    Object actualManager = loop.get(actualController).keySet().toArray()[0];
    assertTrue("Cookie manager should be changed to ThreadSafe instance", actualManager instanceof ThreadSafeCookieManager);
}
 
Example #4
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 #5
Source File: AbstractSimpleThreadGroup.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void start(int groupNum, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine) {
    running = true;

    int numThreads = getNumThreads();

    log.info("Starting thread group number " + groupNum + " threads " + numThreads);

    long now = System.currentTimeMillis(); // needs to be same time for all threads in the group
    final JMeterContext context = JMeterContextService.getContext();
    for (int i = 0; running && i < numThreads; i++) {
        JMeterThread jmThread = makeThread(groupNum, notifier, threadGroupTree, engine, i, context);
        scheduleThread(jmThread, now); // set start and end time
        Thread newThread = new Thread(jmThread, jmThread.getThreadName());
        registerStartedThread(jmThread, newThread);
        newThread.start();
    }

    log.info("Started thread group number " + groupNum);
}
 
Example #6
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 #7
Source File: DebuggingThreadGroup.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
private DebuggingThread makeThread(int groupCount, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine, int i, JMeterContext context) {
    // had to copy whole method because of this line
    DebuggingThread jmeterThread = new DebuggingThread(threadGroupTree, this, notifier, context);

    boolean onErrorStopTest = getOnErrorStopTest();
    boolean onErrorStopTestNow = getOnErrorStopTestNow();
    boolean onErrorStopThread = getOnErrorStopThread();
    boolean onErrorStartNextLoop = getOnErrorStartNextLoop();
    String groupName = getName();

    jmeterThread.setThreadNum(i);
    jmeterThread.setThreadGroup(this);
    jmeterThread.setInitialContext(context);
    String threadName = groupName + " " + (groupCount) + "-" + (i + 1);
    jmeterThread.setThreadName(threadName);
    jmeterThread.setEngine(engine);
    jmeterThread.setOnErrorStopTest(onErrorStopTest);
    jmeterThread.setOnErrorStopTestNow(onErrorStopTestNow);
    jmeterThread.setOnErrorStopThread(onErrorStopThread);
    jmeterThread.setOnErrorStartNextLoop(onErrorStartNextLoop);
    return jmeterThread;
}
 
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: 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 #10
Source File: FeedbackSessionSubmitLNPTest.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(JMeterElements.csrfExtractor("csrfToken"));

    HeaderManager headerManager = JMeterElements.headerManager(getRequestHeaders());
    threadGroup.add(headerManager);

    for (int i = 1; i <= NUMBER_OF_QUESTIONS; i++) {
        String body = "{\"questionType\": \"TEXT\","
                + "\"recipientIdentifier\": \"${studentEmail}\","
                + "\"responseDetails\": {\"answer\": \"<p>test</p>\", \"questionType\": \"TEXT\"}}";
        String path = "webapi/response?questionid=${question" + i + "id}"
                + "&intent=STUDENT_SUBMISSION";
        threadGroup.add(JMeterElements.httpSampler(path, POST, body));
    }

    return testPlan;
}
 
Example #11
Source File: AbstractThreadStarter.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public AbstractThreadStarter(int groupIndex, AbstractDynamicThreadGroup owner, ListedHashTree listedHashTree, ListenerNotifier listenerNotifier, StandardJMeterEngine standardJMeterEngine) {
    super();
    this.owner = owner;
    this.treeClone = cloneTree(listedHashTree); // it needs owner inside
    this.engine = standardJMeterEngine;
    this.groupIndex = groupIndex;
    this.threadGroupTree = listedHashTree;
    this.notifier = listenerNotifier;
    this.context = JMeterContextService.getContext();
    setDaemon(true);
}
 
Example #12
Source File: AbstractThreadStarter.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
protected ListedHashTree cloneTree(ListedHashTree tree) {
    TreeCloner cloner = new TreeCloner(true);
    tree.traverse(cloner);
    ListedHashTree clonedTree = cloner.getClonedTree();
    if (!clonedTree.isEmpty()) {
        Object firstElement = clonedTree.getArray()[0];
        Controller samplerController = ((AbstractDynamicThreadGroup) firstElement).getSamplerController();
        if (samplerController instanceof VirtualUserController) {
            assert owner != null;
            ((VirtualUserController) samplerController).setOwner(owner);
        }
    }
    return clonedTree;
}
 
Example #13
Source File: ArrivalsThreadGroup.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void start(int groupIndex, ListenerNotifier listenerNotifier, ListedHashTree testTree, StandardJMeterEngine engine) {
    super.start(groupIndex, listenerNotifier, testTree, engine);
    synchronized (this) {
        try {
            wait();
            log.info("Got first arrival");
        } catch (InterruptedException e) {
            log.warn("Interrupted start", e);
        }
    }
}
 
Example #14
Source File: ConcurrencyThreadStarter.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public ConcurrencyThreadStarter(int groupIndex, ListenerNotifier listenerNotifier, ListedHashTree testTree, StandardJMeterEngine engine, ConcurrencyThreadGroup concurrencyThreadGroup) {
    super(groupIndex, concurrencyThreadGroup, testTree, listenerNotifier, engine);
    concurrTG = concurrencyThreadGroup;
    // We cache values
    this.rampUp = owner.getRampUpSeconds();
    this.hold = owner.getHoldSeconds();
    this.steps = owner.getStepsAsLong();
    this.maxConcurr = owner.getTargetLevelAsDouble();
    this.defaultShiftRampup = JMeterUtils.getPropDefault("dynamic_tg.shift_rampup_start", 0L);
    this.lastCachedTime = System.currentTimeMillis();
}
 
Example #15
Source File: AbstractDynamicThreadGroup.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void start(int groupIndex, ListenerNotifier listenerNotifier, ListedHashTree testTree, StandardJMeterEngine engine) {
    running = true;
    threadStarter = getThreadStarter(groupIndex, listenerNotifier, testTree, engine);
    threadStarter.setName(getName() + "-ThreadStarter");
    threadStarter.start();
}
 
Example #16
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 #17
Source File: InstructorSessionResultLNPTest.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected ListedHashTree getLnpTestPlan() {
    ListedHashTree testPlan = new ListedHashTree(JMeterElements.testPlan());
    HashTree threadGroup = testPlan.add(
            JMeterElements.threadGroup(1, 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());

    // Set query param.
    Map<String, String> sectionsArgumentsMap = new HashMap<>();
    sectionsArgumentsMap.put("courseid", "${courseId}");

    Map<String, String> argumentsMap = new HashMap<>(sectionsArgumentsMap);
    argumentsMap.put("fsname", "${fsname}");
    argumentsMap.put("intent", "INSTRUCTOR_RESULT");

    addLoadPageController(threadGroup, argumentsMap);
    addLoadSectionsController(threadGroup, sectionsArgumentsMap);
    addLoadNoResponsePanelController(threadGroup, argumentsMap);
    addLoadQuestionPanelController(threadGroup, argumentsMap);
    addLoadSectionPanelController(threadGroup, argumentsMap);

    return testPlan;
}
 
Example #18
Source File: AbstractSimpleThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testStart() {
    System.out.println("start");
    int groupCount = 0;
    ListenerNotifier notifier = null;
    ListedHashTree threadGroupTree = null;
    StandardJMeterEngine engine = null;
    AbstractSimpleThreadGroup instance = new AbstractSimpleThreadGroupImpl();
    instance.start(groupCount, notifier, threadGroupTree, engine);
}
 
Example #19
Source File: DebuggingThreadGroup.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public void start(int groupCount, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine) {
    JMeterContext context = JMeterContextService.getContext();
    DebuggingThread jmThread = makeThread(groupCount, notifier, threadGroupTree, engine, 0, context);
    Thread newThread = new Thread(jmThread, jmThread.getThreadName());
    if (engine instanceof DebuggerEngine) {
        DebuggerEngine dbgEngine = (DebuggerEngine) engine;
        dbgEngine.setTarget(jmThread);
        dbgEngine.setThread(newThread);

        this.jmeterThread = jmThread;
        this.osThread = newThread;
    }
    newThread.start();
}
 
Example #20
Source File: ArrivalsThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public static ListedHashTree getListedHashTree(AbstractThreadGroup atg, boolean stopThread) {
    ListedHashTree tree = new ListedHashTree();
    TestAction pauser = new TestAction();
    if (stopThread) {
        pauser.setAction(TestAction.STOP);
    } else {
        pauser.setAction(TestAction.PAUSE);
    }
    pauser.setTarget(TestAction.THREAD);

    pauser.setDuration(String.valueOf(300));
    tree.add(atg, pauser);
    return tree;
}
 
Example #21
Source File: ConcurrencyThreadStarterTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 1000)
public void testZeroThreads() {
    ConcurrencyThreadGroupExt ctg = new ConcurrencyThreadGroupExt();
    ctg.setTargetLevel("0");
    ctg.setHold("400000");
    ListedHashTree tree = ArrivalsThreadGroupTest.getListedHashTree(ctg, false);
    ConcurrencyThreadStarter starter = new ConcurrencyThreadStarter(0, null, tree, null, ctg);
    starter.supplyActiveThreads();
}
 
Example #22
Source File: ArrivalsThreadGroupGuiTest.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
public ArrivalsRatePreviewer(ArrivalsThreadGroup atg) {
    super(0, null, new ListedHashTree(), null, atg);
    rollingTime = 0;
    startTime = 0;
}
 
Example #23
Source File: FreeFormArrivalsThreadStarterTest.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
public FreeFormArrivalsThreadStarterEmul(FreeFormArrivalsThreadGroup atg) {
    super(0, new ListenerNotifier(), new ListedHashTree(), new EmulatorJmeterEngine(), atg);
    startTime = System.currentTimeMillis() / 1000;
    rollingTime = System.currentTimeMillis();
}
 
Example #24
Source File: ConcurrencyThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testStartNextLoop() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());

    TestSampleListener listener = new TestSampleListener();

    DebugSampler beforeSampler = new DebugSamplerExt();
    beforeSampler.setName("Before Test Action sampler");

    TestAction testAction = new TestAction();
    testAction.setAction(TestAction.RESTART_NEXT_LOOP);

    DebugSampler afterSampler = new DebugSamplerExt();
    afterSampler.setName("After Test Action sampler");


    ConcurrencyThreadGroup ctg = new ConcurrencyThreadGroup();
    ctg.setProperty(new StringProperty(AbstractThreadGroup.ON_SAMPLE_ERROR, AbstractThreadGroup.ON_SAMPLE_ERROR_CONTINUE));
    ctg.setRampUp("0");
    ctg.setTargetLevel("1");
    ctg.setSteps("0");
    ctg.setHold("5"); // TODO: increase this value for debugging
    ctg.setIterationsLimit("10");
    ctg.setUnit("S");

    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(ctg);
    hashTree.add(ctg, beforeSampler);
    hashTree.add(ctg, testAction);
    hashTree.add(ctg, afterSampler);
    hashTree.add(ctg, listener);

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

    ListenerNotifier notifier = new ListenerNotifier();

    ctg.start(1, notifier, hashTree, new StandardJMeterEngine());

    ctg.waitThreadsStopped();

    for (SampleEvent event : listener.events) {
        assertEquals("Before Test Action sampler", event.getResult().getSampleLabel());
    }
}
 
Example #25
Source File: ConcurrencyThreadGroup.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
@Override
protected Thread getThreadStarter(int groupIndex, ListenerNotifier listenerNotifier, ListedHashTree testTree, StandardJMeterEngine engine) {
    return new ConcurrencyThreadStarter(groupIndex, listenerNotifier, testTree, engine, this);
}
 
Example #26
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 #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: FreeFormArrivalsThreadStarter.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
public FreeFormArrivalsThreadStarter(int groupIndex, ListenerNotifier listenerNotifier, ListedHashTree listedHashTree, StandardJMeterEngine standardJMeterEngine, FreeFormArrivalsThreadGroup owner) {
    super(groupIndex, listenerNotifier, listedHashTree, standardJMeterEngine, owner);
    this.arrivalsTG = owner;
}
 
Example #29
Source File: ArrivalsThreadGroup.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
@Override
protected Thread getThreadStarter(int groupIndex, ListenerNotifier listenerNotifier, ListedHashTree testTree, StandardJMeterEngine engine) {
    return new ArrivalsThreadStarter(groupIndex, listenerNotifier, testTree, engine, this);
}
 
Example #30
Source File: FreeFormArrivalsThreadGroup.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
@Override
protected Thread getThreadStarter(int groupIndex, ListenerNotifier listenerNotifier, ListedHashTree testTree, StandardJMeterEngine engine) {
    return new FreeFormArrivalsThreadStarter(groupIndex, listenerNotifier, testTree, engine, this);
}