replacing sound files in tone.js' sampler - tone.js

I've got tone.js sampler set up.
import sample1 from '../samples/musicbox.mp3'
import sample2 from '../samples/cowbell2.wav'
let sampler = new Tone.Sampler({
urls: {
A2: sample1,
}
}).connect(FXreverb, FXtremolo).toDestination();
the question is how can i replace sample1 with sample2 with initialized sampler?

Related

Jmeter Construct Parameter Value based on DataSet

In JMeter, I want to construct the request parameter value from a dataset file based on the PropertyCount.
Dataset
PropertyCount propertyid1 propertyid2 propertyid3
2 13029526 15763743
3 13029526 15763743 12345645
2 13029526 15763743
Request Input Parameter
"values":["13029526","15763743"]
"values":[${outputString}]
PreProcessor Script
With the the below preprocessor script, I am getting the following output but looking to get the values as in Request Input Parameter, with quotes.
2021-08-29 22:15:04,706 INFO o.a.j.m.J.JSR223 PreProcessor: Required output: 13029526,15763743,
2021-08-29 22:15:04,785 INFO o.a.j.m.J.JSR223 PreProcessor: Required output: 13029526,15763743,
JSR223 PreProcessor
def requiredOutput = new StringBuilder()
1.upto(vars.get('propertycount') as int, {
requiredOutput.append(vars.get('propertyid' + it))
requiredOutput
requiredOutput.append(',')
vars.put("outputString",requiredOutput.toString());
})
You're seem to be constructing a JSON Array therefore it makes more sense to consider using Groovy's JsonBuilder instead of doing manual string concatenation:
def outputString = []
1.upto(vars.get('PropertyCount') as int, {
outputString.add(vars.get("propertyid$it"))
})
vars.put('outputString', new groovy.json.JsonBuilder(outputString).toPrettyString())
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

JMeter Beanshell Postprocessor : Reading a file

I am using the below script in a Beanshell Postprocessor
import java.io.*;
File f =new File ("C:\Users\xxxxx\Desktop\testresults.csv");
FileWriter fw=new FileWriter(f,true);
BufferedWriter bw=new BufferedWriter(fw);
var r=prev.getResponseCode();
if (r.equals("200"))
{
bw.write("Test Passed");
}
else
{
bw.write("Test failed");
}
bw.close();
fw.close();
But I am getting the below error
BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.io.*; File f =new File ("C:\Users\xxxxx\Desktop\testresults.csv") . . . '' Token Parsing Error: Lexical error at line 2, column 23. Encountered: "U" (85), after : ""C:\".
What could cause the above error.
You need to escape a backslash with a backslash like:
C:\\Users\\xxxxx\\Desktop\\testresults.csv
or use a forward slash instead:
C:/Users/xxxxx/Desktop/testresults.csv
A couple more hints:
Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting
If you run your test with 2 or more concurrent threads they will be writing into the same file resulting in data corruption due to a race condition so maybe it worth considering switching to Flexible File Writer instead
Change to JSR223 Post Processor and write as one line (groovy default)
new File("C:\\Users\\xxxx\\Desktop\\\testresults.csv") << (prev.getResponseCode().equals("200") ? "Test Passed" : "Test failed")

Logic design in jmeter - pass errors in test flow chain

please advice what has to be the good design and implementation of the following scenario I'm faced with.
Design
Sampler 1 (prerequisite)
Sampler 2 (prerequisite)
Sampler 3 (actual test)
Execution
Sampler 1 failed with error
Sampler 2 not executed
Sampler 3 not executed but marked as failed with Sampler 1 error or executed but result data replaced with error from Sampler 1
Note: Prerequisite samplers are excluded from end result report(already found solution for that).
You can design your test as follows:
Sampler 1
JSR223 PostProcessor with the following code:
if (!prev.isSuccessful()) {
vars.putObject('sampler1Result', prev)
}
If Controller with the following condition: ${JMeterThread.last_sample_ok}
Sampler 2
Sampler 3
JSR223 PostProcessor with the following code:
if (vars.getObject('sampler1Result') != null) {
def sampler1Result = vars.getObject('sampler1Result')
prev.setSuccessful(sampler1Result.isSuccessful())
prev.setResponseCode(sampler1Result.getResponseCode())
prev.setResponseMessage(sampler1Result.getResponseMessage())
prev.setResponseData(sampler1Result.getResponseData())
}
Where:
vars - is a shorthand for JMeterVariables class instance
prev - is a shorthand for HTTPSampleResult class instance

Beanshell Script throws error while running from terminal but it runs perfectly in GUI mode in JMETER

I tried to run the following script:
import org.apache.commons.io.FileUtils; // necessary import
int lines = FileUtils.readLines(new File("${testPlanFileDir}/csv/test_smtp_save.csv")).size() - 1; // get lines count
vars.put("lines", String.valueOf(lines)); // store the count into "lines" variable
To get the number of lines in my csv, so that I can execute a loop according to the number of lines in the CSV file.
The script above runs perfectly if I run from GUI mode, but when I run from terminal then it throws following error.
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval
Sourced file: inline evaluation of:
``import org.apache.commons.io.FileUtils; // necessary import int lines = FileUtil . . . ''
: Typed variable declaration : Method Invocation FileUtils.readLines
How do you get this ${testPlanFileDir} variable value? Apart from it the code looks good.
If you want to have more relevant error message you can try putting your code into the try block:
import org.apache.commons.io.FileUtils;
try {
int lines = FileUtils.readLines(new File("${testPlanFileDir}/csv/test_smtp_save.csv")).size() - 1;
vars.put("lines", String.valueOf(lines));
}
catch (Throwable ex) {
log.error("Error in Beanshell", ex);
throw ex;
}
And look into jmeter.log file - it will contain the "usual" stacktrace.
Alternatively you can add debug() command to the very beginning of your Beanshell script - it will toggle debugging output to stdout
See How to Use BeanShell: JMeter's Favorite Built-in Component for more Beanshell-related tips and tricks
Replace ${testPlanFileDir} by:
vars.get("testPlanFileDir")
You should avoid using Beanshell in favor of JSR223+Groovy+Cache which is embedded in JMeter 3.0, see:
http://jmeter.apache.org/changes.html
https://www.ubik-ingenierie.com/blog/jmeter_performance_tuning_tips/
I used this to get the current directory of .jmx file.
Declared varaible TestPlanFileDir as;
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}

Bash script to insert code from one file at a specific location in another file?

I have a fileA with a snippet of code, and I need a script to insert that snippet into fileB on the line after a specific pattern.
I'm trying to make the accepted answer in this thread work, but it's not, and is not giving an error so not sure why not:
sed -e '/pattern/r text2insert' filewithpattern
Any suggestions?
pattern (insert snippet on line after):
def boot {
also tried escaped pattern but no luck:
def\ boot\ {
def\ boot\ \{
fileA snippet:
LiftRules.htmlProperties.default.set((r: Req) =>
new Html5Properties(r.userAgent))
fileB (Boot.scala):
package bootstrap.liftweb
import net.liftweb._
import util._
import Helpers._
import common._
import http._
import sitemap._
import Loc._
/**
* A class that's instantiated early and run. It allows the application
* to modify lift's environment
*/
class Boot {
def boot {
// where to search snippet
LiftRules.addToPackages("code")
// Build SiteMap
val entries = List(
Menu.i("Home") / "index", // the simple way to declare a menu
// more complex because this menu allows anything in the
// /static path to be visible
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))
// set the sitemap. Note if you don't want access control for
// each page, just comment this line out.
LiftRules.setSiteMap(SiteMap(entries:_*))
// Use jQuery 1.4
LiftRules.jsArtifacts = net.liftweb.http.js.jquery.JQuery14Artifacts
//Show the spinny image when an Ajax call starts
LiftRules.ajaxStart =
Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)
// Make the spinny image go away when it ends
LiftRules.ajaxEnd =
Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)
// Force the request to be UTF-8
LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
}
}
The sed format looks correct to me.
To help you diagnose this, try it with two simpler text files and a simple pattern.
File filewithpattern:
hello
world
File textinsert:
foo
goo
Now run sed:
sed -e '/hello/r textinsert' filewithpattern
You should see this:
hello
foo
goo
world
Does that work for you?
If so, then edit filewithpattern to use your target:
hello
def boot {
world
Run the command:
sed -e '/def boot {/r textinsert' filewithpattern
You should see this:
hello
def boot {
foo
goo
world
If you want variable substitution, try this:
#!/bin/bash
PATTERN='def boot {'
sed -e "/${PATTERN}/r textinsert" filewithpattern

Resources