Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug59945_DefaultGroovyEngineToJSR223ElementsV2 #223

Closed

Conversation

ra0077
Copy link
Contributor

@ra0077 ra0077 commented Aug 4, 2016

Hi,

If the script language has not been chosen on the GUI, I propose to add
a WARN message into the log to inform that the script will be
interpreted as a groovy script

It's avoid message like "ERROR -
jmeter.protocol.java.sampler.JSR223Sampler: Problem in JSR223 script
Echantillon JSR223, message:javax.script.ScriptException: Cannot find
engine named: '', ensure you set language field in JSR223 Test
Element:Echantillon JSR223" and allow to execute the script

Antonio

Hi,

If the script language has not been chosen on the GUI, I propose to add
a WARN message into the log to inform that the script will be
interpreted as a groovy script

It's avoid message like "ERROR -
jmeter.protocol.java.sampler.JSR223Sampler: Problem in JSR223 script
Echantillon JSR223, message:javax.script.ScriptException: Cannot find
engine named: '', ensure you set language field in JSR223 Test
Element:Echantillon JSR223" and allow to execute the  script

Antonio
@@ -36,6 +36,8 @@
private String script = ""; // script (if file not provided)

protected String scriptLanguage = ""; // BSF/JSR223 language to use

protected String defaultScriptLanguage = "groovy"; // if no language is chosen in GUI
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be final static?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@vlsi
Copy link
Collaborator

vlsi commented Aug 4, 2016

Do you think a test should be added to cover the change?
An entry in changes.xml is missing as well.

if (lang.isEmpty()) {
lang = defaultScriptLanguage;
log.warn("Script language has not been chosen on the UI, the script will be interpreted as a groovy script");
}

ScriptEngine scriptEngine = getInstance().getEngineByName(lang);
if (scriptEngine == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scriptEngine will be never null if groovy become the default language. This (if and exception below) must be changes.
Perhaps put here the test (if lang is undefine then log warn "interpret as groovy script")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Milamber,

I have keep the exception because I am not sure that getInstance().getEngineByName("groovy") will always return something.
For example if the groovy jar are missing

Antonio

@milamberspace
Copy link
Contributor

The manual must be updated too for indicate this new behavior (if no language, then groovy script)

I have modified the patch to:
   have better/useful warning message
   transform defaultScriptLanguage string in final static string

Antonio
@ra0077
Copy link
Contributor Author

ra0077 commented Aug 5, 2016

Hi,

New patch with better warn message and changes.xml

I am waiting your advices for a better patch

Antonio

@milamberspace
Copy link
Contributor

Seems better. Fon't forget to update the docs (manual)

@vlsi
Copy link
Collaborator

vlsi commented Aug 5, 2016

-1 for logging a warning on each sampler execution.
Typical user would never open log files, and get bad performance results (or even log overflow of some kind)

@ra0077
Copy link
Contributor Author

ra0077 commented Aug 5, 2016

Hi vladimir,

Can you give me more details to avoid logging a warning on each sampler execution?
I don't know how to implement

Thanks
Antonio

@@ -36,6 +36,8 @@
private String script = ""; // script (if file not provided)

protected String scriptLanguage = ""; // BSF/JSR223 language to use

protected final static String defaultScriptLanguage = "groovy"; // if no language is chosen in GUI
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final static should be written in capital letters

@vlsi
Copy link
Collaborator

vlsi commented Aug 5, 2016

I don't know how to implement

For instance, a boolean flag that is cleared after the fist warning is printed.

@ubikloadpack
Copy link
Contributor

ubikloadpack commented Aug 5, 2016

Hello,
Thanks for PR.
My notes:

  • defaultScriptLanguage should be uppercase being a constant.
  • use StringUtils.isEmpty to avoid spaces breaking the control
  • Maybe a solution to @vlsi note is to set the script , something like this (note that I don't think it will set the lang on the final test but only avoid repeating the log message for the same element each time it runs

`if (StringUtils.isEmpty(lang)) {

        lang = DEFAULT_SCRIPT_LANGUAGE;

        setScript(lang);

        log.warn("Script language has not been chosen on the UI: "+getName()+", the script will be interpreted as a groovy script");

    }

`

Regards
@ubikloadpack

@ra0077
Copy link
Contributor Author

ra0077 commented Aug 5, 2016

Hi ubikloadpack,

Your solution seem good

I will implement it

@ra0077
Copy link
Contributor Author

ra0077 commented Aug 5, 2016

It's don't work :-(

protected ScriptEngine getScriptEngine() throws ScriptException {
    String lang = getScriptLanguage();

    if (StringUtils.isEmpty(lang)) {
        lang = DEFAULT_SCRIPT_LANGUAGE;
        setScriptLanguage(lang);
        log.warn("Script language has not been chosen on the UI: "+getName()+", the script will be interpreted as a groovy script");
    }

    ScriptEngine scriptEngine = getInstance().getEngineByName(lang);
    if (scriptEngine == null) {
        throw new ScriptException("Cannot find engine named: '"+lang+"', ensure you set language field in JSR223 Test Element: "+getName());
    }

    return scriptEngine;
}

@pmouawad
Copy link
Contributor

pmouawad commented Aug 5, 2016

Hello,
In my opinion, you should commit it and we can improve it with further commits.
I agree with @vlsi on the performance involvement of warn logging , but we'll find a solution if you don't want to PR again.

Thanks

@ra0077
Copy link
Contributor Author

ra0077 commented Aug 11, 2016

Hi all,

I have check in JMeter source code if this "problem" (take a default solution if nothing is setted in GUI) and I have find "CSS/JQuery Extractor" element

If you check the documentation (https://jmeter.apache.org/usermanual/component_reference.html#CSS/JQuery_Extractor), we can read "If selector is set to empty, default implementation(JSoup) will be used"

I have check the source code and make a test and when selector is set to empty, there is no log written.

I propose to make the same thing to this PR (remove log to avoid performance problem + have a clear documentation)

Are you ok?

Antonio

@vlsi
Copy link
Collaborator

vlsi commented Aug 11, 2016

remove log to avoid performance problem

+1

Technically speaking, I would prefer to set the language to "groovy" if it was not specified.

That would make the UI clear (user will see what the language is), and that would setup proper syntax highlight mode (much easier to program).
If the conversion is done at load time, then additional log warning is just fine as well.

@milamberspace
Copy link
Contributor

OK for me too.

@ra0077
Copy link
Contributor Author

ra0077 commented Sep 23, 2016

PR commited

@ra0077 ra0077 closed this Sep 23, 2016
asfgit pushed a commit that referenced this pull request Sep 26, 2016
git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1762082 13f79535-47bb-0310-9956-ffa450edef68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants