org.apache.jmeter.engine.StandardJMeterEngine Java Examples

The following examples show how to use org.apache.jmeter.engine.StandardJMeterEngine. 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: AutoStop.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private void stopTest() {
    stopTries++;

    if (JMeter.isNonGUI()) {
        log.info("Stopping JMeter via UDP call");
        stopTestViaUDP("StopTestNow");
    } else {
        if (stopTries > 10) {
            log.info("Tries more than 10, stop it NOW!");
            StandardJMeterEngine.stopEngineNow();
        } else if (stopTries > 5) {
            log.info("Tries more than 5, stop it!");
            StandardJMeterEngine.stopEngine();
        } else {
            JMeterContextService.getContext().getEngine().askThreadsToStop();
        }
    }
}
 
Example #2
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 #3
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 #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: 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 #7
Source File: Debugger.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
public void start() {
    log.debug("Start debugging");
    frontend.started();

    HashTree hashTree = getSelectedTree();
    StandardJMeterEngine.register(new StateListener()); // oh, dear, they use static field then clean it...
    engine = new DebuggerEngine(JMeterContextService.getContext());
    engine.setStepper(this);
    JMeter.convertSubTree(hashTree);
    engine.configure(hashTree);
    try {
        engine.runTest();
    } catch (JMeterEngineException e) {
        log.error("Failed to pauseContinue debug", e);
        stop();
    }
}
 
Example #8
Source File: ParallelSampler.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void addThreadGroupToEngine(AbstractThreadGroup group) {
    try {
        StandardJMeterEngine engine = JMeterContextService.getContext().getEngine();
        Field groupsField = StandardJMeterEngine.class.getDeclaredField("groups");
        groupsField.setAccessible(true);
        List<AbstractThreadGroup> groups = (List<AbstractThreadGroup>) groupsField.get(engine);
        groups.add(group);
    } catch (ReflectiveOperationException ex) {
        log.warn("Can not add DummyThreadGroup to engine", ex);
    }
}
 
Example #9
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 #10
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 #11
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 #12
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 #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: TestPlanCheckTool.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private HashTree loadJMX(File file) throws Exception {
    HashTree tree = SaveService.loadTree(file);

    // unfortunately core JMeter code does not throw exception, we may only guess...
    if (tree == null) {
        throw new TestPlanBrokenException("There was problems loading test plan. Please investigate error messages above.");
    }

    JMeter.convertSubTree(tree); // Remove the disabled items

    JMeterEngine engine = new StandardJMeterEngine();
    engine.configure(tree);

    return tree;
}
 
Example #15
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 #16
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runRealEngine() throws Exception {
    TestTreeProvider prov = new TestProvider();

    HashTree hashTree = prov.getTestTree();
    JMeter.convertSubTree(hashTree);

    StandardJMeterEngine engine = new StandardJMeterEngine();
    engine.configure(hashTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
}
 
Example #17
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 #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: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoopControllerWithNestedDisableController() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();

    URL resource = WeightedSwitchControllerTest.class.getResource("/disableController.jmx");
    File testPlan = new File(resource.getFile());

    HashTree hashTree = SaveService.loadTree(testPlan);

    hashTree.add(hashTree.getArray()[0], listener);
    JMeter.convertSubTree(hashTree);
    StandardJMeterEngine engine = new StandardJMeterEngine();
    engine.configure(hashTree);
    engine.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(100, listener.events.size());
    assertEquals(50, (int) totalResults.get("Debug 1"));
    assertEquals(50, (int) totalResults.get("Debug 3"));
    assertNull(totalResults.get("Debug 2"));
}
 
Example #20
Source File: BlazeMeterBackendListenerClient.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void handleSampleResults(List<SampleResult> list, BackendListenerContext backendListenerContext) {
    if (isInterruptedThroughUI) {
        return;
    }

    accumulator.addAll(list);
    JSONObject data = JSONConverter.convertToJSON(accumulator, list);

    int counter = 0;
    while (!apiClient.isTestStarted() && counter < 3) {
        log.debug("Waiting for test starting");
        makeDelay();
        counter++;
    }

    try {
        apiClient.sendOnlineData(data);
    } catch (JMeterStopTestException ex) {
        isInterruptedThroughUI = true;
        StandardJMeterEngine.stopEngineNow();
    } catch (IOException e) {
        log.warn("Failed to send data: " + data, e);
    }

    makeDelay();
}
 
Example #21
Source File: AbstractDebugElement.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
protected StepTrigger getHook() {
    StandardJMeterEngine engine = JMeterContextService.getContext().getEngine();
    if (engine instanceof DebuggerEngine) {
        return ((DebuggerEngine) engine).getStepper();
    }
    throw new IllegalStateException();
}
 
Example #22
Source File: ParallelSampler.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void removeThreadGroupFromEngine(AbstractThreadGroup group) {
    try {
        StandardJMeterEngine engine = JMeterContextService.getContext().getEngine();
        Field groupsField = StandardJMeterEngine.class.getDeclaredField("groups");
        groupsField.setAccessible(true);
        List<AbstractThreadGroup> groups = (List<AbstractThreadGroup>) groupsField.get(engine);
        groups.remove(group);
    } catch (ReflectiveOperationException ex) {
        log.warn("Can not remove DummyThreadGroup from engine", ex);
    }
}
 
Example #23
Source File: ParallelSampler.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void changeCookieManager() {
    try {
        StandardJMeterEngine engine = getStandardJMeterEngine();
        Field field = StandardJMeterEngine.class.getDeclaredField("test");
        field.setAccessible(true);
        HashTree testTree = (HashTree) field.get(engine);
        HashTree newHashTree = makeCookieManagerThreadSafe(testTree);
        field.set(engine, newHashTree);
    } catch (Throwable ex) {
        log.warn("Cannot change cookie manager", ex);
    }
}
 
Example #24
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void sample() throws Exception {
    JMeterThread dummy = new JMeterThread(new HashTree(new GenericController()), null, null);
    JMeterContextService.getContext().setEngine(new StandardJMeterEngine());
    JMeterContextService.getContext().setThread(dummy);
    JMeterThread thr = JMeterContextService.getContext().getThread();
    for (int n = 0; n < 1000; n++) {// we're doing good check here because of multi-threads
        log.debug("\n\n\nTry #" + n);
        EmulSampler.instances = 0;
        EmulSampler.count.set(0);
        ParallelSampler obj = new ParallelSampler();
        obj.threadStarted();
        obj.setGenerateParent(true);

        obj.addTestElement(getContextedSampler(thr));
        obj.addTestElement(getContextedSampler(thr));
        obj.addTestElement(getContextedSampler(thr));
        obj.addTestElement(getContextedSampler(thr));
        obj.addTestElement(getContextedSampler(thr));

        SampleResult res = obj.sample(null);
        assertEquals(5, EmulSampler.count.get());
        if (res.getSubResults().length < 5) {
            throw new AssertionError();
        }

        assertEquals(5, res.getSubResults().length);
    }
}
 
Example #25
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 #26
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 #27
Source File: ParallelSampler.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
public StandardJMeterEngine getStandardJMeterEngine() throws IllegalAccessException, NoSuchFieldException {
    Field engine = StandardJMeterEngine.class.getDeclaredField("engine");
    engine.setAccessible(true);
    return (StandardJMeterEngine) engine.get(null);
}
 
Example #28
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testThreadSafeCookieManager() throws Exception {
    CookieManager cookieManager = new CookieManager();
    Cookie c = new Cookie();
    c.setName("name");
    c.setValue("value");
    c.setDomain("blazedemo.com");
    c.setPath("");
    cookieManager.add(c);
    HashTree hashtree = createTestTree(cookieManager);

    TestPlan testPlan = new TestPlan();
    HashTree testPlanHashTree = new HashTree();
    testPlanHashTree.put(testPlan, hashtree);

    StandardJMeterEngine engine = new StandardJMeterEngine();
    engine.configure(testPlanHashTree);

    EmulatorThreadMonitor monitor = new EmulatorThreadMonitor();
    JMeterThread thread = new JMeterThread(hashtree, monitor, null);
    thread.setThreadName("test thread");
    JMeterContextService.getContext().setThread(thread);

    ParallelSampler parallel = new ParallelSampler();
    parallel.testStarted();

    Field field = StandardJMeterEngine.class.getDeclaredField("test");
    field.setAccessible(true);
    HashTree testTree = (HashTree) field.get(engine);

    assertTrue("CookieManager should be changed to ThreadSafeCookieManager", testTree.toString().contains("ThreadSafeCookieManager"));
    ListedHashTree loop = (ListedHashTree) (testTree.values().toArray()[0]);
    ListedHashTree threadSafeManager = ((ListedHashTree) (loop.values().toArray()[0]));

    CookieManager mgr = (CookieManager) threadSafeManager.getArray()[0];
    assertTrue(mgr instanceof ThreadSafeCookieManager);
    assertEquals(1, mgr.getCookieCount());
    JMeterProperty property = mgr.getCookies().get(0);
    assertEquals("name", property.getName());
    assertEquals("blazedemo.com\tTRUE\t\tFALSE\t0\tname\tvalue", property.getStringValue());
}
 
Example #29
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 #30
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());
}