I want to generate an array of random numbers that only occur once for multiple inputs in JMeter. For example for a range of 1-100:
"age": ${__Random(1,101)},
"weight": ${__Random(1,101)},
"height": ${__Random(1,101)}
There is a chance that two of the variables will have the same value, how could I avoid such incident?
For unique random number you will need to add JSR223 Sampler using ThreadLocalRandom with the following code
import java.util.concurrent.ThreadLocalRandom;
int[] array = ThreadLocalRandom.current().ints(0, 100).distinct().limit(3).toArray();
vars.put("age", String.valueOf(array[0]));
vars.put("weight", String.valueOf(array[1]));
vars.put("height", String.valueOf(array[2]));
And then call the parameters in request:
"age": ${age},
"weight": ${weight},
"height": ${height}
SuperQA${__Random(4,ABCDEFGHIJKLMNOPQRSTUVWXYZ999999999999)}#gmail.com
Here
4: the count of the generating random number
Related
I'm trying to use an edge bundle but was hoping to have the edge thickness determined by the edges themselves rather than the source node they originate from.
The example given in the docs is here:
https://vega.github.io/editor/#/examples/vega/edge-bundling
The two data sources are here:
https://github.com/vega/vega-datasets/blob/master/data/flare-dependencies.json
https://github.com/vega/vega-datasets/blob/master/data/flare.json
In this example, the thickness of the edges is determined by line 170 in the script where a value of 1.5 is assigned to 'strokeWidth'.
"encode": {
"enter": {
"interpolate": {"value": "bundle"},
"strokeWidth": {"value": 1.5}
},
I had hoped to use the "size" value in the flare.json input to tailor each width separately. However, the example creates a tree from flare-dependencies.json and although the tree does pull in this value, visible in VEGA_DEBUG.view.data('dependencies') , I don't know how to access it and get those values to set each of the 'strokeWidth' elements for the edges.
Could you advise how I might do this?
Regards,
I was provided an answer to this as follows:
First add a formula to append the size value from the flare.json dataset as a field 'strokeWidth' by writing this at line 90 in the example:
{
"type": "formula",
"expr": datum.size/10000",
"as": "strokeWidth"
},
Next, in the marks, set the strokeWidth value for each edge in the edgebundle to the associated 'strokeWidth' in the column now created by writing this at what becomes line 176 after the above change:
"strokeWidth": {"field": "strokeWidth"}
After this, the diagram should render with edges of a thickness defined by that 'size' variable. Note that in this example, I had to scale the 'size' value in the original dataset by 10,000 to set the lines at a reasonable thickness.
In practice, I would scale the data prior to presenting it to Vega.
I am using JMETER to test a web app.
First I perform a http GET request which returns a JSON array such as:
[
{
"key1":
{
"subKey":
[
9.120968,
39.255417
]
},
key2 : 1
},
{
"key1":
{
"subKey":
[
9.123852,
39.243237
]
},
key2 : 10
}
]
Basically I want to take randomly one element, take the elements of key1 and create 2 variables in JMeter that will be used for the next query (if randomly it is not possible than just the 1st element).
I tried using JSON Extractor with the following settings (the example shows a single variable case):
and in the next http GET request referencing the parameter as ${var1}.
How to set JSON Extractor to extract a value, save into a JMeter variable to be used in the next http GET request?
Correct JSON Path query would be something like:
$..key1.subKey[${__Random(0,1,)}]
You need to switch Apply to value either to Main sample only or to Main sample and sub-samples
In the above setup:
Match No: 0 - tells JMeter to get random value from key1 subkey
${__Random(0,1,)} - gets a random element from the array, i.e. 9.120968 or 39.255417
More information:
Jayway Jsonpath
API Testing With JMeter and the JSON Extractor
"JMeter variable name to use" option that you've switched on there means that you'd be examining the content of this variable INSTEAD of Sample result.
So the fix is obvious: if you intend to extract whatever you extracting from Sample result - change it back to it.
PS If you intend the opposite (process the variable content, not the sample result) - let me know please.
I've a sql column filled with json document, one for row:
[{
"ID":"TOT",
"type":"ABS",
"value":"32.0"
},
{
"ID":"T1",
"type":"ABS",
"value":"9.0"
},
{
"ID":"T2",
"type":"ABS",
"value":"8.0"
},
{
"ID":"T3",
"type":"ABS",
"value":"15.0"
}]
How is it possible to trasform it into tabular form? I tried with redshift json_extract_path_text and JSON_EXTRACT_ARRAY_ELEMENT_TEXT function, also I tried with json_each and json_each_text (on postgres) but didn't get what expected... any suggestions?
desired results should appear like this:
T1 T2 T3 TOT
9.0 8.0 15.0 32.0
I assume you printed 4 rows. In postgresql
SELECT this_column->'ID'
FROM that_table;
will return column with JSON strings. Use ->> if you want text column. More info here: https://www.postgresql.org/docs/current/static/functions-json.html
In case you were using some old Postgresql (before 9.3), this gets harder : )
Your best option is to use COPY from JSON Format. This will load the JSON directly into a normal table format. You then query it as normal data.
However, I suspect that you will need to slightly modify the format of the file by removing the outer [...] square brackets and also the commas between records, eg:
{
"ID": "TOT",
"type": "ABS",
"value": "32.0"
}
{
"ID": "T1",
"type": "ABS",
"value": "9.0"
}
If, however, your data is already loaded and you cannot re-load the data, you could either extract the data into a new table, or add additional columns to the existing table and use an UPDATE command to extract each field into a new column.
Or, very worst case, you can use one of the JSON Functions to access the information in a JSON field, but this is very inefficient for large requests (eg in a WHERE clause).
Sorry for the very basic question but what the 410 means in myproject.middlewares.ProxyMiddleware': 410 ? (It's so obvious that nobody talk about it!).
RandomUserAgentMiddleware': 400
HttpProxyMiddleware': 110
ProxyMiddleware': 100
I did not find anything about it in the tuto.
EDIT It's not a duplicate from this : the answers says the number is use to sort the order but doesnt explain why they use a specific number. Why in my example above RandomUserAgentMiddleware use 400, why not 399, or 401, is there a reason for that? Or should we roughly take any number that fit in the order?
The number could be roughly any number which fits the order and also gives you flexibility to fit some other middleware in between.
So you use 100, 200, 300, ... instead of 1, 2, 3,... which gives you more flexibility when adding middlewares in between the existing middlewares. Final the middlewares will be sorted by this number and executed in order. So
{
"A": 200,
"B" : 400,
"C" : 300
}
is equivalent to
{
"C" : 200
"A": 100,
"B" : 400,
}
Both would execute middleware in order A, C, B
I am using google custom search API for searching a site and trying returning the maximum possible results by setting the num param to some high number 999 but this is sending error to me :
(400) Invalid Value
But when i set num value to 10 or lower it works perfectly, So it seems like google is putting some limit on returned results.
Here is my Google CSE link you can check by setting the num param
Google CSE API docs are here : API Docs
Any idea guys?
you can retrieve max 10 page with max 10 results.
in query you can use 'num' and 'start' params to lead your request.
num = 1-10 how many results to show
start = 1-100 the starting point
So, if you need max results, you must to do 10 request with num = 10 (default) and start = 1, 11, 21, ... 91
"queries": {
"nextPage": [
{
"title": "Google Custom Search - WTB rolex",
"totalResults": "3030",
"searchTerms": "WTB rolex",
"count": 10,
"startIndex": 11,
I think they want you to page through the result set. So, in this query, there are 3030 results and we're on page 1.
You can use the following parameters to specify which page you want:
"start": integer
It works, although I'm getting random 400s from it too (anything over 100 400s for me).