use of io.confluent.examples.streams.microservices.domain.beans.OrderBean in project kafka-streams-examples by confluentinc.
the class EndToEndTest method shouldProcessManyValidOrdersEndToEnd.
@Test
public void shouldProcessManyValidOrdersEndToEnd() throws Exception {
client = getClient();
// Add inventory required by the inventory service
List<KeyValue<Product, Integer>> inventory = asList(new KeyValue<>(UNDERPANTS, 75), new KeyValue<>(JUMPERS, 10));
sendInventory(inventory, Topics.WAREHOUSE_INVENTORY);
// Send ten orders in succession
for (int i = 0; i < 10; i++) {
OrderBean inputOrder = new OrderBean(id(i), 2L, OrderState.CREATED, Product.JUMPERS, 1, 1d);
startTimer();
// POST & GET order
client.target(path.urlPost()).request(APPLICATION_JSON_TYPE).post(Entity.json(inputOrder));
returnedBean = client.target(path.urlGetValidated(i)).queryParam("timeout", MIN).request(APPLICATION_JSON_TYPE).get(newBean());
endTimer();
assertThat(returnedBean).isEqualTo(new OrderBean(inputOrder.getId(), inputOrder.getCustomerId(), OrderState.VALIDATED, inputOrder.getProduct(), inputOrder.getQuantity(), inputOrder.getPrice()));
}
}
use of io.confluent.examples.streams.microservices.domain.beans.OrderBean in project kafka-streams-examples by confluentinc.
the class OrdersService method fetchFromOtherHost.
private void fetchFromOtherHost(final String path, AsyncResponse asyncResponse, long timeout) {
log.info("Chaining GET to a different instance: " + path);
try {
OrderBean bean = client.target(path).queryParam("timeout", timeout).request(MediaType.APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
});
asyncResponse.resume(bean);
} catch (Exception swallowed) {
}
}
use of io.confluent.examples.streams.microservices.domain.beans.OrderBean in project kafka-streams-examples by confluentinc.
the class EndToEndTest method shouldCreateNewOrderAndGetBackValidatedOrder.
@Test
public void shouldCreateNewOrderAndGetBackValidatedOrder() throws Exception {
OrderBean inputOrder = new OrderBean(id(1L), 2L, OrderState.CREATED, Product.JUMPERS, 1, 1d);
client = getClient();
// Add inventory required by the inventory service with enough items in stock to pass validation
List<KeyValue<Product, Integer>> inventory = asList(new KeyValue<>(UNDERPANTS, 75), new KeyValue<>(JUMPERS, 10));
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));
returnedBean = client.target(path.urlGetValidated(1)).queryParam("timeout", MIN).request(APPLICATION_JSON_TYPE).get(newBean());
// Then
assertThat(returnedBean.getState()).isEqualTo(OrderState.VALIDATED);
}
use of io.confluent.examples.streams.microservices.domain.beans.OrderBean in project kafka-streams-examples by confluentinc.
the class EndToEndTest method shouldProcessManyInvalidOrdersEndToEnd.
@Test
public void shouldProcessManyInvalidOrdersEndToEnd() throws Exception {
client = getClient();
// Add inventory required by the inventory service
List<KeyValue<Product, Integer>> inventory = asList(new KeyValue<>(UNDERPANTS, 75000), // ***nothing in stock***
new KeyValue<>(JUMPERS, 0));
sendInventory(inventory, Topics.WAREHOUSE_INVENTORY);
// Send ten orders one after the other
for (int i = 0; i < 10; i++) {
OrderBean inputOrder = new OrderBean(id(i), 2L, OrderState.CREATED, Product.JUMPERS, 1, 1d);
startTimer();
// POST & GET order
client.target(path.urlPost()).request(APPLICATION_JSON_TYPE).post(Entity.json(inputOrder));
returnedBean = client.target(path.urlGetValidated(i)).queryParam("timeout", MIN).request(APPLICATION_JSON_TYPE).get(newBean());
endTimer();
assertThat(returnedBean).isEqualTo(new OrderBean(inputOrder.getId(), inputOrder.getCustomerId(), OrderState.FAILED, inputOrder.getProduct(), inputOrder.getQuantity(), inputOrder.getPrice()));
}
}
use of io.confluent.examples.streams.microservices.domain.beans.OrderBean in project kafka-streams-examples by confluentinc.
the class OrdersServiceTest method shouldTimeoutGetIfNoResponseIsFound.
@Test
public void shouldTimeoutGetIfNoResponseIsFound() {
final Client client = ClientBuilder.newClient();
// Start the rest interface
rest = new OrdersService("localhost");
rest.start(CLUSTER.bootstrapServers());
Paths paths = new Paths("localhost", rest.port());
// Then GET order should timeout
try {
client.target(paths.urlGet(1)).queryParam("timeout", // Lower the request timeout
100).request(APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
});
fail("Request should have failed as materialized view has not been updated");
} catch (ServerErrorException e) {
assertThat(e.getMessage()).isEqualTo("HTTP 504 Gateway Timeout");
}
}
Aggregations