Search in sources :

Example 1 with ConvertException

use of org.apache.jmeter.report.core.ConvertException in project jmeter by apache.

the class CustomGraphConsumer method createGroupInfos.

/*
     * (non-Javadoc)
     *
     * @see org.apache.jmeter.report.csv.processor.impl.AbstractGraphConsumer#
     * createGroupInfos()
     */
@Override
protected Map<String, GroupInfo> createGroupInfos() {
    AbstractSeriesSelector seriesSelector = new AbstractSeriesSelector() {

        @Override
        public Iterable<String> select(Sample sample) {
            return Collections.singletonList(sampleVariableName);
        }
    };
    GraphValueSelector graphValueSelector = (series, sample) -> {
        String value;
        if (isNativeSampleVariableName) {
            value = sample.getData(sampleVariableName);
        } else {
            value = sample.getData(CSVSaveService.VARIABLE_NAME_QUOTE_CHAR + sampleVariableName + CSVSaveService.VARIABLE_NAME_QUOTE_CHAR);
        }
        if (StringUtils.isEmpty(value) || "null".equals(value)) {
            return null;
        }
        try {
            return Converters.convert(Double.class, value);
        } catch (ConvertException e) {
            throw new IllegalArgumentException("Double converter failed", e);
        }
    };
    return Collections.singletonMap(AbstractGraphConsumer.DEFAULT_GROUP, new GroupInfo(new MeanAggregatorFactory(), seriesSelector, // We ignore Transaction Controller results
    graphValueSelector, false, false));
}
Also used : Arrays(java.util.Arrays) Sample(org.apache.jmeter.report.core.Sample) AbstractGraphConsumer(org.apache.jmeter.report.processor.graph.AbstractGraphConsumer) Set(java.util.Set) CSVSaveService(org.apache.jmeter.save.CSVSaveService) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) SampleConsumer(org.apache.jmeter.report.processor.SampleConsumer) GraphValueSelector(org.apache.jmeter.report.processor.graph.GraphValueSelector) MapResultData(org.apache.jmeter.report.processor.MapResultData) Map(java.util.Map) MeanAggregatorFactory(org.apache.jmeter.report.processor.MeanAggregatorFactory) TimeStampKeysSelector(org.apache.jmeter.report.processor.graph.TimeStampKeysSelector) ConvertException(org.apache.jmeter.report.core.ConvertException) Converters(org.apache.jmeter.report.core.Converters) AbstractSeriesSelector(org.apache.jmeter.report.processor.graph.AbstractSeriesSelector) ValueResultData(org.apache.jmeter.report.processor.ValueResultData) GroupInfo(org.apache.jmeter.report.processor.graph.GroupInfo) AbstractOverTimeGraphConsumer(org.apache.jmeter.report.processor.graph.AbstractOverTimeGraphConsumer) Collections(java.util.Collections) ConvertException(org.apache.jmeter.report.core.ConvertException) AbstractSeriesSelector(org.apache.jmeter.report.processor.graph.AbstractSeriesSelector) GroupInfo(org.apache.jmeter.report.processor.graph.GroupInfo) Sample(org.apache.jmeter.report.core.Sample) GraphValueSelector(org.apache.jmeter.report.processor.graph.GraphValueSelector) MeanAggregatorFactory(org.apache.jmeter.report.processor.MeanAggregatorFactory)

Example 2 with ConvertException

use of org.apache.jmeter.report.core.ConvertException in project jmeter by apache.

the class ReportGenerator method setProperty.

/**
 * Try to set a property on an object by reflection.
 *
 * @param className     name of the objects class
 * @param obj           the object on which the property should be set
 * @param methods       methods of the object to be searched for the property setter
 * @param propertyName  name of the property to be set
 * @param propertyValue value to be set
 * @param setterName    name of the property setter that should be used to set the
 *                      property
 * @throws IllegalAccessException if reflection throws an IllegalAccessException
 * @throws GenerationException    if conversion of the property value fails or reflection
 *                                throws an InvocationTargetException
 */
private void setProperty(String className, Object obj, Method[] methods, String propertyName, String propertyValue, String setterName) throws IllegalAccessException, GenerationException {
    try {
        int i = 0;
        while (i < methods.length) {
            Method method = methods[i];
            if (method.getName().equals(setterName)) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length == 1) {
                    Class<?> parameterType = parameterTypes[0];
                    if (parameterType.isAssignableFrom(String.class)) {
                        method.invoke(obj, propertyValue);
                    } else {
                        StringConverter<?> converter = Converters.getConverter(parameterType);
                        if (converter == null) {
                            throw new GenerationException(String.format("Not supported conversion to \"%s\"", parameterType.getName()));
                        }
                        method.invoke(obj, converter.convert(propertyValue));
                    }
                    return;
                }
            }
            i++;
        }
        log.warn("'{}' is not a valid property for class '{}', skip it", propertyName, className);
    } catch (InvocationTargetException | ConvertException ex) {
        String message = String.format("Cannot assign \"%s\" to property \"%s\" (mapped as \"%s\"), skip it", propertyValue, propertyName, setterName);
        log.error(message, ex);
        throw new GenerationException(message, ex);
    }
}
Also used : ConvertException(org.apache.jmeter.report.core.ConvertException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ConvertException (org.apache.jmeter.report.core.ConvertException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Converters (org.apache.jmeter.report.core.Converters)1 Sample (org.apache.jmeter.report.core.Sample)1 MapResultData (org.apache.jmeter.report.processor.MapResultData)1 MeanAggregatorFactory (org.apache.jmeter.report.processor.MeanAggregatorFactory)1 SampleConsumer (org.apache.jmeter.report.processor.SampleConsumer)1 ValueResultData (org.apache.jmeter.report.processor.ValueResultData)1 AbstractGraphConsumer (org.apache.jmeter.report.processor.graph.AbstractGraphConsumer)1 AbstractOverTimeGraphConsumer (org.apache.jmeter.report.processor.graph.AbstractOverTimeGraphConsumer)1 AbstractSeriesSelector (org.apache.jmeter.report.processor.graph.AbstractSeriesSelector)1 GraphValueSelector (org.apache.jmeter.report.processor.graph.GraphValueSelector)1 GroupInfo (org.apache.jmeter.report.processor.graph.GroupInfo)1