Java源码示例:org.apache.jmeter.gui.tree.JMeterTreeListener

示例1
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);
      
  }
 
示例2
@Test
public void testGui() throws Exception {
    if (GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
        return;
    }
    String actions = ActionRouter.class.getProtectionDomain().getCodeSource().getLocation().getFile();
    String renderers = RenderAsHTML.class.getProtectionDomain().getCodeSource().getLocation().getFile();
    JMeterUtils.setProperty("search_paths", actions + ";" + renderers);
    TestProvider prov = new TestProvider();
    JMeterTreeModel mdl = prov.getTreeModel();
    JMeterTreeListener a = new JMeterTreeListener();
    a.setActionHandler(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            log.debug("Action " + actionEvent);
        }
    });
    a.setModel(mdl);
    GuiPackage.getInstance(a, mdl);

    DebuggerDialog obj = new DebuggerDialogMock(prov.getTreeModel());
    obj.componentShown(null);
    obj.started();
    obj.statusRefresh(JMeterContextService.getContext());
    obj.frozenAt(new SamplerDebug());
    obj.continuing();
    obj.stopped();
    obj.componentHidden(null);
}
 
示例3
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
}
 
示例4
@Test
public void displayGUI() throws InterruptedException, IOException, IllegalUserActionException {
    if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
        TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/vars.jmx", "vars.jmx");
        JMeterTreeModel mdl = prov.getTreeModel();
        JMeterTreeListener a = new JMeterTreeListener();
        a.setActionHandler(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                log.debug("Action " + actionEvent);
            }
        });
        a.setModel(mdl);

        GuiPackage.getInstance(a, mdl);
        String actions = ActionRouter.class.getProtectionDomain().getCodeSource().getLocation().getFile();
        String renderers = RenderAsHTML.class.getProtectionDomain().getCodeSource().getLocation().getFile();
        JMeterUtils.setProperty("search_paths", actions + ";" + renderers);
        MainFrame mf = new MainFrame(mdl, a); // does important stuff inside
        ComponentFinder<JMeterToolBar> finder = new ComponentFinder<>(JMeterToolBar.class);
        JMeterToolBar tb = finder.findComponentIn(mf);
        tb.add(new JButton("test"));

        new TimeFunction();
        long now = System.currentTimeMillis();
        JMeterUtils.setProperty("START.MS", Long.toString(now));
        Date today = new Date(now);
        JMeterUtils.setProperty("START.YMD", new SimpleDateFormat("yyyyMMdd").format(today));
        JMeterUtils.setProperty("START.HMS", new SimpleDateFormat("HHmmss").format(today));

        DebuggerDialogMock frame = new DebuggerDialogMock(mdl);

        frame.setPreferredSize(new Dimension(800, 600));
        frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
        while (frame.isVisible()) {
            Thread.sleep(1000);
        }
    }
}