Jmeter - BeanShell assertion is not running - jmeter

When running the thread, it goes through the whole flow except for the last BeanShell assertion.
My BeanShell code is:
report = vars.get("status_1");
if (report=="active") {
Failure = true;
FailureMessage = "failed to report";
} else {
Failure = false;
}
What could go wrong?

You are comparing String using == you must use .equals() method to compare them.
That is generally true, not just for beanshell, but for most of the java world. Always be careful about how you compare strings. see How do I compare strings in Java?

You can either use .equals() or boolean
boolean report = vars.get("status_1");
if (report) {
Failure = true;
FailureMessage = "failed to report";
} else {
Failure = false;
}

Related

How to chain Coroutine Flow?

I could easily chain coroutine Flows by doing:
val someFlow = flow { //Some logic that my succeed or throw error }
val anotherFlow = flow { // Another logic that my succeed or throe error }
val resultingFlow = someFlow.flatmapLatest(anotherFlow)
but what if I want to individually be able to retry someFlow and anotherFlow where if someFlow already succeed to return a value but anotherFlow failed, I want to retry anotherFlow by using the value from someFlow (The value return when it succeeded).
Whats the best way to do this?
You could use the retryWhen operator on anotherFlow like this:
val someFlow = flow {
//Some logic that my succeed or throw error
}
val anotherFlow = flow {
// Another logic that my succeed or throe error
}
.retryWhen { cause, attempt ->
if (cause is IOException) { // retry on IOException
emit(“Some value”) // emit anything you want before retry
delay(1000) // delay for one second before retry
true
} else { // do not retry otherwise
false
}
}
val resultingFlow = someFlow.flatmapLatest(anotherFlow)
Just be careful because you could end up retrying forever. Use the attempt argument to check the number of times you have retried.
Here is the retryWhen operator official documentation: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/retry-when.html
Have you considered using zip?
I haven't tested or anything but this might be worth a try.
val someFlow = flow {}
val anotherFlow = flow {}
someFlow.zip(anotherFlow) { some, another ->
if(another is Resource.Error)
repository.fetchAnother(some)
else
some
}.collect {
Log.d(TAG, it)
}

AudioKit exportAsynchronously fails after changing input device

I need to make an ability to change input device for record on the fly while program is running (between recording sessions, not in recording process).
Here is the code that, i suppose, have to do that. But when im trying to change input device, AKNodeRecorder records nothing (duration always 0) and after trying to call exportAsynchronously on recorder.audioFile i always get an following error:
[central] 54: ERROR: >avae> AVAudioFile.mm:37: AVAudioFileImpl: error 2003334207
Tried to change almost all, but nothing has an effect. Here is the code that changes input device.
func setupRecordingChain(_ deviceIndex: Int = 0)
{
AudioKit.stop()
setupInputDevice(for: deviceIndex)
self.micMixer = AKMixer(self.mic)
self.micBooster = AKBooster(self.micMixer)
self.micBooster.gain = 0
do {
self.recorder = try AKNodeRecorder(node: self.micMixer)
}
catch {
//catch error
}
self.mainMixer = AKMixer(self.micBooster)
AudioKit.output = self.mainMixer
AudioKit.start()
}
private func setupInputDevice(for deviceIndex: Int)
{
guard let inputDevices = AudioKit.inputDevices else { return }
let inputDevice = inputDevices[deviceIndex]
do {
try self.mic.setDevice(inputDevice)
} catch {
//catch error
}
}

Debugging Jasmine Custom Matcher Messages

I have the following code for a Jasmine Custom Matcher, as described here:
jasmine.addMatchers({
testingFunction: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
if (expected === undefined) {
expected = '';
}
var result = {};
result.pass = util.equals(actual.myValue, 1, customEqualityTesters);
if (result.pass) {
result.message = "Passed";
} else {
result.message = "Failed";
}
return result;
}
}
}
});
And calling it as such:
.then(function() {
expect({
myValue: 1
}).testingFunction();
})
During debugging, I see that execution goes to my custom matcher but for some reason, neither my Pass or Fail messages get printed to the console.
Any ideas as to why this might be?
Thanks
For anyone else that may be running into this issue, I figured out that in my jasmineNodeOpts, I was overriding the jasmine print method as such:
// Overrides jasmine's print method to report dot syntax for custom reports
//print: () => {},
Removing that fixed my issue.

How to avoid nesting do/catch statements in Swift2

I keep wanting to do this:
do {
let result = try getAThing()
} catch {
//error
}
do {
let anotherResult = try getAnotherThing(result) //Error - result out of scope
} catch {
//error
}
But seem only to be able to do this:
do {
let result = try getAThing()
do {
let anotherResult = try getAnotherThing(result)
} catch {
//error
}
} catch {
//error
}
Is there a way to keep an immutable result in scope without having to nest do/catch blocks? Is there a way to guard against the error similar to how we use the guard statement as an inverse of if/else blocks?
In Swift 1.2, you can separate the declaration of the constant from the assignment of the constant. (See "Constants are now more powerful and consistent" in the Swift 1.2 Blog Entry.) So, combining that with the Swift 2 error handling, you can do:
let result: ThingType
do {
result = try getAThing()
} catch {
// error handling, e.g. return or throw
}
do {
let anotherResult = try getAnotherThing(result)
} catch {
// different error handling
}
Alternatively, sometimes we don't really need two different do-catch statements and a single catch will handle both potential thrown errors in one block:
do {
let result = try getAThing()
let anotherResult = try getAnotherThing(result)
} catch {
// common error handling here
}
It just depends on what type of handling you need.

PromiseKit 3.0: chaining with loops

I'm using promisekit 3.0 to help chain alamofire callbacks in a clean way. The objective is to start with a network call, with a promise to return an array of urls.
Then, I'm looking to execute network calls on as many of those urls as needed to find the next link i'm looking for. As soon as this link is found, I can pass it to the next step.
This part is where I'm stuck.
I can pick an arbitrary index in the array that I know has what I want, but I can't figure out the looping to keep it going until the right information is returned.
I tried learning from this obj-c example, but i couldn't get it working in swift.
https://stackoverflow.com/a/30693077/1079379
He's a more tangible example of what i've done.
Network.sharedInstance.makeFirstPromise(.GET, url: NSURL(string: fullSourceLink)! )
.then { (idArray) -> Promise<AnyObject> in
let ids = idArray as! [String]
//how do i do that in swift? (from the example SO answer)
//PMKPromise *p = [PMKPromise promiseWithValue: nil]; // create empty promise
//only thing i could do was feed it the first value
var p:Promise<AnyObject> = Network.sharedInstance.makePromiseRequestHostLink(.POST, id: ids[0])
//var to hold my eventual promise value, doesn't really work unless i set it to something first
var goodValue:Promise<AnyObject>
for item in ids {
//use continue to offset the promise from before the loop started
continue
//hard part
p = p.then{ returnValue -> Promise<AnyObject> in
//need a way to check if what i get is what i wanted then we can break the loop and move on
if returnValue = "whatIwant" {
goodvalue = returnValue
break
//or else we try again with the next on the list
}else {
return Network.sharedInstance.makeLoopingPromise(.POST, id: item)
}
}
}
return goodValue
}.then { (finalLink) -> Void in
//do stuck with finalLink
}
Can someone show me how to structure this properly, please?
Is nesting promises like that anti-pattern to avoid? In that case, what is the best approach.
I have finally figured this out with a combination of your post and the link you posted. It works, but I'll be glad if anyone has input on a proper solution.
func download(arrayOfObjects: [Object]) -> Promise<AnyObject> {
// This stopped the compiler from complaining
var promise : Promise<AnyObject> = Promise<AnyObject>("emptyPromise")
for object in arrayOfObjects {
promise = promise.then { _ in
return Promise { fulfill, reject in
Service.getData(stuff: object.stuff completion: { success, data in
if success {
print("Got the data")
}
fulfill(successful)
})
}
}
}
return promise
}
The only thing I'm not doing is showing in this example is retaining the received data, but I'm assuming you can do that with the results array you have now.
The key to figuring out my particular issue was using the "when" function. It keeps going until all the calls you inputted are finished. The map makes it easier to look at (and think about in my head)
}.then { (idArray) -> Void in
when(idArray.map({Network.sharedInstance.makePromiseRequest(.POST, params: ["thing":$0])})).then{ link -> Promise<String> in
return Promise { fulfill, reject in
let stringLink:[String] = link as! [String]
for entry in stringLink {
if entry != "" {
fulfill(entry)
break
}
}
}
}.then {
}
}

Resources