Substring on jmeter variable in beanshell script error - beanshell

Using jmeter, I have a variable that is obtained by xpath expression. I have then used beanshell post processor to then get a substring (last 4 characters) which will be used in another request.
However, I keep getting an method invocation error for the script below.
import org.apache.jmeter.util.JMeterUtils;
import java.lang.*;
import java.io.*;
String numb = String.valueOf(vars.get("num"));
String last4 = num.Substring(num.length()-4, num.length());
log.info("num");
Any ideas as to what I'm doing wrong?

Added the correct libraries, which is as follows:
import org.apache.jmeter.util.JMeterUtils;
import org.apache.commons.lang3;
Change the start and end index values as well

Related

I created a updatesite.nsf from updatesite.ntf template and trying to import a feature

I created a updatesite.nsf from updatesite.ntf template and trying to import a feature and I get an error says "LS2J Error: Java constructor failed to execute in (#304)..." And a long message. Notes and Domino are 12.0.02 both 64 bit...Need help in this . Why am I getting this error ? Nothing in Activity logs either in the updatesite.nsf.
The developer tried to create a JAR and trying to import it the Feature into the updatesite,nsf database and it errors out as above. It should import as I am expecting.

Acessing a database using zeep

I am trying to programmatically retrieve information from a database(BRENDA) using Zeep.
The following is the code.
import zeep
import hashlib
wsdl = "https://www.brenda-enzymes.org/soap/brenda.wsdl"
password = hashlib.sha256("xx".encode('utf-8')).hexdigest()
parameters = "xxx," + password + ",ecNumber*{}#organism*{}#".format("2.7.1.2", "Homo sapiens")
client = zeep.Client(wsdl=wsdl)
print(client)
km_string = client.getKmValue(parameters)
However, I get the following error
AttributeError: 'Client' object has no attribute 'getKmValue'
Could someone help me with this?
The above code works fine while using SOAPpy library in python 2. However, I couldn't successfully install SOAPpy in python 3, therefore I tried Zeep.
The sample code that shows SOAP implementation is available here
We fixed the webservice. It should work, now. Please have a look at the SOAP documentation on our website.
not the resolution but some hints.
1) with zeep you need to put .service between client and the name of the method. the correct syntax is client.service.getKmValue(parameters) (take a look at documentation)
anyway for zeep, getKmValue doesn't exists (but it exists on the wsdl schema and SoapUi see it).
you can also try py-suds,
but for some reason i obtain a 403 calling the wsdl.
from suds.client import Client
import hashlib
client = Client("https://www.brenda-enzymes.org/soap/brenda.wsdl")

Why won't my application start with pandas_udf and PySpark+Flask?

When my Flask+PySpark application has a function with #udf or #pandas_udf annotation, it will not start. If I simply remove the annotation, it does start.
If I try to start my application with Flask, the first pass of lexical interpretation of the script is executed. For example, the debugger stops at import lines such as
from pyspark.sql.functions import pandas_udf, udf, PandasUDFType
. However no statement is executed at all, including the initial app = Flask(name) statement. (Could it be some kind of hidden exception? )
If I start my application without Flask, with the same exact function and with the same imports, it does work.
These are the imports:
from pyspark.sql import SQLContext
from pyspark.sql import SparkSession
from pyspark.sql.functions import pandas_udf, udf, PandasUDFType
import pandas as pd
This is the function:
#pandas_udf('string', PandasUDFType.SCALAR)
def pandas_not_null(s):
return s.fillna("_NO_NA_").replace('', '_NO_E_')
This is the statement that is not executed iff #pandas_udf is there:
app = Flask(__name__)
This is how IntelliJ starts Flask:
FLASK_APP = app
FLASK_ENV = development
FLASK_DEBUG = 1
In folder /Users/vivaomengao/projects/dive-platform/cat-intel/divecatintel
/Users/vivaomengao/anaconda/bin/python /Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py --module --multiproc --qt-support=auto --client 127.0.0.1 --port 56486 --file flask run
I'm running MacOS in my own computer.
I found the problem. The problem was that the #pandas_udf annotation required a Spark session at the time that the module is loaded (some kind of "first pass parsing" in Python). To solve the problem, I first called my code that creates a Spark session. Then I imported the module that has the function with the #pandas_udf annotation after. I imported it right inside the caller function and not at the header.
To troubleshoot, I set a breakpoint over the #pandas_udf function (in PyCharm) and stepped into the functions. With that I could inspect the local variables. One of the variables referred to something like "sc" or "_jvm". I knew from a past problem that that happened if the Spark session was not initialized.

difference between calling yahoo finance from 0.18 to 0.19

WARNING: NEWBIE
i had put off upgrading from pandas 0.18 to 0.19 until this morning. this code used to just give a deprication warning:
import pandas.io.data as web
x = web.DataReader('GE','yahoo',(2016, 10, 1), (2016, 11, 1))
now it throws an error and tells me: "The pandas.io.data module is moved to a separate package " builtins.ImportError: The pandas.io.data module is moved to a separate package (pandas-datareader). After installing the pandas-datareader package (https://github.com/pandas-dev/pandas-datareader), you can change the import from pandas.io import data, wb to from pandas_datareader import data, wb."
so, i rewrite my "from...import..." line to:
from pandas_datareader import data, wb
as expected, when i run the code, it throws an error:
builtins.NameError: name 'web' is not defined
when i try this code:
x = wb.pandas-datareader('GE','yahoo',(2016, 10, 1), (2016, 11, 1))
this error is thrown:
builtins.AttributeError: module 'pandas_datareader.wb' has no attribute 'pandas'
when i try this code:
x = wb.Datareader('GE','yahoo',(2016, 10, 1), (2016, 11, 1))
this error is thrown:
builtins.AttributeError: module 'pandas_datareader.wb' has no attribute 'DataReader'
can anyone please tell me how to call the datareader now?
thanks in advance
The old method of using the data reader in pandas should not be used as the first error you encountered. So never use import pandas.io.data as web
The correct way to access the modules of the new package pandas_datareader is what you wrote.
from pandas_datareader import data, wb
data and wb are modules (Python files) with many different functions that you can call to bring in different types of external data into your program. To see all the functions of each module use the dir command.
You can see all the publicly available objects with:
[attribute for attribute in dir(data) if attribute[0] != '_']
Which outputs
['DataReader',
'EurostatReader',
'FamaFrenchReader',
'FredReader',
'GoogleDailyReader',
'OECDReader',
'Options',
'YahooActionReader',
'YahooDailyReader',
'YahooOptions',
'YahooQuotesReader',
'get_components_yahoo',
'get_data_famafrench',
'get_data_fred',
'get_data_google',
'get_data_yahoo',
'get_data_yahoo_actions',
'get_quote_google',
'get_quote_yahoo',
'warnings']
So, these are all the items that you can use after the . in the data module.
If you run the same dir command with the wb module you will see that DataReader does not exist in that module. It exists in the above list in the data module.
Finally, make sure you have spelled your function correctly DataReader has upper case R. Use tab completion to avoid these mistakes or you will get the no attribute error. If the function you want does not get outputted with the dir command then you are using the wrong module.
DataReader also accepts strings as dates so the following will get you what you want.
data.DataReader('GE','yahoo', '2016-10-1', '2016-11-1')

How to get the name of JMX Jmeter filename in a variable

I want to use the name of the jmeter test script (.jmx) in a listener so as to generate the result file in a dynamic way. Can you please tell me what is the Jmeter variable for that purpose?
Used ${fileName} which didn't work
You can do it via Beanshell scripting like:
GUI mode
import org.apache.jmeter.gui.GuiPackage;
String scriptName = GuiPackage.getInstance().getTestPlanFile();
vars.put("scriptName", scriptName);
non-GUI mode
import org.apache.jmeter.services.FileServer;
String scriptName = FileServer.getFileServer().getScriptName();
vars.put("scriptName", scriptName);
Put the code snippet of your choice into any "Beanshell" test element (sampler, pre/post processor, or assertion), it will get .jmx test script name and store it into ${scriptName} variable.
To learn more about Beanshell scripting in JMeter check out How to use BeanShell: JMeter's favorite built-in component guide.
The variable that holds the test plan name is ${__TestPlanName}
Ref: http://jmeter.apache.org/usermanual/functions.html#__TestPlanName
Below would work irrespective of GUI / Non GUI mode:
import org.apache.jmeter.services.FileServer;
import java.io.File;
String testPlanFile = FileServer.getFileServer().getBaseDir() +
File.separator +
FileServer.getFileServer().getScriptName();
props.put("testPlanFile", testPlanFile);
Use this as ${__P(testPlanFile)} - Adding it as var would not work across all threads. From http://jmeter.apache.org/usermanual/functions.html -
Properties are not the same as variables. Variables are local to a
thread; properties are common to all threads, and need to be
referenced using the __P or __property function.