You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by sebb AT ASF <se...@apache.org> on 2013/08/14 15:19:09 UTC

Re: svn commit: r1513863 - in /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http: control/gui/HttpTestSampleGui.java sampler/HTTPAbstractImpl.java sampler/HTTPSamplerBase.java

On 14 August 2013 14:10,  <se...@apache.org> wrote:
> Author: sebb
> Date: Wed Aug 14 13:10:10 2013
> New Revision: 1513863
>
> URL: http://svn.apache.org/r1513863
> Log:
> Support device in addition to source IP address
> Use enum for source types; don't convert between index and name unnecessarily.
> Bugzilla Id: 54874

Hopefully the changed code is OK with you all?

It's unlikely we'll need another enum entry for a while, but if we do,
it should now be quite easy to add.

> Modified:
>     jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
>     jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
>     jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
>
> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java?rev=1513863&r1=1513862&r2=1513863&view=diff
> ==============================================================================
> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java (original)
> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java Wed Aug 14 13:10:10 2013
> @@ -72,7 +72,7 @@ public class HttpTestSampleGui extends A
>
>      private JTextField sourceIpAddr; // does not apply to Java implementation
>
> -    private JComboBox sourceIpType = new JComboBox(HTTPSamplerBase.getSourceTypeList().toArray());
> +    private JComboBox sourceIpType = new JComboBox(HTTPSamplerBase.getSourceTypeList());
>
>      private final boolean isAJP;
>
> @@ -136,7 +136,7 @@ public class HttpTestSampleGui extends A
>          samplerBase.setEmbeddedUrlRE(embeddedRE.getText());
>          if (!isAJP) {
>              samplerBase.setIpSource(sourceIpAddr.getText());
> -            samplerBase.setIpSourceType(HTTPSamplerBase.getSourceTypeList().indexOf(sourceIpType.getSelectedItem()));
> +            samplerBase.setIpSourceType(sourceIpType.getSelectedIndex());
>          }
>          this.configureTestElement(sampler);
>      }
> @@ -241,8 +241,7 @@ public class HttpTestSampleGui extends A
>
>          if (!isAJP) {
>              // Add a new field source ip address (for HC implementations only)
> -            sourceIpType.setSelectedItem(HTTPSamplerBase.getSourceTypeList().
> -                    get(HTTPSamplerBase.SOURCE_TYPE_IP_HOSTNAME));  //default: IP/Hostname
> +            sourceIpType.setSelectedIndex(HTTPSamplerBase.SourceType.HOSTNAME.ordinal()); //default: IP/Hostname
>              sourceIpType.setFont(FONT_VERY_SMALL);
>              sourceAddrPanel.add(sourceIpType);
>
> @@ -276,8 +275,7 @@ public class HttpTestSampleGui extends A
>          embeddedRE.setText(""); // $NON-NLS-1$
>          if (!isAJP) {
>              sourceIpAddr.setText(""); // $NON-NLS-1$
> -            sourceIpType.setSelectedItem(HTTPSamplerBase.getSourceTypeList()
> -                    .get(HTTPSamplerBase.SOURCE_TYPE_IP_HOSTNAME));
> +            sourceIpType.setSelectedIndex(HTTPSamplerBase.SourceType.HOSTNAME.ordinal()); //default: IP/Hostname
>          }
>      }
>
>
> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java?rev=1513863&r1=1513862&r2=1513863&view=diff
> ==============================================================================
> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java (original)
> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java Wed Aug 14 13:10:10 2013
> @@ -35,6 +35,7 @@ import org.apache.jmeter.protocol.http.c
>  import org.apache.jmeter.protocol.http.control.CacheManager;
>  import org.apache.jmeter.protocol.http.control.CookieManager;
>  import org.apache.jmeter.protocol.http.control.HeaderManager;
> +import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.SourceType;
>  import org.apache.jmeter.protocol.http.util.HTTPConstantsInterface;
>  import org.apache.jmeter.protocol.http.util.HTTPFileArg;
>  import org.apache.jmeter.samplers.Interruptible;
> @@ -142,13 +143,6 @@ public abstract class HTTPAbstractImpl i
>      }
>
>      /**
> -     * Invokes {@link HTTPSamplerBase#getIpSourceType()}
> -     */
> -    protected int getIpSourceType() {
> -        return testElement.getIpSourceType();
> -    }
> -
> -    /**
>       * Gets the IP source address (IP spoofing) if one has been provided.
>       *
>       * @return the IP source address to use (or null, if none provided or the device address could not be found)
> @@ -159,16 +153,18 @@ public abstract class HTTPAbstractImpl i
>          final String ipSource = getIpSource();
>          if (ipSource.trim().length() > 0) {
>              Class<? extends InetAddress> ipClass = null;
> -            switch (getIpSourceType()) {
> -            case HTTPSamplerBase.SOURCE_TYPE_DEVICE:
> +            final SourceType sourceType = HTTPSamplerBase.SourceType.values()[testElement.getIpSourceType()];
> +            switch (sourceType) {
> +            case DEVICE:
>                  ipClass = InetAddress.class;
>                  break;
> -            case HTTPSamplerBase.SOURCE_TYPE_DEVICE_IPV4:
> +            case DEVICE_IPV4:
>                  ipClass = Inet4Address.class;
>                  break;
> -            case HTTPSamplerBase.SOURCE_TYPE_DEVICE_IPV6:
> +            case DEVICE_IPV6:
>                  ipClass = Inet6Address.class;
>                  break;
> +            case HOSTNAME:
>              default:
>                  return InetAddress.getByName(ipSource);
>              }
>
> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=1513863&r1=1513862&r2=1513863&view=diff
> ==============================================================================
> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (original)
> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java Wed Aug 14 13:10:10 2013
> @@ -189,22 +189,28 @@ public abstract class HTTPSamplerBase ex
>
>      public static final int CONCURRENT_POOL_SIZE = 4; // Default concurrent pool size for download embedded resources
>
> -    public static final int SOURCE_TYPE_IP_HOSTNAME = 0;
> -
> -    public static final int SOURCE_TYPE_DEVICE = 1;
> -
> -    public static final int SOURCE_TYPE_DEVICE_IPV4 = 2;
> +    public static enum SourceType {
> +        HOSTNAME("web_testing_source_ip_hostname"), //$NON-NLS-1$
> +        DEVICE("web_testing_source_ip_device"), //$NON-NLS-1$
> +        DEVICE_IPV4("web_testing_source_ip_device_ipv4"), //$NON-NLS-1$
> +        DEVICE_IPV6("web_testing_source_ip_device_ipv6"); //$NON-NLS-1$
> +
> +        public final String propertyName;
> +        SourceType(String propertyName) {
> +            this.propertyName = propertyName;
> +        }
> +    }
>
> -    public static final int SOURCE_TYPE_DEVICE_IPV6 = 3;
> +    private static final int SOURCE_TYPE_DEFAULT = HTTPSamplerBase.SourceType.HOSTNAME.ordinal();
>
>      // Use for ComboBox Source Address Type. Preserve order (specially with localization)
> -    public static final ArrayList<String> getSourceTypeList() {
> -        ArrayList<String> sourceTypeList = new ArrayList<String>(4);
> -        sourceTypeList.add(JMeterUtils.getResString("web_testing_source_ip_hostname")); //$NON-NLS-1$
> -        sourceTypeList.add(JMeterUtils.getResString("web_testing_source_ip_device")); //$NON-NLS-1$
> -        sourceTypeList.add(JMeterUtils.getResString("web_testing_source_ip_device_ipv4")); //$NON-NLS-1$
> -        sourceTypeList.add(JMeterUtils.getResString("web_testing_source_ip_device_ipv6")); //$NON-NLS-1$
> -        return sourceTypeList;
> +    public static final String[] getSourceTypeList() {
> +        final SourceType[] types = SourceType.values();
> +        final String[] displayStrings = new String[types.length];
> +        for(int i = 0; i < types.length; i++) {
> +            displayStrings[i] = JMeterUtils.getResString(types[i].propertyName);
> +        }
> +        return displayStrings;
>      }
>
>      public static final String DEFAULT_METHOD = HTTPConstants.GET; // $NON-NLS-1$
> @@ -1737,7 +1743,7 @@ public abstract class HTTPSamplerBase ex
>       * set IP/address source type to use
>       */
>      public void setIpSourceType(int value) {
> -        setProperty(IP_SOURCE_TYPE, value, HTTPSamplerBase.SOURCE_TYPE_IP_HOSTNAME);
> +        setProperty(IP_SOURCE_TYPE, value, SOURCE_TYPE_DEFAULT);
>      }
>
>      /**
> @@ -1746,7 +1752,7 @@ public abstract class HTTPSamplerBase ex
>       * @return address source type
>       */
>      public int getIpSourceType() {
> -        return getPropertyAsInt(IP_SOURCE_TYPE, HTTPSamplerBase.SOURCE_TYPE_IP_HOSTNAME);
> +        return getPropertyAsInt(IP_SOURCE_TYPE, SOURCE_TYPE_DEFAULT);
>      }
>
>      /**
>
>

Re: svn commit: r1513863 - in /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http: control/gui/HttpTestSampleGui.java sampler/HTTPAbstractImpl.java sampler/HTTPSamplerBase.java

Posted by Milamber <mi...@apache.org>.
Le 14/08/2013 14:19, sebb AT ASF a ecrit :
> On 14 August 2013 14:10,  <se...@apache.org> wrote:
>> Author: sebb
>> Date: Wed Aug 14 13:10:10 2013
>> New Revision: 1513863
>>
>> URL: http://svn.apache.org/r1513863
>> Log:
>> Support device in addition to source IP address
>> Use enum for source types; don't convert between index and name unnecessarily.
>> Bugzilla Id: 54874
> Hopefully the changed code is OK with you all?

Thanks. After some tests (with success), all seems good for me.


>
> It's unlikely we'll need another enum entry for a while, but if we do,
> it should now be quite easy to add.
>
>> Modified:
>>      jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
>>      jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
>>      jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
>>
>> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
>> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java?rev=1513863&r1=1513862&r2=1513863&view=diff
>> ==============================================================================
>> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java (original)
>> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java Wed Aug 14 13:10:10 2013
>> @@ -72,7 +72,7 @@ public class HttpTestSampleGui extends A
>>
>>       private JTextField sourceIpAddr; // does not apply to Java implementation
>>
>> -    private JComboBox sourceIpType = new JComboBox(HTTPSamplerBase.getSourceTypeList().toArray());
>> +    private JComboBox sourceIpType = new JComboBox(HTTPSamplerBase.getSourceTypeList());
>>
>>       private final boolean isAJP;
>>
>> @@ -136,7 +136,7 @@ public class HttpTestSampleGui extends A
>>           samplerBase.setEmbeddedUrlRE(embeddedRE.getText());
>>           if (!isAJP) {
>>               samplerBase.setIpSource(sourceIpAddr.getText());
>> -            samplerBase.setIpSourceType(HTTPSamplerBase.getSourceTypeList().indexOf(sourceIpType.getSelectedItem()));
>> +            samplerBase.setIpSourceType(sourceIpType.getSelectedIndex());
>>           }
>>           this.configureTestElement(sampler);
>>       }
>> @@ -241,8 +241,7 @@ public class HttpTestSampleGui extends A
>>
>>           if (!isAJP) {
>>               // Add a new field source ip address (for HC implementations only)
>> -            sourceIpType.setSelectedItem(HTTPSamplerBase.getSourceTypeList().
>> -                    get(HTTPSamplerBase.SOURCE_TYPE_IP_HOSTNAME));  //default: IP/Hostname
>> +            sourceIpType.setSelectedIndex(HTTPSamplerBase.SourceType.HOSTNAME.ordinal()); //default: IP/Hostname
>>               sourceIpType.setFont(FONT_VERY_SMALL);
>>               sourceAddrPanel.add(sourceIpType);
>>
>> @@ -276,8 +275,7 @@ public class HttpTestSampleGui extends A
>>           embeddedRE.setText(""); // $NON-NLS-1$
>>           if (!isAJP) {
>>               sourceIpAddr.setText(""); // $NON-NLS-1$
>> -            sourceIpType.setSelectedItem(HTTPSamplerBase.getSourceTypeList()
>> -                    .get(HTTPSamplerBase.SOURCE_TYPE_IP_HOSTNAME));
>> +            sourceIpType.setSelectedIndex(HTTPSamplerBase.SourceType.HOSTNAME.ordinal()); //default: IP/Hostname
>>           }
>>       }
>>
>>
>> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
>> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java?rev=1513863&r1=1513862&r2=1513863&view=diff
>> ==============================================================================
>> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java (original)
>> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java Wed Aug 14 13:10:10 2013
>> @@ -35,6 +35,7 @@ import org.apache.jmeter.protocol.http.c
>>   import org.apache.jmeter.protocol.http.control.CacheManager;
>>   import org.apache.jmeter.protocol.http.control.CookieManager;
>>   import org.apache.jmeter.protocol.http.control.HeaderManager;
>> +import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.SourceType;
>>   import org.apache.jmeter.protocol.http.util.HTTPConstantsInterface;
>>   import org.apache.jmeter.protocol.http.util.HTTPFileArg;
>>   import org.apache.jmeter.samplers.Interruptible;
>> @@ -142,13 +143,6 @@ public abstract class HTTPAbstractImpl i
>>       }
>>
>>       /**
>> -     * Invokes {@link HTTPSamplerBase#getIpSourceType()}
>> -     */
>> -    protected int getIpSourceType() {
>> -        return testElement.getIpSourceType();
>> -    }
>> -
>> -    /**
>>        * Gets the IP source address (IP spoofing) if one has been provided.
>>        *
>>        * @return the IP source address to use (or null, if none provided or the device address could not be found)
>> @@ -159,16 +153,18 @@ public abstract class HTTPAbstractImpl i
>>           final String ipSource = getIpSource();
>>           if (ipSource.trim().length() > 0) {
>>               Class<? extends InetAddress> ipClass = null;
>> -            switch (getIpSourceType()) {
>> -            case HTTPSamplerBase.SOURCE_TYPE_DEVICE:
>> +            final SourceType sourceType = HTTPSamplerBase.SourceType.values()[testElement.getIpSourceType()];
>> +            switch (sourceType) {
>> +            case DEVICE:
>>                   ipClass = InetAddress.class;
>>                   break;
>> -            case HTTPSamplerBase.SOURCE_TYPE_DEVICE_IPV4:
>> +            case DEVICE_IPV4:
>>                   ipClass = Inet4Address.class;
>>                   break;
>> -            case HTTPSamplerBase.SOURCE_TYPE_DEVICE_IPV6:
>> +            case DEVICE_IPV6:
>>                   ipClass = Inet6Address.class;
>>                   break;
>> +            case HOSTNAME:
>>               default:
>>                   return InetAddress.getByName(ipSource);
>>               }
>>
>> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
>> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=1513863&r1=1513862&r2=1513863&view=diff
>> ==============================================================================
>> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (original)
>> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java Wed Aug 14 13:10:10 2013
>> @@ -189,22 +189,28 @@ public abstract class HTTPSamplerBase ex
>>
>>       public static final int CONCURRENT_POOL_SIZE = 4; // Default concurrent pool size for download embedded resources
>>
>> -    public static final int SOURCE_TYPE_IP_HOSTNAME = 0;
>> -
>> -    public static final int SOURCE_TYPE_DEVICE = 1;
>> -
>> -    public static final int SOURCE_TYPE_DEVICE_IPV4 = 2;
>> +    public static enum SourceType {
>> +        HOSTNAME("web_testing_source_ip_hostname"), //$NON-NLS-1$
>> +        DEVICE("web_testing_source_ip_device"), //$NON-NLS-1$
>> +        DEVICE_IPV4("web_testing_source_ip_device_ipv4"), //$NON-NLS-1$
>> +        DEVICE_IPV6("web_testing_source_ip_device_ipv6"); //$NON-NLS-1$
>> +
>> +        public final String propertyName;
>> +        SourceType(String propertyName) {
>> +            this.propertyName = propertyName;
>> +        }
>> +    }
>>
>> -    public static final int SOURCE_TYPE_DEVICE_IPV6 = 3;
>> +    private static final int SOURCE_TYPE_DEFAULT = HTTPSamplerBase.SourceType.HOSTNAME.ordinal();
>>
>>       // Use for ComboBox Source Address Type. Preserve order (specially with localization)
>> -    public static final ArrayList<String> getSourceTypeList() {
>> -        ArrayList<String> sourceTypeList = new ArrayList<String>(4);
>> -        sourceTypeList.add(JMeterUtils.getResString("web_testing_source_ip_hostname")); //$NON-NLS-1$
>> -        sourceTypeList.add(JMeterUtils.getResString("web_testing_source_ip_device")); //$NON-NLS-1$
>> -        sourceTypeList.add(JMeterUtils.getResString("web_testing_source_ip_device_ipv4")); //$NON-NLS-1$
>> -        sourceTypeList.add(JMeterUtils.getResString("web_testing_source_ip_device_ipv6")); //$NON-NLS-1$
>> -        return sourceTypeList;
>> +    public static final String[] getSourceTypeList() {
>> +        final SourceType[] types = SourceType.values();
>> +        final String[] displayStrings = new String[types.length];
>> +        for(int i = 0; i < types.length; i++) {
>> +            displayStrings[i] = JMeterUtils.getResString(types[i].propertyName);
>> +        }
>> +        return displayStrings;
>>       }
>>
>>       public static final String DEFAULT_METHOD = HTTPConstants.GET; // $NON-NLS-1$
>> @@ -1737,7 +1743,7 @@ public abstract class HTTPSamplerBase ex
>>        * set IP/address source type to use
>>        */
>>       public void setIpSourceType(int value) {
>> -        setProperty(IP_SOURCE_TYPE, value, HTTPSamplerBase.SOURCE_TYPE_IP_HOSTNAME);
>> +        setProperty(IP_SOURCE_TYPE, value, SOURCE_TYPE_DEFAULT);
>>       }
>>
>>       /**
>> @@ -1746,7 +1752,7 @@ public abstract class HTTPSamplerBase ex
>>        * @return address source type
>>        */
>>       public int getIpSourceType() {
>> -        return getPropertyAsInt(IP_SOURCE_TYPE, HTTPSamplerBase.SOURCE_TYPE_IP_HOSTNAME);
>> +        return getPropertyAsInt(IP_SOURCE_TYPE, SOURCE_TYPE_DEFAULT);
>>       }
>>
>>       /**
>>
>>