View | Details | Raw Unified | Return to bug 62426
Collapse All | Expand All

(-)a/src/core/org/apache/jmeter/report/processor/graph/impl/SyntheticResponseTimeDistributionGraphConsumer.java (-8 / +12 lines)
Lines 17-39 Link Here
17
 */
17
 */
18
package org.apache.jmeter.report.processor.graph.impl;
18
package org.apache.jmeter.report.processor.graph.impl;
19
19
20
import java.text.MessageFormat;
21
import java.util.Arrays;
20
import java.util.Arrays;
22
import java.util.HashMap;
21
import java.util.HashMap;
23
import java.util.Map;
22
import java.util.Map;
24
23
25
import org.apache.jmeter.report.core.Sample;
24
import org.apache.jmeter.report.core.Sample;
26
import org.apache.jmeter.report.processor.ListResultData;
27
import org.apache.jmeter.report.processor.MapResultData;
28
import org.apache.jmeter.report.processor.SumAggregatorFactory;
29
import org.apache.jmeter.report.processor.ValueResultData;
30
import org.apache.jmeter.report.processor.graph.AbstractGraphConsumer;
25
import org.apache.jmeter.report.processor.graph.AbstractGraphConsumer;
31
import org.apache.jmeter.report.processor.graph.AbstractSeriesSelector;
26
import org.apache.jmeter.report.processor.graph.AbstractSeriesSelector;
32
import org.apache.jmeter.report.processor.graph.CountValueSelector;
27
import org.apache.jmeter.report.processor.graph.CountValueSelector;
33
import org.apache.jmeter.report.processor.graph.GraphKeysSelector;
28
import org.apache.jmeter.report.processor.graph.GraphKeysSelector;
34
import org.apache.jmeter.report.processor.graph.GroupInfo;
29
import org.apache.jmeter.report.processor.graph.GroupInfo;
35
import org.apache.jmeter.report.processor.graph.SeriesData;
30
import org.apache.jmeter.report.processor.graph.SeriesData;
31
import org.apache.jmeter.report.processor.ListResultData;
32
import org.apache.jmeter.report.processor.MapResultData;
33
import org.apache.jmeter.report.processor.SumAggregatorFactory;
34
import org.apache.jmeter.report.processor.ValueResultData;
36
import org.apache.jmeter.util.JMeterUtils;
35
import org.apache.jmeter.util.JMeterUtils;
36
import org.apache.jorphan.text.PreCompiledFormatter;
37
import org.apache.jorphan.text.PreCompiledFormatterBuilder;
37
38
38
/**
39
/**
39
 * The class SyntheticResponseTimeDistributionGraphConsumer provides a graph to visualize
40
 * The class SyntheticResponseTimeDistributionGraphConsumer provides a graph to visualize
Lines 44-52 import org.apache.jmeter.util.JMeterUtils; Link Here
44
public class SyntheticResponseTimeDistributionGraphConsumer extends
45
public class SyntheticResponseTimeDistributionGraphConsumer extends
45
        AbstractGraphConsumer {
46
        AbstractGraphConsumer {
46
    private static final String FAILED_LABEL = JMeterUtils.getResString("response_time_distribution_failed_label");
47
    private static final String FAILED_LABEL = JMeterUtils.getResString("response_time_distribution_failed_label");
47
    private static final MessageFormat SATISFIED_LABEL = new MessageFormat(JMeterUtils.getResString("response_time_distribution_satisfied_label"));
48
    private static final PreCompiledFormatter SATISFIED_LABEL = PreCompiledFormatterBuilder.build(
48
    private static final MessageFormat TOLERATED_LABEL = new MessageFormat(JMeterUtils.getResString("response_time_distribution_tolerated_label"));
49
            JMeterUtils.getResString("response_time_distribution_satisfied_label"));
49
    private static final MessageFormat UNTOLERATED_LABEL = new MessageFormat(JMeterUtils.getResString("response_time_distribution_untolerated_label"));
50
    private static final PreCompiledFormatter TOLERATED_LABEL = PreCompiledFormatterBuilder.build(
51
            JMeterUtils.getResString("response_time_distribution_tolerated_label"));
52
    private static final PreCompiledFormatter UNTOLERATED_LABEL = PreCompiledFormatterBuilder.build(
53
            JMeterUtils.getResString("response_time_distribution_untolerated_label"));
50
    private static final String SERIE_COLOR_PROPERTY = "color";
54
    private static final String SERIE_COLOR_PROPERTY = "color";
51
    private static final String SATISFIED_COLOR = "#9ACD32";
55
    private static final String SATISFIED_COLOR = "#9ACD32";
52
    private static final String TOLERATED_COLOR = "yellow";
56
    private static final String TOLERATED_COLOR = "yellow";
(-)a/src/core/org/apache/jmeter/report/processor/graph/impl/TransactionsPerSecondGraphConsumer.java (-5 / +2 lines)
Lines 39-45 import org.apache.jmeter.report.processor.graph.TimeStampKeysSelector; Link Here
39
public class TransactionsPerSecondGraphConsumer extends
39
public class TransactionsPerSecondGraphConsumer extends
40
        AbstractOverTimeGraphConsumer {
40
        AbstractOverTimeGraphConsumer {
41
41
42
    private static final String STATUS_SERIES_FORMAT = "%s-%s";
43
    private static final String SUCCESS_SERIES_SUFFIX = "success";
42
    private static final String SUCCESS_SERIES_SUFFIX = "success";
44
    private static final String FAILURE_SERIES_SUFFIX = "failure";
43
    private static final String FAILURE_SERIES_SUFFIX = "failure";
45
44
Lines 72-81 public class TransactionsPerSecondGraphConsumer extends Link Here
72
71
73
                    @Override
72
                    @Override
74
                    public Iterable<String> select(Sample sample) {
73
                    public Iterable<String> select(Sample sample) {
75
                        String label = String.format(STATUS_SERIES_FORMAT,
74
                        String success = sample.getSuccess() ? SUCCESS_SERIES_SUFFIX : FAILURE_SERIES_SUFFIX;
76
                                sample.getName(),
75
                        String label = sample.getName() + "-" + success;
77
                                sample.getSuccess() ? SUCCESS_SERIES_SUFFIX
78
                                        : FAILURE_SERIES_SUFFIX);
79
                        return Arrays.asList(label);
76
                        return Arrays.asList(label);
80
                    }
77
                    }
81
                },
78
                },
(-)a/src/jorphan/org/apache/jorphan/text/BooleanFormatter.java (+46 lines)
Line 0 Link Here
1
/* 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed  under the  License is distributed on an "AS IS" BASIS,
13
 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
14
 * implied.
15
 * 
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
package org.apache.jorphan.text;
20
21
import java.util.function.Function;
22
23
public class BooleanFormatter implements SimpleFormatter {
24
25
  Function<String, String> transformer;
26
27
  public BooleanFormatter() {
28
    this(s -> s);
29
  }
30
31
  public BooleanFormatter(Function<String, String> transformer) {
32
    this.transformer = transformer;
33
  }
34
35
  @Override
36
  public void format(StringBuilder sb, Object arg) {
37
    String valueAsString = arg instanceof Boolean ? String.valueOf(arg) : "true";
38
    sb.append(transformer.apply(arg == null ? "false" : valueAsString));
39
  }
40
41
  @Override
42
  public int argsNeeded() {
43
    return 1;
44
  }
45
46
}
(-)a/src/jorphan/org/apache/jorphan/text/CombinedFormatter.java (+46 lines)
Line 0 Link Here
1
/* 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed  under the  License is distributed on an "AS IS" BASIS,
13
 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
14
 * implied.
15
 * 
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
package org.apache.jorphan.text;
20
21
import java.util.List;
22
23
public class CombinedFormatter implements PreCompiledFormatter {
24
25
  private List<SimpleFormatter> formatters;
26
27
  public CombinedFormatter(List<SimpleFormatter> formatters) {
28
    this.formatters = formatters;
29
  }
30
31
  @Override
32
  public String format(Object... args) {
33
    StringBuilder sb = new StringBuilder();
34
    int index = 0;
35
    for (SimpleFormatter f : formatters) {
36
      if (f.argsNeeded() > 0) {
37
        f.format(sb, args[index]);
38
      } else {
39
        f.format(sb, null);
40
      }
41
      index += f.argsNeeded();
42
    }
43
    return sb.toString();
44
  }
45
46
}
(-)a/src/jorphan/org/apache/jorphan/text/NoOpFormatter.java (+28 lines)
Line 0 Link Here
1
/* 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed  under the  License is distributed on an "AS IS" BASIS,
13
 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
14
 * implied.
15
 * 
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
package org.apache.jorphan.text;
20
21
public class NoOpFormatter implements PreCompiledFormatter {
22
23
  @Override
24
  public String format(Object... args) {
25
    return "";
26
  }
27
28
}
(-)a/src/jorphan/org/apache/jorphan/text/PreCompiledFormatter.java (+24 lines)
Line 0 Link Here
1
/* 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed  under the  License is distributed on an "AS IS" BASIS,
13
 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
14
 * implied.
15
 * 
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
package org.apache.jorphan.text;
20
21
public interface PreCompiledFormatter {
22
23
  public String format(Object... args);
24
}
(-)a/src/jorphan/org/apache/jorphan/text/PreCompiledFormatterBuilder.java (+79 lines)
Line 0 Link Here
1
/* 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed  under the  License is distributed on an "AS IS" BASIS,
13
 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
14
 * implied.
15
 * 
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
package org.apache.jorphan.text;
20
21
import java.util.ArrayList;
22
import java.util.HashMap;
23
import java.util.List;
24
import java.util.Map;
25
import java.util.regex.Matcher;
26
import java.util.regex.Pattern;
27
28
public class PreCompiledFormatterBuilder {
29
30
  private PreCompiledFormatterBuilder() {
31
    // hide publicly
32
  }
33
34
  private static Map<String, SimpleFormatter> availableFormatters;
35
  static {
36
    availableFormatters = new HashMap<>();
37
    availableFormatters.put("s", new StringFormatter());
38
    availableFormatters.put("S", new StringFormatter(String::toUpperCase));
39
    availableFormatters.put("b", new BooleanFormatter());
40
    availableFormatters.put("B", new BooleanFormatter(String::toUpperCase));
41
    availableFormatters.put("%", new StaticFormatter("%"));
42
    availableFormatters.put("n", new StaticFormatter("\n"));
43
  }
44
45
  private static Pattern formatPattern = Pattern.compile("%(\\w)");
46
47
  public static PreCompiledFormatter build(String format) {
48
    List<SimpleFormatter> f = new ArrayList<>();
49
    Matcher matcher = formatPattern.matcher(format);
50
    while (matcher.find()) {
51
      StringBuffer buf = new StringBuffer();
52
      matcher.appendReplacement(buf,
53
          Matcher.quoteReplacement(""));
54
      String prefix = buf.toString();
55
      if (prefix.length() > 0) {
56
        f.add(new StaticFormatter(prefix));
57
      }
58
      if (availableFormatters.containsKey(matcher.group(1))) {
59
        f.add(availableFormatters.get(matcher.group(1)));
60
      } else {
61
        throw new IllegalArgumentException("No formatter available for %" + matcher.group(1) + " in [" + format + "]");
62
      }
63
    }
64
    String tailString = extractTail(matcher);
65
    if (!tailString.isEmpty()) {
66
      f.add(new StaticFormatter(tailString));
67
    }
68
    if (f.isEmpty()) {
69
      return new NoOpFormatter();
70
    }
71
    return new CombinedFormatter(f);
72
  }
73
74
  private static String extractTail(Matcher matcher) {
75
    StringBuffer buf = new StringBuffer();
76
    matcher.appendTail(buf);
77
    return buf.toString();
78
  }
79
}
(-)a/src/jorphan/org/apache/jorphan/text/SimpleFormatter.java (+26 lines)
Line 0 Link Here
1
/* 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed  under the  License is distributed on an "AS IS" BASIS,
13
 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
14
 * implied.
15
 * 
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
package org.apache.jorphan.text;
20
21
public interface SimpleFormatter {
22
23
  public void format(StringBuilder sb, Object arg);
24
25
  public int argsNeeded();
26
}
(-)a/src/jorphan/org/apache/jorphan/text/StaticFormatter.java (+39 lines)
Line 0 Link Here
1
/* 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed  under the  License is distributed on an "AS IS" BASIS,
13
 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
14
 * implied.
15
 * 
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
package org.apache.jorphan.text;
20
21
public class StaticFormatter implements SimpleFormatter {
22
23
  private final String text;
24
25
  public StaticFormatter(final String text) {
26
    this.text = text;
27
  }
28
29
  @Override
30
  public void format(StringBuilder sb, Object arg) {
31
    sb.append(text);
32
  }
33
34
  @Override
35
  public int argsNeeded() {
36
    return 0;
37
  }
38
39
}
(-)a/src/jorphan/org/apache/jorphan/text/StringFormatter.java (+45 lines)
Line 0 Link Here
1
/* 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed  under the  License is distributed on an "AS IS" BASIS,
13
 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
14
 * implied.
15
 * 
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
package org.apache.jorphan.text;
20
21
import java.util.function.Function;
22
23
public class StringFormatter implements SimpleFormatter {
24
25
  Function<String, String> transform;
26
27
  public StringFormatter() {
28
    this(s -> s);
29
  }
30
31
  public StringFormatter(Function<String, String> transform) {
32
    this.transform = transform;
33
  }
34
35
  @Override
36
  public void format(StringBuilder sb, Object arg) {
37
    sb.append(transform.apply(arg == null ? "null" : arg.toString()));
38
  }
39
40
  @Override
41
  public int argsNeeded() {
42
    return 1;
43
  }
44
45
}
(-)a/test/src/org/apache/jorphan/text/PreCompiledFormatterSpec.groovy (-1 / +50 lines)
Line 0 Link Here
0
- 
1
/* 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed  under the  License is distributed on an "AS IS" BASIS,
13
 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
14
 * implied.
15
 * 
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
package org.apache.jorphan.io
20
21
import org.apache.jorphan.text.PreCompiledFormatter
22
import org.apache.jorphan.text.PreCompiledFormatterBuilder
23
import spock.lang.Specification
24
import spock.lang.Unroll
25
26
@Unroll
27
class PreCompiledFormatterSpec extends Specification {
28
29
    def "empty format gives an empty string"() {
30
        given:
31
            def sut = PreCompiledFormatterBuilder.build("")
32
        expect:
33
            sut.format() == ""
34
    }
35
36
    def "formats are the same as String.format"() {
37
        given:
38
            def sut = PreCompiledFormatterBuilder.build(format)
39
            Object[] args = allArgs.toArray(new Object[0])
40
        expect:
41
            sut.format(args) == String.format(format, args)
42
        where:
43
            format       | allArgs
44
            "Hello, %s!" | ['World']
45
            "%s-%s"      | [42, 23]
46
            "%s => %S"   | ['aBc', 'aBc']
47
            "%s => %b"   | [true, true]
48
    }
49
50
}

Return to bug 62426