If controller jexl3 is not evaluating the condition correctly - if-statement

My script uses a while loop and an if controller as a child for evaluating a condition using jexl3 and determining if a particular request should or not run; this is how my test plans look like:
While Controller Details
The "While Controller2" value should equal 5 to set the while controller condition to true and exit the test
If Controller Details
The "If Controller" evaluates if a determinate if a request should run or not, depending on the current "${__V(MultitrackerId_${counter})}_skip" value; note that _skip is append to the variable.
Request Details
There are the requests that run depending on the if condition evaluation; as you can see, the "${__V(MultitrackerId_${counter})}" is sent, and the path field and "counter" variable is also appended at the end.
Counter Details
And the counter is incrementing 1++ with its maximum value as "${MultitrackerId_matchNr}"
Debug Sampler with variables values
This is a Debug Sampler to show you the values of the variables before the thread enters, for example, the main "While Controller2". The "MultitrackerId" has 4 possible values, and the counter starts in "1"
according to the test plan requirements, the MultitrackerId values are sent sequentially because of the counter, and each value should stop being sent when the response body contains "SUCCESSFUL", and the same thread should continue sending the request as many times as required to all the remaining "MultitrackerId values" contains "SUCCESSFUL" in their responses.
NOTE: depending on the length of the received data, each "MultitrackerId" value could require "n" iterations to get the "SUCCESSFUL" string present on its response
For handling the previous requirements, I am using a JSR223 Postprocessor as a child of the main above-shown request. A "matches" variable is defined starting from 0. It's incremented if the previous response contains "SUCCESSFUL", in addition, for avoiding to repeat a request that has already received the "SUCCESSFUL" string in its response, I am defining a new variable called "variable", using the current MultitrackerId value with a "_skip" value appended and finally, the same variable is set to true.
def matches = vars.getObject('matches') ?: 0
if (prev.getResponseDataAsString().contains("SUCCESSFUL")) {
vars.putObject('matches', matches + 1)
def variable = '${__V(MultitrackerId_${counter})}'
vars.put(variable + '_skip', "true")
}
When I run the test, the request is evaluated in the "if" condition, and if the "SUCCESSFUL" is contained in the response, matches increase +1 to update the main "While" condition and send the next MultitrackerId value.
I am expecting each MultitracketId already evaluated in the JSR223( SUCCESSFUL and marked with _skip) to be skipped in the "If Controller" condition; this is an example of the final "Debug Sampler"
Final Debug Sampler
Despite the matches variable being equal to "5" and the test stopping because of the "While Controller" condition, the requests evaluated in the JSR223 "if" as response with "SUCCESSFUL" and marked with "_skip" are being sent again, so the "matches" variable is reaching its expected value "5", others MultitrackersId values could be still pending to receive "SUCCESSFUL", so the test is finishing without being completed according with the requirements.
Let's remember the "If Controller" condition:
${__jexl3("${__V(MultitrackerId_${counter})}_skip" != "true",)}
When trying to debug the "If Controller" with the jexl3 condition, I am noticing that even if the MultitrackerId was evaluated in the JSR223 and set to "_skip", it's being evaluated once and once again
2023-01-06 21:44:57,423 DEBUG o.a.j.t.TestBeanHelper: Setting script=def matches = vars.getObject('matches') ?: 0
if (prev.getResponseDataAsString().contains("SUCCESSFUL")) {
vars.putObject('matches', matches + 1)
def variable = 's5KZoGfPawRt1RHkwechR'
vars.put(variable + '_skip', "true")
}
2023-01-06 21:44:57,435 DEBUG o.a.j.c.IfController: getCondition() : [true]
2023-01-06 21:44:57,436 DEBUG o.a.j.c.IfController: >> evaluate Condition - [true] results is [true]
I would really appreaciate any idea for solving this.

There are 2 problems in your script I can see:
In first While Controller you're using < operator to compare 2 string values
I believe it needs to be changed to something like ${__jexl3(${matches} < 5,)}
This bit: def variable = '${__V(MultitrackerId_${counter})}'
According to JSR223 Sampler documentation:
The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:
Use Script files instead of inlining them. This will make JMeter compile them if this feature is available on ScriptEngine and cache them.
Or Use Script Text and check Cache compiled script if available property.
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
I think you need to change it to def variable = vars.get('MultitrackerId_' + vars.get('counter'))
or just move function to Parameters section and refer it as Parameters
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

Related

Is it possible to register commands to a breakpoint from within an external file in GDB?

GDB allows registering a set of commands to a specific breakpoint via commands NUM syntax. I need to register the set of commands for a specific breakpoint via an external file, by using a syntax something like the following:
commands ./main.c:18
silent
print buffer[0]
cont
end
commands ./io.c:29
silent
printf "Hello world %i\n", myvar1
cont
end
The commands path/to/file:XX syntax is made up by me. Because the NUM in commands NUM syntax requires exactly the breakpoint's runtime ID number (assigned by GDB), I can not use a deterministic syntax for that purpose.
I'm currently registering breakpoints via a text file with such a content:
break ./main.c:18
break ./io.c:29
and then issuing source breakpoints.txt command inside GDB. It seems that there is no way to register commands at the same time while registering a breakpoint:
(gdb) help break
Set breakpoint at specified line or function.
break [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]
PROBE_MODIFIER shall be present if the command is to be placed in a
probe point. Accepted values are -probe' (for a generic, automatically guessed probe type), -probe-stap' (for a SystemTap probe) or
`-probe-dtrace' (for a DTrace probe).
LOCATION may be a line number, function name, or "*" and an address.
If a line number is specified, break at start of code for that line.
If a function is specified, break at start of code for that function.
If an address is specified, break at that exact address.
With no LOCATION, uses current execution address of the selected
stack frame. This is useful for breaking on return to a stack frame.
THREADNUM is the number from "info threads".
CONDITION is a boolean expression.
Multiple breakpoints at one place are permitted, and useful if their
conditions are different.
Question
Is there any easy way to set some predetermined commands for a predetermined breakpoint from within a file?
If not, is there any equivalent way to pass the (gdb) info breakpoints output to a file or a program while pipe is not available in GDB (version 5.3)? Currently I'm trying a workaround by using logging feature for that purpose:
set logging file /tmp/breakpoints
set logging on
info breakpoints
set logging off
Is there any easy way to set some predetermined commands for a predetermined breakpoint from within a file?
Yes: if you use commands without NUM, the commands will apply to the last breakpoint set. So you want something like:
break main.c:18
commands
silent
print buffer[0]
cont
end

Why would a PyDev breakpoint on a return statement only work part of the time?

I have some code that calculates the price of a stock option using Monte Carlo and returns a discounted price. The final few lines of the relevant method look like this:
if(payoffType == pt.LongCall or payoffType == pt.LongPut):
discountedPrice=discountedValue
elif(payoffType == pt.ShortCall or payoffType == pt.ShortPut):
discountedPrice=(-1.0)*discountedValue
else:
raise Exception
#endif
print "dv:", discountedValue, " px:", discountedPrice
return discountedPrice
At a higher level of the program, I create four pricers, which are passed to instances of a portfolio class that calls the price() method on the pricer it has received.
When I set the breakpoint on the if statement or the print statement, the breakpoints work as expected. When I set the breakpoint on the return statement, the breakpoint is interpreted correctly on the first pass through the pricing code, but then skipped on subsequent passes.
On occasion, if I have set a breakpoint somewhere in the flow of execution between the first pass through the pricing code and the second pass, the breakpoint will be picked up.
I obviously have a workaround, but I'm curious if anyone else has observed this behavior in the PyDev debugger, and if so, does anyone know the root cause?
The issues I know of are:
If you have a StackOverflowError anywhere in the code, Python will disable the tracing that the debugger uses.
I know there are some issues with asynchronous code which could make the debugger break.
A workaround is using a programmatic breakpoint (i.e.: pydevd.settrace -- the remote debugger session: http://www.pydev.org/manual_adv_remote_debugger.html has more details on it) -- it resets the tracing even if Python broke it in a stack overflow error and will always be hit to (the issue on asynchronous code is that the debugger tries to run with untraced threads, but sometimes it's not able to restore it on some conditions when dealing with asynchronous code).

Break outside a loop, return outside a function - iPython Notebook

I have an iPython notebook that has blocks of code of which I want to be able to have the opportunity to stop at points whilst it is executing.
The code downloads a query form an API and on the first return determines the maximum rows and whether it contains sampled data.
Depending if it has sampled data, and to what extent, I would like the option to stop the code prior to the while loop which will iteratively download the full dataset.
The 'break' code I have is as below:
print "Contains sampled data? " + str(metadata["containsSampledData"])
print "Break query? -> Y"
bi = raw_input()
if bi == "Y":
break
I have tried return and break, which both give errors (though they do stop the code). In addition, I have tired quit() however I am not wanting to reset the kernal and re-import modules/create variables.
Is there any way, outside of a loop and not within a function that you can stop the code, without quitting the instance?
I think you need to rethink and rewrite the logic of your program.
print "Contains sampled data? " + str(metadata["containsSampledData"])
while True:
# Check the condition with your API stuff here
# and exit or ask everytime if the condition is true as shown below
print "Break query? -> Y"
bi = raw_input()
if bi == "Y":
break
# Continue executing your code here.
The other option is to use sys.exit() as you already tried but it will exit the program.

How can i pick out value from consecutive value of event by using siddhi

for example, that is data:
1,1470732420000,0
2,1470732421000,0
3,1470732422000,0
4,1470732423000,86
5,1470732424000,87
6,1470732425000,88
7,1470732426000,84
8,1470732427000,0
9,1470732428000,0
10,1470732429000,0
11,1470732430000,89
12,1470732431000,89
13,1470732432000,87
14,1470732433000,89
15,1470732434000,85
16,1470732435000,89
17,1470732436000,89
18,1470732437000,87
19,1470732438000,86
20,1470732439000,88
21,1470732440000,0
22,1470732441000,0
23,1470732442000,0
24,1470732443000,87
25,1470732444000,85
26,1470732445000,86
27,1470732446000,0
28,1470732447000,0
29,1470732448000,0
30,1470732449000,0
column one is id,column two is timestamp,column three is value,1 sec interval between the timestamp.
i want monitoring the value of event,if i found out value>=85(e.g. id=4), i will starting counting,if the next two consecutive value>=85(e.g. id=5/id=6),then i will put the third value of event to OutputStream.(e.g. id=6,value=88,timestamp=1470732425000)
at the same time i clear the counting and wait value lower than 85(e.g. id=7,value=84), then i will monitoring again,when i found out value>=85(e.g. id=11,value=89) i will starting counting,if the next two consecutive value>=85(e.g. id=12/id=13),then i will put the third value of event to OutputStream.(e.g. id=13,value=87,timestamp=1470732432000)...
all this is i wanna do,before i post this ask, i've got an answer in this post,i've tried this code:
from every a1=InputStream[value>=85], a2=InputStream[value>=85]+, a3=InputStream[value<85]
select a2[1].id, a2[1].value
having (not (a2[1] is null))
insert into OutPutStream;
and it works,but i found out it will insert the value into OutputStream after the value<=85,and what i want is if i got three consecutive value>=85 then i insert into the value immediately.(i don't want to wait if the next value>=85 all the times)
in fact, i just wanna record value of third seconds in three consecutive seconds value(>=85) .
i'm using wso2das-3.1.0-SNAPSHOT.
Though DAS (Siddhi) supports sequence/pattern processing, for your requirement you might need to write a custom extension. I have written a sample window processor extension to cater your requirement (source code). Download and place siddhi-extension-condition-window-1.0.jar in <das_home>/repository/components/lib/ directory and restart the server. Refer to the test case to get an idea of the usage of the extension.

In GDB is it possible to give an address relative (in lines) from the start of a function?

The subject line basically says it all.
If I give the location based on the file and a line number, that value can change if I edit the file. In fact it tends to change quite often and in an inconvenient way if I edit more than a single function during refactoring. However, it's less likely to change if it were (line-)relative to the beginning of a function.
In case it's not possible to give the line offset from the start of a function, then is it perhaps possible to use convenience variables to emulate it? I.e. if I would declare convenience variables that map to the start of a particular function (a list that I would keep updated)?
According to help break neither seems to be available, but I thought I'd better ask to be sure.
(gdb) help break
Set breakpoint at specified line or function.
break [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]
PROBE_MODIFIER shall be present if the command is to be placed in a
probe point. Accepted values are `-probe' (for a generic, automatically
guessed probe type) or `-probe-stap' (for a SystemTap probe).
LOCATION may be a line number, function name, or "*" and an address.
If a line number is specified, break at start of code for that line.
If a function is specified, break at start of code for that function.
If an address is specified, break at that exact address.
With no LOCATION, uses current execution address of the selected
stack frame. This is useful for breaking on return to a stack frame.
THREADNUM is the number from "info threads".
CONDITION is a boolean expression.
Multiple breakpoints at one place are permitted, and useful if their
conditions are different.
Do "help breakpoints" for info on other commands dealing with breakpoints.
It's a longstanding request to add this to gdb. However, it doesn't exist right now. It's maybe sort of possible with Python, but perhaps not completely, as Python doesn't currently have access to all the breakpoint re-set events (so the breakpoint might work once but not on re-run or library load or some other inferior change).
However, the quoted text shows a nicer way -- use an probe point. These are so-called "SystemTap probe points", but in reality they're more like a generic ELF + GCC feature -- they originated from the SystemTap project but don't depend on it. These let you mark a spot in the source and easily put a breakpoint on it, regardless of other edits to the source. They are already used on linux distros to mark special spots in the unwinder and longjump runtime routines to make debugging work nicely in the presence of these.
I understand that this is an old question, but I still could not find a better solution even now in 2017. Here's a Python solution. Maybe it's not the most robust/cleanest one, but it works very well in many practical scenarios:
class RelativeFunctionBreakpoint (gdb.Breakpoint):
def __init__(self, functionName, lineOffset):
super().__init__(RelativeFunctionBreakpoint.calculate(functionName, lineOffset))
def calculate(functionName, lineOffset):
"""
Calculates an absolute breakpoint location (file:linenumber)
based on functionName and lineOffset
"""
# get info about the file and line number where the function is defined
info = gdb.execute("info line "+functionName, to_string=True)
# extract file name and line number
m = re.match(r'Line[^\d]+(\d+)[^"]+"([^"]+)', info)
if not m:
raise Exception('Failed to find function %s.' % functionName)
line = int(m.group(1))+lineOffset #add the lineOffset
fileName = m.group(2)
return "%s:%d" % (fileName, line)
USAGE:
basic:
RelativeFunctionBreakpoint("yourFunctionName", lineOffset=5)
custom breakpoint:
class YourCustomBreakpoint (RelativeFunctionBreakpoint):
def __init__(self, funcName, lineOffset, customData):
super().__init__(funcName, lineOffset)
self.customData = customData
def stop(self):
# do something
# here you can access self.customData
return False #or True if you want the execution to stop
Advantages of the solution
relatively fast, because the breakpoint is set only once, before the execution starts
robust to changes in the source file if they don't affect the function
Disadvatages
Of course, it's not robust to the edits in the function itself
Not robust to the changes in the output syntax of the info line funcName gdb command (probably there is a better way to extract the file name and line number)
other? you point out