You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Jonathan Carlson <ja...@katun.com> on 2002/12/19 18:14:03 UTC

Re: Assertion Results bug? -- here's the fix 2

Here are all the changes again, but with thread protection added for Perl5Compiler and pre-compilation of all regex patterns.  I included the full methods since it seemed easier to do and because I added javadoc where there was none.  Any news on getting the nightly builds going again?

1) The compiler and matcher field definitions replace the existing ones.  (I don't remember what the original access level was, but I think they were protected.
2) The default constructor is a replacement.
3) The #getTestPatterns() method is new.
4) The #evaluateResponse method is a replacement.


    protected transient static ThreadLocal compiler =
        new ThreadLocal()
        {
            protected Object initialValue()
            {
                return new Perl5Compiler();
            }
        };

    protected transient static ThreadLocal matcher =
        new ThreadLocal()
        {
            protected Object initialValue()
            {
                return new Perl5Matcher();
            }
        };


    /************************************************************
     *  Constructs a ResponseAssertion instance.
     ***********************************************************/
    public ResponseAssertion()
    {
        setProperty(TEST_STRINGS,new ArrayList());

        // This ThreadLocal inner class assumes that all test strings will be
        // set before it is accessed the first time.  It should be a safe
        // assumption since it is only accessed from the #evaluateResponse
        // method.  If a test string cannot be compiled, this will add the
        // MalformedPatternException instead of the compiled pattern.
        ThreadLocal testPatterns =
            new ThreadLocal()
            {
                protected Object initialValue()
                {
                    List compiledPatternList = new ArrayList();
                    Iterator iterator = getTestStrings().iterator();
                    Perl5Compiler localCompiler = (Perl5Compiler) compiler.get();
                    while (iterator.hasNext())
                    {
                        String stringPattern = (String)iterator.next();
                        try
                        {
                            compiledPatternList.add(localCompiler.compile(stringPattern));
                        }
                        catch (MalformedPatternException e)
                        {
                            compiledPatternList.add(e);
                        }
                    }
                    return compiledPatternList;
                }
            };
        setProperty(TEST_PATTERNS, testPatterns);
    }

    /**
     * Returns a list of compiled regex patterns.  If a test string is not
     * compilable into a pattern, then a MalformedPatternException will be in
     * the list in place of the compiled pattern.
     * @return a list of compiled regex patterns and MalformedPatternExceptions
     */
    private List getTestPatterns()
    {
        ThreadLocal testPatterns = (ThreadLocal) getProperty(TEST_PATTERNS);
        List patternList = (List) testPatterns.get();
        return patternList;
    }

    /**
     * Make sure the response satisfied the specified assertion requirements.
     * @param response an instance of SampleResult
     * @return an instance of AssertionResult
     */
    private AssertionResult evaluateResponse(SampleResult response)
    {
        boolean pass = true;
        boolean not = (NOT & getTestType()) > 0;
        AssertionResult result = new AssertionResult();
        try
        {
            String responseString = new String(response.getResponseData());
            // Get the matcher for this thread
            Perl5Matcher localMatcher = (Perl5Matcher) this.matcher.get();
            Iterator iter = getTestPatterns().iterator();
            while (iter.hasNext())
            {
                Object element = iter.next();
                // I know this is strange looking but ThreadLocal#initialValue()
                // won't let you throw an exception
                if (element instanceof MalformedPatternException)
                {
                    throw (MalformedPatternException) element;
                }
                Pattern pattern = (Pattern) element;
                boolean found;
                if ((CONTAINS & getTestType()) > 0)
                {
                    found = localMatcher.contains(responseString, pattern);
                }
                else
                {
                    found = localMatcher.matches(responseString, pattern);
                }
                pass = not ? !found : found;

                if (!pass)
                {
                    result.setFailure(true);
                    result.setFailureMessage(
                            "Test Failed, expected " + notMessage + failMessage + pattern);
                    break;
                }
            }
            if(pass)
            {
                result.setFailure(false);
            }
            result.setError(false);
        }
        catch(MalformedPatternException e)
        {
            result.setError(true);
            result.setFailure(false);
            result.setFailureMessage("Bad test configuration"+e);
        }
        return result;
    }


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Assertion Results bug? -- here's the fix 2

Posted by Scott Eade <se...@backstagetech.com.au>.
Jonathan,

1. The compiler and matcher definitions were private.

2. I think you forgot to include:

    Public final static String TEST_PATTERNS = "Assertion.test_patterns";

I'll post the patch to bugzilla shortly.

Cheers,

Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au
.Mac Chat/AIM: seade at mac dot com


On 20/12/2002 4:14 AM, "Jonathan Carlson" <ja...@katun.com> wrote:

> Here are all the changes again, but with thread protection added for
> Perl5Compiler and pre-compilation of all regex patterns.  I included the full
> methods since it seemed easier to do and because I added javadoc where there
> was none.  Any news on getting the nightly builds going again?
> 
> 1) The compiler and matcher field definitions replace the existing ones.  (I
> don't remember what the original access level was, but I think they were
> protected.
> 2) The default constructor is a replacement.
> 3) The #getTestPatterns() method is new.
> 4) The #evaluateResponse method is a replacement.
> 
> 
>   protected transient static ThreadLocal compiler =
>       new ThreadLocal()
>       {
>           protected Object initialValue()
>           {
>               return new Perl5Compiler();
>           }
>       };
> 
>   protected transient static ThreadLocal matcher =
>       new ThreadLocal()
>       {
>           protected Object initialValue()
>           {
>               return new Perl5Matcher();
>           }
>       };
> 
> 
>   /************************************************************
>    *  Constructs a ResponseAssertion instance.
>    ***********************************************************/
>   public ResponseAssertion()
>   {
>       setProperty(TEST_STRINGS,new ArrayList());
> 
>       // This ThreadLocal inner class assumes that all test strings will be
>       // set before it is accessed the first time.  It should be a safe
>       // assumption since it is only accessed from the #evaluateResponse
>       // method.  If a test string cannot be compiled, this will add the
>       // MalformedPatternException instead of the compiled pattern.
>       ThreadLocal testPatterns =
>           new ThreadLocal()
>           {
>               protected Object initialValue()
>               {
>                   List compiledPatternList = new ArrayList();
>                   Iterator iterator = getTestStrings().iterator();
>                   Perl5Compiler localCompiler = (Perl5Compiler)
> compiler.get();
>                   while (iterator.hasNext())
>                   {
>                       String stringPattern = (String)iterator.next();
>                       try
>                       {
>                  
> compiledPatternList.add(localCompiler.compile(stringPattern));
>                       }
>                       catch (MalformedPatternException e)
>                       {
>                           compiledPatternList.add(e);
>                       }
>                   }
>                   return compiledPatternList;
>               }
>           };
>       setProperty(TEST_PATTERNS, testPatterns);
>   }
> 
>   /**
>    * Returns a list of compiled regex patterns.  If a test string is not
>    * compilable into a pattern, then a MalformedPatternException will be in
>    * the list in place of the compiled pattern.
>    * @return a list of compiled regex patterns and MalformedPatternExceptions
>    */
>   private List getTestPatterns()
>   {
>       ThreadLocal testPatterns = (ThreadLocal) getProperty(TEST_PATTERNS);
>       List patternList = (List) testPatterns.get();
>       return patternList;
>   }
> 
>   /**
>    * Make sure the response satisfied the specified assertion requirements.
>    * @param response an instance of SampleResult
>    * @return an instance of AssertionResult
>    */
>   private AssertionResult evaluateResponse(SampleResult response)
>   {
>       boolean pass = true;
>       boolean not = (NOT & getTestType()) > 0;
>       AssertionResult result = new AssertionResult();
>       try
>       {
>           String responseString = new String(response.getResponseData());
>           // Get the matcher for this thread
>           Perl5Matcher localMatcher = (Perl5Matcher) this.matcher.get();
>           Iterator iter = getTestPatterns().iterator();
>           while (iter.hasNext())
>           {
>               Object element = iter.next();
>               // I know this is strange looking but ThreadLocal#initialValue()
>               // won't let you throw an exception
>               if (element instanceof MalformedPatternException)
>               {
>                   throw (MalformedPatternException) element;
>               }
>               Pattern pattern = (Pattern) element;
>               boolean found;
>               if ((CONTAINS & getTestType()) > 0)
>               {
>                   found = localMatcher.contains(responseString, pattern);
>               }
>               else
>               {
>                   found = localMatcher.matches(responseString, pattern);
>               }
>               pass = not ? !found : found;
> 
>               if (!pass)
>               {
>                   result.setFailure(true);
>                   result.setFailureMessage(
>                           "Test Failed, expected " + notMessage + failMessage
> + pattern);
>                   break;
>               }
>           }
>           if(pass)
>           {
>               result.setFailure(false);
>           }
>           result.setError(false);
>       }
>       catch(MalformedPatternException e)
>       {
>           result.setError(true);
>           result.setFailure(false);
>           result.setFailureMessage("Bad test configuration"+e);
>       }
>       return result;
>   }


Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au
seade@backstagetech.com.au
Mobile: 0403 278 908
.Mac Chat/AIM: seade at mac dot com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


HTTP Proxy Server with SSL?

Posted by Ayman Mobarak <ay...@dhapdigital.com>.
I am not having success with the proxy server for an https site.  The
mail archives indicate that this functionality is not available. Is that
still the case for the latest version?  I am using v-1.8. If not, it
seems that my alternatives are:

* persuade developers to provide a plaintext system for test development
  (not a small request as the test target is a complex enterprise
application)
* generate test scripts manually without using the proxy server

Are there any better options?
-Ayman Mobarak


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>