Java Code Examples for org.apache.jmeter.util.JMeterUtils#getPropDefault()

The following examples show how to use org.apache.jmeter.util.JMeterUtils#getPropDefault() . 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: JMeterPluginsUtils.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
public static String getShortHostname(String host) {
    log.debug("getShortHostname: " + host);
    try {
        String defaultRegex = "([\\w\\-]+)\\..*";
        String hostnameRegex = JMeterUtils.getPropDefault("jmeterPlugin.perfmon.label.useHostname.pattern", defaultRegex);
        log.debug("hostnameRegex: " + hostnameRegex);
        Pattern p = Pattern.compile(hostnameRegex, Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(host);
        if (m.matches()) {
            String shortName = m.group(1);
            log.debug("shortName of " + host + " is: " + shortName);
            host = shortName;
        }
    } catch (Exception e) {
        log.warn("getShortHostname exception: " + e.getClass().getName() + " :: " + e.getMessage());
        log.debug("getShortHostname exception: ", e);
    }
    return host;
}
 
Example 2
Source File: GraphModelToCsvExporter.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
public GraphModelToCsvExporter(
        AbstractMap<String, AbstractGraphRow> rows,
        File destFile,
        String csvSeparator,
        String xAxisLabel,
        NumberRenderer xAxisRenderer,
        int hideNonRepValLimit) {
    this.destFile = destFile;
    this.model = rows;
    this.csvSeparator = csvSeparator;
    this.decimalSeparator = new DecimalFormatSymbols().getDecimalSeparator();
    this.xAxisLabel = xAxisLabel;
    this.hideNonRepValLimit = hideNonRepValLimit;
    if (xAxisRenderer != null && xAxisRenderer instanceof DividerRenderer) {
        this.xAxisRenderer = new DividerRenderer(((DividerRenderer) xAxisRenderer).getFactor());
    } else if (xAxisRenderer != null && xAxisRenderer instanceof DateTimeRenderer) {
        String format = JMeterUtils.getPropDefault("jmeterPlugin.csvTimeFormat", "HH:mm:ss" + decimalSeparator + "S");
        dateFormatter = new SimpleDateFormat(format);
    }
}
 
Example 3
Source File: AutoStop.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private void stopTestViaUDP(String command) {
    try {
        int port = JMeterUtils.getPropDefault("jmeterengine.nongui.port", JMeter.UDP_PORT_DEFAULT);
        log.info("Sending " + command + " request to port " + port);
        DatagramSocket socket = new DatagramSocket();
        byte[] buf = command.getBytes("ASCII");
        InetAddress address = InetAddress.getByName("localhost");
        DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port);
        socket.send(packet);
        socket.close();
    } catch (Exception e) {
        //e.printStackTrace();
        log.error(e.getMessage());
    }

}
 
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: AbstractThreadStarter.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
protected DynamicThread makeThread(long threadIndex) {
    boolean onErrorStopTest = owner.getOnErrorStopTest();
    boolean onErrorStopTestNow = owner.getOnErrorStopTestNow();
    boolean onErrorStopThread = owner.getOnErrorStopThread();
    boolean onErrorStartNextLoop = owner.getOnErrorStartNextLoop();
    final DynamicThread jmeterThread = new DynamicThread(treeClone, this.owner, notifier);
    jmeterThread.setThreadNum((int) threadIndex);
    jmeterThread.setThreadGroup(this.owner);
    jmeterThread.setInitialContext(context);
    String groupName = getName();
    String distributedPrefix = JMeterUtils.getPropDefault(AbstractSimpleThreadGroup.THREAD_GROUP_DISTRIBUTED_PREFIX_PROPERTY_NAME, "");
    final String threadName = distributedPrefix + (distributedPrefix.isEmpty() ? "" : "-") + groupName + " " + groupIndex + "-" + (threadIndex + 1);
    jmeterThread.setThreadName(threadName);
    jmeterThread.setEngine(engine);
    jmeterThread.setOnErrorStopTest(onErrorStopTest);
    jmeterThread.setOnErrorStopTestNow(onErrorStopTestNow);
    jmeterThread.setOnErrorStopThread(onErrorStopThread);
    jmeterThread.setOnErrorStartNextLoop(onErrorStartNextLoop);
    return jmeterThread;
}
 
Example 6
Source File: HttpUtils.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private static AbstractHttpClient createHTTPClient() {
    AbstractHttpClient client = new DefaultHttpClient();
    String proxyHost = System.getProperty("https.proxyHost", "");
    if (!proxyHost.isEmpty()) {
        int proxyPort = Integer.parseInt(System.getProperty("https.proxyPort", "-1"));
        log.info("Using proxy " + proxyHost + ":" + proxyPort);
        HttpParams params = client.getParams();
        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
        params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

        String proxyUser = System.getProperty(JMeter.HTTP_PROXY_USER, JMeterUtils.getProperty(JMeter.HTTP_PROXY_USER));
        if (proxyUser != null) {
            log.info("Using authenticated proxy with username: " + proxyUser);
            String proxyPass = System.getProperty(JMeter.HTTP_PROXY_PASS, JMeterUtils.getProperty(JMeter.HTTP_PROXY_PASS));

            String localHost;
            try {
                localHost = InetAddress.getLocalHost().getCanonicalHostName();
            } catch (Throwable e) {
                log.error("Failed to get local host name, defaulting to 'localhost'", e);
                localHost = "localhost";
            }

            AuthScope authscope = new AuthScope(proxyHost, proxyPort);
            String proxyDomain = JMeterUtils.getPropDefault("http.proxyDomain", "");
            NTCredentials credentials = new NTCredentials(proxyUser, proxyPass, localHost, proxyDomain);
            client.getCredentialsProvider().setCredentials(authscope, credentials);
        }
    }
    return client;
}
 
Example 7
Source File: WebDriverSampler.java    From jmeter-plugins-webdriver with Apache License 2.0 5 votes vote down vote up
public WebDriverSampler() {
    Class<SampleResult> srClass;
    this.scriptEngineManager = new ScriptEngineManager();
    String className = JMeterUtils.getPropDefault("webdriver.sampleresult_class", SampleResult.class.getCanonicalName());
    try {
        srClass = (Class<SampleResult>) Class.forName(className);
    } catch (ClassNotFoundException e) {
        LOGGER.warn("Class " + className + " not found, defaulted to " + SampleResult.class.getCanonicalName(), e);
        srClass = SampleResult.class;
    }
    sampleResultClass = srClass;
}
 
Example 8
Source File: JMeterProxyControl.java    From jsflight with Apache License 2.0 5 votes vote down vote up
private void initKeyStore() throws IOException, GeneralSecurityException
{
    switch (KEYSTORE_MODE)
    {
    case DYNAMIC_KEYSTORE:
        storePassword = getPassword();
        keyPassword = getPassword();
        initDynamicKeyStore();
        break;
    case JMETER_KEYSTORE:
        storePassword = getPassword();
        keyPassword = getPassword();
        initJMeterKeyStore();
        break;
    case USER_KEYSTORE:
        storePassword = JMeterUtils.getPropDefault("proxy.cert.keystorepass", DEFAULT_PASSWORD); // $NON-NLS-1$;
        keyPassword = JMeterUtils.getPropDefault("proxy.cert.keypassword", DEFAULT_PASSWORD); // $NON-NLS-1$;
        LOG.info("HTTP(S) Test Script Recorder will use the keystore '" + CERT_PATH_ABS + "' with the alias: '"
                + CERT_ALIAS + "'");
        initUserKeyStore();
        break;
    case NONE:
        throw new IOException("Cannot find keytool application and no keystore was provided");
    default:
        throw new IllegalStateException("Impossible case: " + KEYSTORE_MODE);
    }
}
 
Example 9
Source File: AbstractIPSampler.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public AbstractIPSampler() {
    //recvBuf = ByteBuffer.allocateDirect(JMeterUtils.getPropDefault(RECV_BUFFER_LEN_PROPERTY, 1024 * 4));
    recvDataLimit = JMeterUtils.getPropDefault(RESULT_DATA_LIMIT, Integer.MAX_VALUE);
    if (recvDataLimit < Integer.MAX_VALUE) {
        log.info("Limiting result data to " + recvDataLimit);
    }
}
 
Example 10
Source File: HttpSimpleTableServer.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public static void main(String args[]) {
    JMeterUtils.loadJMeterProperties("jmeter.properties");
    String dataset = JMeterUtils.getPropDefault(
            "jmeterPlugin.sts.datasetDirectory",
            HttpSimpleTableControl.DEFAULT_DATA_DIR);
    int port = JMeterUtils.getPropDefault("jmeterPlugin.sts.port",
            HttpSimpleTableControl.DEFAULT_PORT);
    boolean timestamp = JMeterUtils.getPropDefault(
            "jmeterPlugin.sts.addTimestamp",
            HttpSimpleTableControl.DEFAULT_TIMESTAMP);

    // default level
    Configurator.setLevel(log.getName(), Level.INFO);
    // allow override by system properties
    
    String loglevelStr = JMeterUtils.getPropDefault(
            "loglevel", HttpSimpleTableControl.DEFAULT_LOG_LEVEL);
    System.out.println("loglevel=" + loglevelStr);
    
    //Configurator.setLevel(log.getName(), Level.toLevel(loglevelStr));
    Configurator.setRootLevel(Level.toLevel(loglevelStr));
    Configurator.setLevel(log.getName(), Level.toLevel(loglevelStr));
    bStartFromMain=true;
    
    HttpSimpleTableServer serv = new HttpSimpleTableServer(port, timestamp,
            dataset);

    log.info("Creating HttpSimpleTable ...");
    log.info("------------------------------");
    log.info("SERVER_PORT : " + port);
    log.info("DATASET_DIR : " + dataset);
    log.info("TIMESTAMP : " + timestamp);
    log.info("------------------------------");
    log.info("STS_VERSION : " + STS_VERSION);
    ServerRunner.executeInstance(serv);
}
 
Example 11
Source File: PerfMonCollector.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
protected PerfMonAgentConnector getConnector(String host, int port) throws IOException {
    log.debug("Trying new connector");
    SocketAddress addr = new InetSocketAddress(host, port);
    Transport transport;
    try {
        transport = TransportFactory.TCPInstance(addr);
        if (!transport.test()) {
            throw new IOException("Agent is unreachable via TCP");
        }
    } catch (IOException e) {
        log.info("Can't connect TCP transport for host: " + addr.toString(), e);
        boolean useUDP = JMeterUtils.getPropDefault("jmeterPlugin.perfmon.useUDP", false);
        if (!useUDP) {
            throw e;
        } else {
            try {
                log.debug("Connecting UDP");
                transport = TransportFactory.UDPInstance(addr);
                if (!transport.test()) {
                    throw new IOException("Agent is unreachable via UDP");
                }
            } catch (IOException ex) {
                log.info("Can't connect UDP transport for host: " + addr.toString(), ex);
                throw ex;
            }
        }
    }
    NewAgentConnector conn = new NewAgentConnector();
    conn.setTransport(transport);
    transport.setInterval(interval);
    return conn;
}
 
Example 12
Source File: ConcurrencyThreadStarter.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Check if we need to reload properties
 *
 * @param now Now as Millis
 */
void checkNeedsPropertiesReloading(long now) {
    if (CACHING_VALIDITY_MS > 0 && now - lastCachedTime > CACHING_VALIDITY_MS) {
        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 13
Source File: FifoMap.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private BlockingQueue<Object> getFifo(String fifoName) {
    if (super.containsKey(fifoName)) {
        return super.get(fifoName);
    } else {
        BlockingQueue<Object> fifo = new LinkedBlockingQueue<Object>(JMeterUtils.getPropDefault(FifoMap.CAPACITY_PROP, Integer.MAX_VALUE));
        super.put(fifoName, fifo);
        return fifo;
    }
}
 
Example 14
Source File: DistributedTestControlGui.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public TestElement createTestElement() {
    String srv_list = JMeterUtils.getPropDefault(DistributedTestControl.PROP_HOSTS, "127.0.0.1");
    ArrayList<String> data = new ArrayList<String>(Arrays.asList(srv_list.split(",")));

    for (String srv_name : data) {
        serversPanel.add(srv_name);
    }

    DistributedTestControl control = new DistributedTestControl();
    control.setData(data);
    modifyTestElement(control);
    return control;
}
 
Example 15
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 16
Source File: DbMonCollector.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
public DbMonCollector() {
    // TODO: document it
    interval = JMeterUtils.getPropDefault("jmeterPlugin.dbmon.interval", 1000);
}
 
Example 17
Source File: JMXMonCollector.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
public JMXMonCollector() {
    interval = JMeterUtils.getPropDefault("jmeterPlugin.jmxmon.interval", 1000);
}
 
Example 18
Source File: FifoPop.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
public FifoPop() {
    timeout = JMeterUtils.getPropDefault(FifoMap.TIMEOUT_PROP, Long.MAX_VALUE);
}
 
Example 19
Source File: PerfMonCollector.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
public PerfMonCollector() {
    interval = JMeterUtils.getPropDefault("jmeterPlugin.perfmon.interval", 1000) / 1000;
}
 
Example 20
Source File: JMeterCollectorRegistry.java    From jmeter-prometheus-plugin with Apache License 2.0 4 votes vote down vote up
public static String threadMetricName() {
	return JMeterUtils.getPropDefault(COLLECT_THREADS_NAME, COLLECT_THREADS_NAME_DEFAULT);
}