Skip to content

Commit

Permalink
Merge branch '3.3.3-post' into 4.0.0-post
Browse files Browse the repository at this point in the history
  • Loading branch information
mjsax committed Mar 26, 2019
2 parents 37bf541 + be509ee commit 850f88e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void shouldCreateNewOrderAndGetBackValidatedOrder() {
sendInventory(inventory, Topics.WAREHOUSE_INVENTORY);

//When we POST order and immediately GET on the returned location
client.target(path.urlPost()).request(APPLICATION_JSON_TYPE).post(Entity.json(inputOrder));
postWithRetries(client.target(path.urlPost()).request(APPLICATION_JSON_TYPE), Entity.json(inputOrder), 5);
Invocation.Builder builder = client
.target(path.urlGetValidated(1))
.queryParam("timeout", MIN)
Expand Down Expand Up @@ -84,7 +84,7 @@ public void shouldProcessManyValidOrdersEndToEnd() {
startTimer();

//POST & GET order
client.target(path.urlPost()).request(APPLICATION_JSON_TYPE).post(Entity.json(inputOrder));
postWithRetries(client.target(path.urlPost()).request(APPLICATION_JSON_TYPE), Entity.json(inputOrder), 5);
Invocation.Builder builder = client
.target(path.urlGetValidated(i))
.queryParam("timeout", MIN)
Expand Down Expand Up @@ -122,7 +122,7 @@ public void shouldProcessManyInvalidOrdersEndToEnd() {
startTimer();

//POST & GET order
client.target(path.urlPost()).request(APPLICATION_JSON_TYPE).post(Entity.json(inputOrder));
postWithRetries(client.target(path.urlPost()).request(APPLICATION_JSON_TYPE), Entity.json(inputOrder), 5);
Invocation.Builder builder = client
.target(path.urlGetValidated(i))
.queryParam("timeout", MIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ public void shouldPostOrderAndGetItBack() {
Paths paths = new Paths("localhost", rest.port());

//When we POST an order
Response response = client.target(paths.urlPost())
.request(APPLICATION_JSON_TYPE)
.post(Entity.json(bean));
Response response = postWithRetries(
client.target(paths.urlPost()).request(APPLICATION_JSON_TYPE),
Entity.json(bean),
5);

//Then
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_CREATED);
Expand Down Expand Up @@ -113,9 +114,7 @@ public void shouldGetValidatedOrderOnRequest() {
Paths paths = new Paths("localhost", rest.port());

//When we post an order
client.target(paths.urlPost())
.request(APPLICATION_JSON_TYPE)
.post(Entity.json(beanV1));
postWithRetries(client.target(paths.urlPost()).request(APPLICATION_JSON_TYPE), Entity.json(beanV1), 5);

//Simulate the order being validated
MicroserviceTestUtils.sendOrders(Collections.singletonList(
Expand Down Expand Up @@ -172,9 +171,7 @@ public void shouldGetOrderByIdWhenOnDifferentHost() {
Paths paths2 = new Paths("localhost", rest2.port());

//And one order
client.target(paths1.urlPost())
.request(APPLICATION_JSON_TYPE)
.post(Entity.json(order));
postWithRetries(client.target(paths1.urlPost()).request(APPLICATION_JSON_TYPE), Entity.json(order), 5);

//When GET to rest1
Invocation.Builder builder = client.target(paths1.urlGet(order.getId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import org.slf4j.LoggerFactory;

import javax.ws.rs.ServerErrorException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -259,4 +261,18 @@ public static <T> T getWithRetries(final Invocation.Builder builder,
}
}

public static <T> Response postWithRetries(final Invocation.Builder builder,
final Entity<T> entity,
int numberOfRetries) {
while (true) {
try {
return builder.post(entity);
} catch (ServerErrorException exception) {
if (exception.getMessage().contains("504") && numberOfRetries-- > 0) {
continue;
}
throw exception;
}
}
}
}

0 comments on commit 850f88e

Please sign in to comment.