Skip to content

Commit

Permalink
Merge pull request #838 from mattrjacobs/unit-test-for-command-proper…
Browse files Browse the repository at this point in the history
…ties-reset

Reinstated HystrixTest and added unit test for modifying semaphore count
  • Loading branch information
mattrjacobs committed Jul 22, 2015
2 parents b806672 + d849fb0 commit 9ca80ab
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions hystrix-core/src/test/java/com/netflix/hystrix/HystrixTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@
import org.junit.Before;

import com.netflix.hystrix.HystrixCommand.Setter;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class HystrixTest {
@Before
public void reset() {
Hystrix.reset();
}

/*@Test
@Test
public void testNotInThread() {
assertNull(Hystrix.getCurrentThreadExecutingCommand());
}
Expand Down Expand Up @@ -100,7 +105,7 @@ public void testInsideHystrixSemaphoreExecute() {

HystrixCommand<Boolean> command = new HystrixCommand<Boolean>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("TestUtil"))
.andCommandKey(HystrixCommandKey.Factory.asKey("SemaphoreIsolatedCommandName"))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE))) {
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE))) {

@Override
protected Boolean run() {
Expand All @@ -122,7 +127,7 @@ public void testInsideHystrixSemaphoreQueue() throws Exception {

HystrixCommand<Boolean> command = new HystrixCommand<Boolean>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("TestUtil"))
.andCommandKey(HystrixCommandKey.Factory.asKey("SemaphoreIsolatedCommandName"))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE))) {
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE))) {

@Override
protected Boolean run() {
Expand All @@ -145,7 +150,7 @@ public void testThreadNestedInsideHystrixSemaphore() {
HystrixCommand<Boolean> command = new HystrixCommand<Boolean>(Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("TestUtil"))
.andCommandKey(HystrixCommandKey.Factory.asKey("OuterSemaphoreCommand"))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE))) {
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE))) {

@Override
protected Boolean run() {
Expand Down Expand Up @@ -186,22 +191,25 @@ protected Boolean run() {
//see https://github.com/Netflix/Hystrix/issues/280
@Test
public void testResetCommandProperties() {
HystrixCommand<Boolean> cmd1 = new ResettableCommand(100, 10);
assertEquals(100L, (long) cmd1.getProperties().executionIsolationThreadTimeoutInMilliseconds().get());
HystrixCommand<Boolean> cmd1 = new ResettableCommand(100, 1, 10);
assertEquals(100L, (long) cmd1.getProperties().executionTimeoutInMilliseconds().get());
assertEquals(1L, (long) cmd1.getProperties().executionIsolationSemaphoreMaxConcurrentRequests().get());
assertEquals(10L, (long) cmd1.threadPool.getExecutor().getCorePoolSize());

Hystrix.reset();

HystrixCommand<Boolean> cmd2 = new ResettableCommand(700, 40);
assertEquals(700L, (long) cmd2.getProperties().executionIsolationThreadTimeoutInMilliseconds().get());
HystrixCommand<Boolean> cmd2 = new ResettableCommand(700, 2, 40);
assertEquals(700L, (long) cmd2.getProperties().executionTimeoutInMilliseconds().get());
assertEquals(2L, (long) cmd2.getProperties().executionIsolationSemaphoreMaxConcurrentRequests().get());
assertEquals(40L, (long) cmd2.threadPool.getExecutor().getCorePoolSize());
}*/
}

private static class ResettableCommand extends HystrixCommand<Boolean> {
ResettableCommand(int timeout, int poolCoreSize) {
ResettableCommand(int timeout, int semaphoreCount, int poolCoreSize) {
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("GROUP"))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(timeout))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
.withExecutionTimeoutInMilliseconds(timeout)
.withExecutionIsolationSemaphoreMaxConcurrentRequests(semaphoreCount))
.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(poolCoreSize)));
}

Expand Down

0 comments on commit 9ca80ab

Please sign in to comment.