Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstated HystrixTest and added unit test for modifying semaphore count #838

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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