mercredi 13 avril 2016

Waiting for POST to finish processing before calling GET Request

I am doing an integration test where I call a POST request that send a file to the server. Immediately after the POST, I call a GET request that retrieves the document and get a response that gives me the attributes of that document. However, sometimes I would get a 404 error, saying that the document does not exist until I run it again a few seconds after.

I am thinking the POST has not finished processing yet so I have implement a Thread.sleep to wait 10 seconds but this way does not seem good as it might wait longer than it needs to or might not wait long enough. Is there some kind of 'implicit wait' that allows the POST to finish processing before requesting the GET?

Below is a code snippet:

String str = fileToStringProcessing("C:/Users/Linh/Desktop/file.xml");
ResponseEntity<Message> postResponse = getRestTemplate().exchange(getUri() + "documents", HttpMethod.POST, new HttpEntity(str, getHeaders()), Message.class);
Thread.sleep(10000);
ResponseEntity<Account> getResponse = getRestTemplate().exchange(getUri() + "account/7452616052/documents?start=2015-01-01&end=2016-03-31", HttpMethod.GET, getHttpEntity(), Account.class);
ResponseEntity<Message> deleteResponse = getRestTemplate().exchange(getUri() + "documents/2015067452616054", HttpMethod.DELETE, getHttpEntity(), Message.class);

Aucun commentaire:

Enregistrer un commentaire