Merge remote-tracking branch 'upstream/master'
Conflicts: hystrix/src/test/java/com/baeldung/hystrix/HystrixTimeoutTest.java
This commit is contained in:
@@ -17,6 +17,28 @@ public class HystrixAspect {
|
||||
private HystrixCommandProperties.Setter commandProperties;
|
||||
private HystrixThreadPoolProperties.Setter threadPoolProperties;
|
||||
|
||||
@Value("${remoteservice.command.execution.timeout}")
|
||||
private int executionTimeout;
|
||||
|
||||
@Value("${remoteservice.command.sleepwindow}")
|
||||
private int sleepWindow;
|
||||
|
||||
@Value("${remoteservice.command.threadpool.maxsize}")
|
||||
private int maxThreadCount;
|
||||
|
||||
@Value("${remoteservice.command.threadpool.coresize}")
|
||||
private int coreThreadCount;
|
||||
|
||||
@Value("${remoteservice.command.task.queue.size}")
|
||||
private int queueCount;
|
||||
|
||||
@Value("${remoteservice.command.group.key}")
|
||||
private String groupKey;
|
||||
|
||||
@Value("${remoteservice.command.key}")
|
||||
private String key;
|
||||
|
||||
|
||||
@Around("@annotation(com.baeldung.hystrix.HystrixCircuitBreaker)")
|
||||
public Object circuitBreakerAround(final ProceedingJoinPoint aJoinPoint) {
|
||||
return new RemoteServiceCommand(config, aJoinPoint).execute();
|
||||
@@ -31,7 +53,7 @@ public class HystrixAspect {
|
||||
this.commandProperties.withExecutionTimeoutInMilliseconds(executionTimeout);
|
||||
this.commandProperties.withCircuitBreakerSleepWindowInMilliseconds(sleepWindow);
|
||||
|
||||
this.threadPoolProperties= HystrixThreadPoolProperties.Setter();
|
||||
this.threadPoolProperties = HystrixThreadPoolProperties.Setter();
|
||||
this.threadPoolProperties.withMaxQueueSize(maxThreadCount).withCoreSize(coreThreadCount).withMaxQueueSize(queueCount);
|
||||
|
||||
this.config.andCommandPropertiesDefaults(commandProperties);
|
||||
@@ -58,24 +80,4 @@ public class HystrixAspect {
|
||||
}
|
||||
}
|
||||
|
||||
@Value("${remoteservice.command.execution.timeout}")
|
||||
private int executionTimeout;
|
||||
|
||||
@Value("${remoteservice.command.sleepwindow}")
|
||||
private int sleepWindow;
|
||||
|
||||
@Value("${remoteservice.command.threadpool.maxsize}")
|
||||
private int maxThreadCount;
|
||||
|
||||
@Value("${remoteservice.command.threadpool.coresize}")
|
||||
private int coreThreadCount;
|
||||
|
||||
@Value("${remoteservice.command.task.queue.size}")
|
||||
private int queueCount;
|
||||
|
||||
@Value("${remoteservice.command.group.key}")
|
||||
private String groupKey;
|
||||
|
||||
@Value("${remoteservice.command.key}")
|
||||
private String key;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ remoteservice.command.threadpool.coresize=5
|
||||
remoteservice.command.threadpool.maxsize=10
|
||||
remoteservice.command.task.queue.size=5
|
||||
remoteservice.command.sleepwindow=5000
|
||||
remoteservice.timeout=5000
|
||||
remoteservice.timeout=15000
|
||||
@@ -1,23 +1,22 @@
|
||||
package com.baeldung.hystrix;
|
||||
|
||||
import com.netflix.hystrix.*;
|
||||
import com.netflix.hystrix.collapser.RequestCollapserFactory;
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import com.netflix.hystrix.HystrixCommandProperties;
|
||||
import com.netflix.hystrix.HystrixThreadPoolProperties;
|
||||
import com.netflix.hystrix.exception.HystrixRuntimeException;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class HystrixTimeoutTest {
|
||||
|
||||
private HystrixCommand.Setter config;
|
||||
private HystrixCommandProperties.Setter commandProperties ;
|
||||
private HystrixCommandProperties.Setter commandProperties;
|
||||
|
||||
|
||||
@Rule
|
||||
@@ -27,8 +26,8 @@ public class HystrixTimeoutTest {
|
||||
public void setup() {
|
||||
commandProperties = HystrixCommandProperties.Setter();
|
||||
config = HystrixCommand
|
||||
.Setter
|
||||
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup1"));
|
||||
.Setter
|
||||
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,12 +117,12 @@ public class HystrixTimeoutTest {
|
||||
equalTo("Success"));
|
||||
}
|
||||
|
||||
public String invokeRemoteService(long timeout) throws InterruptedException{
|
||||
public String invokeRemoteService(long timeout) throws InterruptedException {
|
||||
String response = null;
|
||||
try{
|
||||
try {
|
||||
response = new RemoteServiceTestCommand(config,
|
||||
new RemoteServiceTestSimulator(timeout)).execute();
|
||||
}catch(HystrixRuntimeException ex){
|
||||
} catch (HystrixRuntimeException ex) {
|
||||
System.out.println("ex = " + ex);
|
||||
}
|
||||
return response;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.hystrix;
|
||||
|
||||
import com.netflix.hystrix.exception.HystrixRuntimeException;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = AppConfig.class)
|
||||
public class SpringAndHystrixIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private HystrixController hystrixController;
|
||||
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void givenTimeOutOf15000_whenExistingClientCalled_thenExpectHystrixRuntimeException() throws InterruptedException {
|
||||
exception.expect(HystrixRuntimeException.class);
|
||||
assertThat(hystrixController.index(), equalTo("Success"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user