Commit b8d2b047 authored by Benjamin Wilms's avatar Benjamin Wilms

update

parent 783bcbd7
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.codecentric.de.resilience.training</groupId>
<artifactId>transport-booking-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>transport-booking-spring-solution</name>
<parent>
<groupId>org.springframework.boot</groupId>
......@@ -19,6 +20,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR3</spring-cloud.version>
</properties>
<dependencies>
......@@ -26,20 +28,37 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
......
......@@ -31,14 +31,13 @@ public class BookingControlller {
@GetMapping("create")
public ResponseEntity<String> createBooking() {
String jsonResponse = restTemplate.getForObject(connoteUrl, String.class);
ConnoteCommand connoteCommand = new ConnoteCommand(restTemplate, connoteUrl);
String connote = connoteCommand.execute();
// Extract Connote from JSON Repsonse
JsonObject jobj = new Gson().fromJson(jsonResponse, JsonObject.class);
return new ResponseEntity<>(jobj.get("connote").getAsString(), HttpStatus.OK);
return new ResponseEntity<>(connote, HttpStatus.OK);
}
}
package com.codecentric.de.resilience.transport.rest;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.web.client.RestTemplate;
/**
* @author Benjamin Wilms (xd98870)
*/
public class ConnoteCommand extends HystrixCommand<String> {
private final RestTemplate restTemplate;
private final String connoteUrl;
protected ConnoteCommand(RestTemplate restTemplate, String connoteUrl) {
super(HystrixCommandGroupKey.Factory.asKey("ConnoteCommandGroup"));
this.restTemplate = restTemplate;
this.connoteUrl = connoteUrl;
}
@Override
protected String run() throws Exception {
String jsonResponse = restTemplate.getForObject(connoteUrl, String.class);
// Extract Connote from JSON Repsonse
JsonObject jobj = new Gson().fromJson(jsonResponse, JsonObject.class);
String connote = jobj.get("connote").getAsString();
return connote;
}
@Override
protected String getFallback() {
return "fallback";
}
}
......@@ -23,6 +23,6 @@ public class CommandGoodMorningFallback extends HystrixCommand<String> {
protected String getFallback() {
// TODO: implement a fallback and pass the test CommandGoodMorningFallbackTest
return null;
return "Hallo, " + name + "!";
}
}
......@@ -13,6 +13,7 @@ public class AsyncCallGoodMorning {
// implementation starts here, use commandGoodMorning
// TODO: use commandGoodMorning asynchron and return the result
return null;
}
}
......@@ -7,9 +7,9 @@ import rx.functions.Action1;
* @author Benjamin Wilms
*/
public class ColdReactiveCallGoodMorning {
private String result;
public String nonBlockingCallCommandGoodMorningReactive(String name) {
public String nonBlockingCallCommandGoodMorningReactive(String name) throws InterruptedException {
// keep it
de.codecentric.resilience.hystrix.solutions.exercise01.CommandGoodMorning commandGoodMorning = new de.codecentric.resilience.hystrix.solutions.exercise01.CommandGoodMorning(name);
Observable<String> observable = commandGoodMorning.observe();
......@@ -18,10 +18,10 @@ public class ColdReactiveCallGoodMorning {
observable.subscribe(new Action1<String>() {
@Override
public void call(String s) {
result = s;
}
});
return null;
Thread.sleep(1000);
return result;
}
}
......@@ -16,8 +16,8 @@ public class ColdReactiveCallGoodMorningTest {
String name = "Jim";
String resultExpected = "Hallo, " + name + "!";
de.codecentric.resilience.hystrix.solutions.exercise07.ColdReactiveCallGoodMorning coldReactiveCallGoodMorning = new de.codecentric
.resilience.hystrix.solutions.exercise07.ColdReactiveCallGoodMorning();
de.codecentric.resilience.hystrix.exercise07.ColdReactiveCallGoodMorning coldReactiveCallGoodMorning = new de.codecentric
.resilience.hystrix.exercise07.ColdReactiveCallGoodMorning();
String result = coldReactiveCallGoodMorning.nonBlockingCallCommandGoodMorningReactive(name);
......
......@@ -59,8 +59,8 @@ public class ConfigurationCommandExampleTest {
public void timeout_Disabled() throws Exception {
// play with it
int hystrixTimeout = 30;
boolean hystrixTimeoutEnabled = true;
int hystrixTimeout = 10;
boolean hystrixTimeoutEnabled = false;
boolean fallbackEnabled = true;
// leave it as it is
......
......@@ -41,7 +41,6 @@ public class GetUserCommandCollapserTest {
@After
public void tearDown() throws Exception {
Mockito.reset(userServiceMock);
context.shutdown();
}
......@@ -82,7 +81,7 @@ public class GetUserCommandCollapserTest {
}
@Test
public void userCommandCollapser_Sleep110ms() throws Exception {
public void userCommandCollapser_Sleep200ms() throws Exception {
Integer userId1 = userIdsToSearch.get(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment