I am creating a command line utility using go , which will request particular server for data and will get the data from server in JSON response. Utility can do multiple requests for multiple products .
I am able to do multiple requests and get the response for each product properly in JSON format.
Now , I want to save the result locally in caching or local files. By which on every request I will check the local cache before sending request to server . If data is available for that product then no request will be send .
I want to save the whole json response in cache or local file and keep that data every time before doing any request to server for data.
Use Case :
Products {"A","B","C","D","E"} It could be any number of products
Test 1 : Get data for A,B,C
Check local storage whether data is available or do request.
Save json request in storage for each product.
So for test 1 ,It will have entry like:
[{test 1 : [{product a : json response} , {product b : json response} ,{product c : json response}]}]
And in case if test fails in between and it get results for two products it should save response for 2 products and if we reran the test it will get result for 3rd product only.
There's a bunch of Go libraries to do HTTP caching transparently.
https://github.com/lox/httpcache
https://github.com/gregjones/httpcache
Choose the one you like most and satisfies your needs better, both have examples in their README to get you started real fast.
If for some reason you can't or don't wanna use third-party libraries check out this answer https://stackoverflow.com/a/32885209/322221 which uses httputil.DumpResponse and http.ReadResponse, both on Go's standard library and also the answerer provides an example implementation you can base your work on.
You can store the data inside a Map and get it via Key, you can implement it or use plugin such as go-cache.
As alternative you can use Redis for storing the data, here you can find the driver for Go
Related
While doing performance testing via JMETER, I encountered one usecase where the POST request call is taking the dynamic data from the website. So in that case when we run our script it fails as that data is no more available on the website.
Payload looks like given below. It is a POST CALL and the payload is changing everytime.
{"marketId":"U-16662943","price":{"up":98,"down":100,"dec":"1.98"},"side":"HOME","line":0,"selectionids":["W2-1"]}
Could anyone suggest how we can make this payload dynamic when we create a script in JMETER?
I can think of 3 possible options:
Duplicate data is not allowed. If this is the case you can use JMeter Functions like __Random(), __RandomString(), __counter() and so on
The data you're sending needs to be aligned with the data in the application somehow, in this case you can use JDBC PreProcessor in order to build a proper request body basing on the data from the application under test database
The data is present in previous response. In that case it's a matter of simple correlation, the dynamic values should be extracted from the previous response using suitable Post-Processors and variables needs to be sent instead of hard-coded parameters
I have a scenario that
1. user upload a file - system process take 10mins -
2. then the user can transfer the file
I cannot do load test in a Thread - #1 then #2 because of the processing time (#2 is performing too quickly before the file is ready for transfer).
I am thinking to keep sending GET requests and finding the response containing the file name then proceeding to #2.
I can only use GET API to get a list of files (API does not support specific file search, the GET return list of file in response)
is that a good approach? how can I do it?
Use While Controller to wait until the uploaded file appears in the list of files from the API. The output of the API can be parsed using i.e. JSON Extractor
Check out Using the While Controller in JMeter for more comprehensive information and example configuration.
I want to get multiple store details using Shopify graphql.
I tried like following but getting only current store details.
nodes(ids: ["gid://shopify/Shop/22954311758","gid://shopify/Shop/25747685469"]) {
... on Shop {
id
email
}
}
I know Shopify not provide other shop details like this because of security reason but I am looking for alternative to get multiple store details in a single graphql call.
This is not possible by default because of 2 restrictions:
1) You can't request two different end points ( you will have to request two stores GraphQL end points at the same time )
2) You will need to pass two different Access Tokens in the header request for each store.
In order to achieve this you will need to create a custom GraphQL server that will handle the request from the two different stores and pass them to your request. So in fact you are making two request in the background but your one will be a single one.
In addition if you make a separate GraphQL server you wont get any advantages in speed unless you cache the requests
But I find this solution a massive overkill in the current state of the request in your question. If you require multiply request of a such matter yes, but if you want to decrease a single request instead of making two just make the two instead of reinventing the wheel.
I want to design an api that allows clients to upload images, then the application creates different variants of the images, like resizing or changing the image format, finally the application stores the image information for each of the variants in a database. The problem occurs when I try to determine the proper strategy to implement this task, here are some different strategies i can think of.
Strategy 1:
Send a post request to /api/pictures/,
create all the image variants and return 201 created if all image files were created correctly and the image information was saved to the database, otherwise it returns a 500 error.
pros: easy to implement
cons: the client has to wait a very long time until all variants of the images are created.
Strategy 2:
Send a post request to /api/pictures/, create just the necessary information for the image variants and store it in the database, then returns a 202 accepted, and start creating the actual image variant files, the 202 response includes a location header with a new url, something like /api/pictures/:pictureId/status to 'monitor' the state of the image variants creation process. The client could use this url to check whether the process was completed or not, if the process was completed return a 201 created, if the process is pending return a 200 ok, if there is an error during the process, it ends and returns a 410 gone
pros: the client gets a very fast response, and it doesn't have to wait until all image variants are created.
cons: hard to implement server side logic, the client has to keep checking the returned location url in order to know when the process has finished.
Another problem is that, for example when the image variants are created correctly but one fails, the entire process returns a 410 gone, the client can keep sending requests to the status url because the application will try to create the failed image again, returning a 201 when its end correctly.
Strategy 3:
This is very similar to strategy 2 but instead of return a location for the whole 'process', it returns an array of locations with status urls for each image variant, this way the client can check the status for each individual image variant instead of the status of the whole process.
pros: same as strategy 2, if one image variant fails during creation, the other variants are not affected. For example, if one of the variants fails during creation it returns a 410 gone while the images that were created properly returns a 201 created.
cons: the client is hard to implement because it has to keep track of an array of locations instead of just one location, the number of requests increases proportionally to the number of variants.
My question is what is the best way to accomplish this task?
Your real problem is how to deal with asynchronous requests in HTTP. My approach to that problem is usually to adopt option 2, returning 202 Accepted and allowing the client to check current status with GET on the Location URI if he wants to.
Optionally, the client can provide a callback URI on a request header, which I will use to notify completion.
I need to receive some data from xml document from the web and
display them but only if I didn't output them earlier.
I check xml document every 5 minutes.
Data items don't have any timestamps associated with them. (So I can't compare them)
What is the best way to check if data is new?
The XML you're reading may not have any timestamps in it, but can you provide a specific example of the web resource you're accessing?
If it is just a resource accessed over regular HTTP, and if the HTTP server is following standards, there should be a Last-Modified HTTP Header that you could use to determine when the file was last modified. (Details at http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html.)