Java Code Examples for org.apache.jmeter.testelement.property.CollectionProperty#size()

The following examples show how to use org.apache.jmeter.testelement.property.CollectionProperty#size() . 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: FirefoxDriverConfig.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
private void setPreferences(FirefoxProfile profile) {
    JMeterProperty property = getProperty(PREFERENCES);
    if (property instanceof NullProperty) {
        return;
    }
    CollectionProperty rows = (CollectionProperty) property;
    for (int i = 0; i < rows.size(); i++) {
        ArrayList row = (ArrayList) rows.get(i).getObjectValue();
        String name = ((JMeterProperty) row.get(0)).getStringValue();
        String value = ((JMeterProperty) row.get(1)).getStringValue();
        switch (value) {
            case "true":
                profile.setPreference(name, true);
                break;
            case "false":
                profile.setPreference(name, false);
                break;
            default:
                profile.setPreference(name, value);
                break;
        }
    }
}
 
Example 2
Source File: BaseCollectorConfig.java    From jmeter-prometheus-plugin with Apache License 2.0 6 votes vote down vote up
public String[] getLabels() {
	JMeterProperty prop = this.getProperty(LABELS);
	if(prop == null || prop instanceof NullProperty) {
		return new String[0];
	}

	CollectionProperty colletion = (CollectionProperty) prop;
	String[] retArray = new String[colletion.size()];
	PropertyIterator it = colletion.iterator();

	int i=0;
	while(it.hasNext()) {
		String next = it.next().getStringValue();
		retArray[i] = next;
		i++;
	}

	return retArray;
}
 
Example 3
Source File: PrometheusMetricsConfig.java    From jmeter-prometheus-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object o) {
	if (o instanceof PrometheusMetricsConfig) {
		PrometheusMetricsConfig other = (PrometheusMetricsConfig) o;
		
		CollectionProperty thisConfig = this.getCollectorConfigs();
		CollectionProperty otherConfig = other.getCollectorConfigs();
		boolean sameSize = thisConfig.size() == otherConfig.size();
		
		for (int i = 0; i < thisConfig.size(); i++) {
			JMeterProperty left = thisConfig.get(i);
			JMeterProperty right = otherConfig.get(i);
			
			if(!left.equals(right)) {
				return false;
			}
		}
		
		return true && sameSize;
	}
	
	return false;
}
 
Example 4
Source File: JMeterPluginsUtils.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
public static void collectionPropertyToTableModelRows(CollectionProperty prop, PowerTableModel model, Class[] columnClasses) {
    model.clearData();
    for (int rowN = 0; rowN < prop.size(); rowN++) {
        ArrayList<StringProperty> rowStrings = (ArrayList<StringProperty>) prop.get(rowN).getObjectValue();
        ArrayList<Object> rowObject = new ArrayList<>(rowStrings.size());

        for (int i = 0; i < columnClasses.length && i < rowStrings.size(); i++) {
            rowObject.add(convertToClass(rowStrings.get(i), columnClasses[i]));
        }
        //for now work only if new fields are added at the end...
        //needed for retro compatibility if new fields added
        if (rowObject.size() < columnClasses.length) {
            for (int i = rowObject.size(); i < columnClasses.length; i++) {
                rowObject.add(new Object());
            }
        }
        model.addRow(rowObject.toArray());
    }
    model.fireTableDataChanged();
}
 
Example 5
Source File: CompositeGraphGui.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private void setConfig(CollectionProperty properties) {
    PropertyIterator iter = properties.iterator();

    CollectionProperty testplans = (CollectionProperty) iter.next();
    CollectionProperty rows = (CollectionProperty) iter.next();

    if (rows.size() > 0) {
        PropertyIterator iterTestplans = testplans.iterator();
        PropertyIterator iterRows = rows.iterator();

        while (iterTestplans.hasNext() && iterRows.hasNext()) {
            String testplan = iterTestplans.next().getStringValue();
            String row = iterRows.next().getStringValue();
            compositeRowsSelectorPanel.addItemsToComposite(testplan, row);
        }

    }
}
 
Example 6
Source File: DbMonCollector.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private void initiateConnectors() throws SQLException {
    JMeterProperty prop = getSamplerSettings();
    dbMonSamplers.clear();
    if (!(prop instanceof CollectionProperty)) {
        log.warn("Got unexpected property: " + prop);
        return;
    }
    CollectionProperty rows = (CollectionProperty) prop;

    for (int i = 0; i < rows.size(); i++) {
        ArrayList<Object> row = (ArrayList<Object>) rows.get(i).getObjectValue();
        String connectionPool = ((JMeterProperty) row.get(0)).getStringValue();
        String label = ((JMeterProperty) row.get(1)).getStringValue();
        boolean isDelta = ((JMeterProperty) row.get(2)).getBooleanValue();
        String sql = ((JMeterProperty) row.get(3)).getStringValue();
        initiateConnector(connectionPool, label, isDelta, sql);
    }
}
 
Example 7
Source File: FirefoxDriverConfig.java    From jmeter-plugins-webdriver with Apache License 2.0 5 votes vote down vote up
private void addExtensions(FirefoxProfile profile) {
    JMeterProperty property = getProperty(EXTENSIONS_TO_LOAD);
    if (property instanceof NullProperty) {
        return;
    }
    CollectionProperty rows = (CollectionProperty) property;
    for (int i = 0; i < rows.size(); i++) {
        ArrayList row = (ArrayList) rows.get(i).getObjectValue();
        String filename = ((JMeterProperty) row.get(0)).getStringValue();
        profile.addExtension(new File(filename));
    }
}
 
Example 8
Source File: WeightedSwitchController.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private CollectionProperty removeDisableSubGroups(CollectionProperty data) {
    CollectionProperty result = new CollectionProperty();
    for (int i = 0; i < data.size(); i++) {
        JMeterProperty property = data.get(i);
        if (property instanceof CollectionProperty &&
                ((CollectionProperty) property).size() == 3 &&
                "true".equals(((CollectionProperty) property).get(2).getStringValue())) {
            result.addProperty(property);
        }
    }
    return result;
}
 
Example 9
Source File: WeightedSwitchController.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private CollectionProperty setEnabledSubGroups(CollectionProperty data) {
    for (int i = 0; i < data.size(); i++) {
        JMeterProperty property = data.get(i);
        if (property instanceof CollectionProperty) {
            CollectionProperty prop = (CollectionProperty) property;
            if (prop.size() == 2) {
                prop.addItem("true");
            }
        }
    }

    setProperty(data);
    return data;
}
 
Example 10
Source File: WeightedSwitchController.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private double[] getWeights(CollectionProperty data) {
    long sum = 0;
    double[] weights = new double[data.size()];
    for (int n = 0; n < data.size(); n++) {
        CollectionProperty row = (CollectionProperty) data.get(n);
        weights[n] = Long.parseLong(row.get(1).getStringValue());
        sum += weights[n];
    }

    for (int n = 0; n < weights.length; n++) {
        weights[n] /= sum;
    }
    //log.info("Weights: " + Arrays.toString(weights));
    return weights;
}
 
Example 11
Source File: WeightedSwitchControllerGui.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private JMeterProperty getRowByName(String rowName, CollectionProperty oldData) {
    for (int i = 0; i <  oldData.size(); i++) {
        JMeterProperty row = oldData.get(i);
        if (row instanceof CollectionProperty && rowName.equals(((CollectionProperty) row).get(0).getStringValue())) {
            return row;
        }
    }
    return null;
}
 
Example 12
Source File: JMeterPluginsUtils.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public static void collectionPropertyToTableModelRows(CollectionProperty prop, PowerTableModel model) {
    model.clearData();
    for (int rowN = 0; rowN < prop.size(); rowN++) {
        ArrayList<String> rowObject = (ArrayList<String>) prop.get(rowN).getObjectValue();
        model.addRow(rowObject.toArray());
    }
    model.fireTableDataChanged();
}
 
Example 13
Source File: PerfMonCollector.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private void initiateConnectors() {
    oldValues.clear();
    JMeterProperty prop = getMetricSettings();
    connectors.clear();
    if (!(prop instanceof CollectionProperty)) {
        log.warn("Got unexpected property: " + prop);
        return;
    }
    CollectionProperty rows = (CollectionProperty) prop;

    for (int i = 0; i < rows.size(); i++) {
        Object val = rows.get(i).getObjectValue();
        if (val instanceof ArrayList) {
            ArrayList<JMeterProperty> row = (ArrayList<JMeterProperty>) val;
            String host = row.get(0).getStringValue();
            int port = row.get(1).getIntValue();
            String metric = row.get(2).getStringValue();
            String params = row.get(3).getStringValue();
            initiateConnector(host, port, i, metric, params);
        }
    }

    for (Object key : connectors.keySet()) {
        try {
            connectors.get(key).connect();
        } catch (IOException ex) {
            log.error("Error connecting to agent", ex);
            connectors.put(key, new UnavailableAgentConnector(ex));
        }
    }
}
 
Example 14
Source File: ServersListPanel.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public void loadFromTestElement(DistributedTestControl te) {
    CollectionProperty servers = te.getData();
    log.debug("Loading: " + servers.toString());
    clear();
    for (int n = 0; n < servers.size(); n++) {
        log.debug("Adding: " + servers.get(n).toString());
        add(servers.get(n).getStringValue());
    }
}
 
Example 15
Source File: DistributedTestControl.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public CollectionProperty getData() {
    CollectionProperty data = (CollectionProperty) getProperty(DATA_PROP);
    LinkedList<String> arr=new LinkedList<String>();

    for (int n = 0; n < data.size(); n++) {
        arr.add(data.get(n).getStringValue());
    }

    String val = StringUtils.join(arr, ",");
    log.debug("Setting hosts 1: " + val);
    JMeterUtils.setProperty(PROP_HOSTS, val);
    return data;
}