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

The following examples show how to use org.apache.jmeter.util.JMeterUtils#getProperty() . 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: UltimateThreadGroup.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private CollectionProperty getLoadFromExternalProperty() {
    String loadProp = JMeterUtils.getProperty(EXTERNAL_DATA_PROPERTY);
    log.debug("Profile prop: " + loadProp);
    if (loadProp != null && loadProp.length() > 0) {
        //expected format : threads_schedule="spawn(1,1s,1s,1s,1s) spawn(2,1s,3s,1s,2s)"
        log.info("GUI threads profile will be ignored");
        PowerTableModel dataModel = new PowerTableModel(UltimateThreadGroupGui.columnIdentifiers, UltimateThreadGroupGui.columnClasses);
        String[] chunks = loadProp.split("\\)");

        for (String chunk : chunks) {
            try {
                parseChunk(chunk, dataModel);
            } catch (RuntimeException e) {
                log.warn("Wrong  chunk ignored: " + chunk, e);
            }
        }

        log.info("Setting threads profile from property " + EXTERNAL_DATA_PROPERTY + ": " + loadProp);
        return JMeterPluginsUtils.tableModelRowsToCollectionProperty(dataModel, UltimateThreadGroup.DATA_PROPERTY);
    }
    return null;
}
 
Example 2
Source File: VariableThroughputTimer.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private void trySettingLoadFromProperty() {
    String loadProp = JMeterUtils.getProperty(DATA_PROPERTY);
    log.debug("Loading property: {}={}", DATA_PROPERTY, loadProp);
    if (!StringUtils.isEmpty(loadProp)) {
        log.info("GUI load profile will be ignored as property {} is defined", DATA_PROPERTY);
        PowerTableModel dataModel = new PowerTableModel(VariableThroughputTimer.columnIdentifiers, VariableThroughputTimer.columnClasses);

        String[] chunks = loadProp.split("\\)");

        for (String chunk : chunks) {
            try {
                parseChunk(chunk, dataModel);
            } catch (RuntimeException e) {
                log.warn("Wrong load chunk {} will be ignored", chunk, e);
            }
        }

        log.info("Setting load profile from property {}: {}", DATA_PROPERTY, loadProp);
        overrideProp = JMeterPluginsUtils.tableModelRowsToCollectionProperty(dataModel, VariableThroughputTimer.DATA_PROPERTY);
    }
}
 
Example 3
Source File: HonoSampler.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
int getSemaphores() {
    synchronized (semaphoreLock) {
        final String semaphores = JMeterUtils.getProperty(HONO_PREFIX + getAddress());
        if (semaphores == null) {
            return 0;
        } else {
            return Integer.parseInt(semaphores);
        }
    }
}
 
Example 4
Source File: ColorsDispatcherFactory.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public static ColorsDispatcher getColorsDispatcher() {
    String customDispatcher = JMeterUtils.getProperty("jmeterPlugin.customColorsDispatcher");
    String customOptions = JMeterUtils.getProperty("jmeterPlugin.customColorsDispatcher.options");
    if (customDispatcher != null) {
        if (customDispatcher.equalsIgnoreCase("huerotate")) {
            log.debug("customDispatcher hue rotate");
            return new HueRotatePalette(customOptions);
        } else if (customDispatcher.equalsIgnoreCase("custompalette")) {
            log.debug("customDispatcher custom palette");
            return new CustomPalette(customOptions);
        }
    }
    log.debug("Original boring cycle colors");
    return new CycleColors(); // original "cycle" colors dispatcher
}
 
Example 5
Source File: ElasticsearchBackendClient.java    From jmeter-elasticsearch-backend-listener with MIT License 4 votes vote down vote up
@Override
public void setupTest(BackendListenerContext context) throws Exception {
    try {
        this.filters = new HashSet<>();
        this.fields = new HashSet<>();
        this.modes = new HashSet<>(Arrays.asList("info", "debug", "error", "quiet"));
        this.bulkSize = Integer.parseInt(context.getParameter(ES_BULK_SIZE));
        this.timeoutMs = Integer.parseInt((context.getParameter(ES_TIMEOUT_MS)));
        this.buildNumber = (JMeterUtils.getProperty(ElasticsearchBackendClient.BUILD_NUMBER) != null
                && !JMeterUtils.getProperty(ElasticsearchBackendClient.BUILD_NUMBER).trim().equals(""))
                        ? Integer.parseInt(JMeterUtils.getProperty(ElasticsearchBackendClient.BUILD_NUMBER)) : 0;

        setSSLConfiguration(context);

        if (context.getParameter(ES_AWS_ENDPOINT).equalsIgnoreCase("")) {
            client = RestClient
                    .builder(new HttpHost(context.getParameter(ES_HOST),
                            Integer.parseInt(context.getParameter(ES_PORT)), context.getParameter(ES_SCHEME)))
                    .setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000)
                            .setSocketTimeout((int) timeoutMs))
                    .setFailureListener(new RestClient.FailureListener() {
                        @Override
                        public void onFailure(Node node) {
                            logger.error("Error with node: " + node.toString());
                        }
                    }).build();
        } else {
            AWS4Signer signer = new AWS4Signer();
            signer.setServiceName(SERVICE_NAME);
            signer.setRegionName(context.getParameter(ES_AWS_REGION));
            HttpRequestInterceptor interceptor = new AWSRequestSigningApacheInterceptor(SERVICE_NAME, signer,
                    credentialsProvider);
            client = RestClient.builder(HttpHost.create(context.getParameter(ES_AWS_ENDPOINT)))
                    .setHttpClientConfigCallback(hacb -> hacb.addInterceptorLast(interceptor)).build();
        }

        convertParameterToSet(context, ES_SAMPLE_FILTER, this.filters);
        convertParameterToSet(context, ES_FIELDS, this.fields);

        this.sender = new ElasticSearchMetricSender(client, context.getParameter(ES_INDEX).toLowerCase(),
                context.getParameter(ES_AUTH_USER), context.getParameter(ES_AUTH_PWD),
                context.getParameter(ES_AWS_ENDPOINT));
        this.sender.createIndex();
        this.esVersion = sender.getElasticSearchVersion();

        checkTestMode(context.getParameter(ES_TEST_MODE));
        super.setupTest(context);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to connect to the ElasticSearch engine", e);
    }
}
 
Example 6
Source File: AbstractGraphPanelVisualizer.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
private void reloadLabelToColorMapping() {

        String labelToColorMappingString = JMeterUtils.getProperty("jmeterPlugin.labelToColorMapping");
        labelToColorMapping = LabelToColorMapping.load(labelToColorMappingString);
    }
 
Example 7
Source File: AbstractGraphPanelVisualizer.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
private void setOptionsFromProperties(GraphPanelChart graph) {
    // moved this into jmeter part, because charting package knows nothing on JMEters
    //properties from user.properties
    String cfgDrawGradient = JMeterUtils.getProperty("jmeterPlugin.drawGradient");
    if (cfgDrawGradient != null) {
        graph.getChartSettings().setDrawGradient("true".equalsIgnoreCase(cfgDrawGradient.trim()));
    }
    String cfgNeverDrawFinalZeroingLines = JMeterUtils.getProperty("jmeterPlugin.neverDrawFinalZeroingLines");
    if (cfgNeverDrawFinalZeroingLines != null) {
        graph.getChartSettings().setConfigNeverDrawFinalZeroingLines("true".equalsIgnoreCase(cfgNeverDrawFinalZeroingLines.trim()));
    }

    String cfgOptimizeYAxis = JMeterUtils.getProperty("jmeterPlugin.optimizeYAxis");
    if (cfgOptimizeYAxis != null) {
        graph.getChartSettings().setConfigOptimizeYAxis("true".equalsIgnoreCase(cfgOptimizeYAxis.trim()));
    }

    String cfgNeverDrawFinalCurrentX = JMeterUtils.getProperty("jmeterPlugin.neverDrawCurrentX");
    if (cfgNeverDrawFinalCurrentX != null) {
        graph.getChartSettings().setConfigNeverDrawCurrentX("true".equalsIgnoreCase(cfgNeverDrawFinalCurrentX.trim()));
    }
    String cfgCsvSeparator = JMeterUtils.getProperty("jmeterPlugin.csvSeparator");
    if (cfgCsvSeparator != null) {
        graph.getChartSettings().setConfigCsvSeparator(cfgCsvSeparator);
    }
    String cfgUseRelativeTime = JMeterUtils.getProperty("jmeterPlugin.useRelativeTime");
    if (cfgUseRelativeTime != null) {
        graph.getChartSettings().setUseRelativeTime("true".equalsIgnoreCase(cfgUseRelativeTime.trim()));
    }
    String cfgGraphLineWitdh = JMeterUtils.getProperty("jmeterPlugin.graphLineWidth");
    if (cfgGraphLineWitdh != null) {
        graph.getChartSettings().setLineWidth(JMeterPluginsUtils.getFloatFromString(cfgGraphLineWitdh, 1.0f));
    }
    String cfgGraphLineMarker = JMeterUtils.getProperty("jmeterPlugin.drawLineMarker");
    if (cfgGraphLineMarker != null) {
        boolean removeMarkers = "false".equalsIgnoreCase(cfgGraphLineMarker.trim());
        if (removeMarkers) {
            graph.getChartSettings().setChartMarkers(ChartSettings.CHART_MARKERS_NO);
        }
    }
}
 
Example 8
Source File: PerfMonCollector.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
private void initiateConnector(String host, int port, int index, String metric, String params) {
    InetSocketAddress addr = new InetSocketAddress(host, port);
    String stringKey = addr.toString() + "#" + index;
    String labelHostname = host;

    String useHostnameProp = JMeterUtils.getProperty("jmeterPlugin.perfmon.label.useHostname");
    if (useHostnameProp != null && Boolean.parseBoolean(useHostnameProp)) {
        labelHostname = JMeterPluginsUtils.getShortHostname(host);
    }

    // handle label parameter
    MetricParams paramsParsed = MetricParams.createFromString(params);
    String label;
    if (paramsParsed.getLabel().isEmpty()) {
        label = labelHostname + " " + metric;
        if (!params.isEmpty()) {
            label = label + " " + params;
        }
    } else {
        label = labelHostname + " " + metric + " " + paramsParsed.getLabel();

        String[] tokens = params.split("(?<!\\\\)" + PerfMonMetricGetter.DVOETOCHIE);

        params = "";

        for (String token : tokens) {
            if (!token.startsWith("label=")) {
                if (params.length() != 0) {
                    params = params + PerfMonMetricGetter.DVOETOCHIE;
                }
                params = params + token;
            }
        }
    }

    try {
        if (connectors.containsKey(addr)) {
            connectors.get(addr).addMetric(metric, params, label);
        } else {
            PerfMonAgentConnector connector = getConnector(host, port);
            connector.addMetric(metric, params, label);
            connectors.put(addr, connector);
        }
    } catch (IOException e) {
        log.error("Problems creating connector", e);
        connectors.put(stringKey, new UnavailableAgentConnector(e));
    }
}