-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Implementation for feature request #1013 #1032
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.netflix.hystrix; | ||
|
||
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty; | ||
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy; | ||
import com.netflix.hystrix.strategy.properties.HystrixProperty; | ||
|
||
import static com.netflix.hystrix.strategy.properties.HystrixProperty.Factory.asProperty; | ||
|
||
/** | ||
* Properties for Hystrix timer thread pool. | ||
* <p> | ||
* Default implementation of methods uses Archaius (https://github.com/Netflix/archaius) | ||
*/ | ||
public abstract class HystrixTimerThreadPoolProperties { | ||
|
||
private final HystrixProperty<Integer> corePoolSize; | ||
|
||
protected HystrixTimerThreadPoolProperties() { | ||
this(new Setter().withCoreSize(Runtime.getRuntime().availableProcessors())); | ||
} | ||
|
||
protected HystrixTimerThreadPoolProperties(Setter setter) { | ||
this.corePoolSize = getProperty("hystrix", "coreSize", setter.getCoreSize()); | ||
} | ||
|
||
private static HystrixProperty<Integer> getProperty(String propertyPrefix, String instanceProperty, Integer defaultValue) { | ||
return asProperty(new HystrixPropertiesChainedArchaiusProperty.IntegerProperty( | ||
new HystrixPropertiesChainedArchaiusProperty.DynamicIntegerProperty(propertyPrefix + ".timer.threadpool.default." + instanceProperty, defaultValue))); | ||
} | ||
|
||
public HystrixProperty<Integer> getCorePoolSize() { | ||
return corePoolSize; | ||
} | ||
|
||
/** | ||
* Factory method to retrieve the default Setter. | ||
*/ | ||
public static Setter Setter() { | ||
return new Setter(); | ||
} | ||
|
||
/** | ||
* Fluent interface that allows chained setting of properties. | ||
* <p> | ||
* See {@link HystrixPropertiesStrategy} for more information on order of precedence. | ||
* <p> | ||
* Example: | ||
* <p> | ||
* <pre> {@code | ||
* HystrixTimerThreadPoolProperties.Setter() | ||
* .withCoreSize(10); | ||
* } </pre> | ||
* | ||
* @NotThreadSafe | ||
*/ | ||
public static class Setter { | ||
private Integer coreSize = null; | ||
|
||
private Setter() { | ||
} | ||
|
||
public Integer getCoreSize() { | ||
return coreSize; | ||
} | ||
|
||
public Setter withCoreSize(int value) { | ||
this.coreSize = value; | ||
return this; | ||
} | ||
|
||
/** | ||
* Base properties for unit testing. | ||
*/ | ||
/* package */ | ||
static Setter getUnitTestPropertiesBuilder() { | ||
return new Setter().withCoreSize(10); // size of thread pool | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright 2012 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.hystrix.strategy.properties; | ||
|
||
import com.netflix.hystrix.HystrixThreadPoolKey; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused import |
||
import com.netflix.hystrix.HystrixThreadPoolProperties; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused import |
||
import com.netflix.hystrix.HystrixTimerThreadPoolProperties; | ||
|
||
/** | ||
* Default implementation of {@link HystrixTimerThreadPoolProperties} using Archaius (https://github.com/Netflix/archaius) | ||
* | ||
* @ExcludeFromJavadoc | ||
*/ | ||
public class HystrixPropertiesTimerThreadPoolDefault extends HystrixTimerThreadPoolProperties { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/** | ||
* Copyright 2015 Netflix, Inc. | ||
* | ||
* <p/> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* <p/> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* <p/> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
|
@@ -15,22 +15,35 @@ | |
*/ | ||
package com.netflix.hystrix.util; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import com.netflix.hystrix.Hystrix; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import |
||
import com.netflix.hystrix.HystrixTimerThreadPoolProperties; | ||
import com.netflix.hystrix.strategy.HystrixPlugins; | ||
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy; | ||
import com.netflix.hystrix.util.HystrixTimer.ScheduledExecutor; | ||
import com.netflix.hystrix.util.HystrixTimer.TimerListener; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.lang.ref.Reference; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.junit.Test; | ||
|
||
import com.netflix.hystrix.util.HystrixTimer.ScheduledExecutor; | ||
import com.netflix.hystrix.util.HystrixTimer.TimerListener; | ||
import static org.junit.Assert.*; | ||
|
||
|
||
public class HystrixTimerTest { | ||
|
||
@Before | ||
public void setUp() { | ||
HystrixTimer timer = HystrixTimer.getInstance(); | ||
HystrixTimer.reset(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
HystrixPlugins.reset(); | ||
} | ||
|
||
@Test | ||
public void testSingleCommandSingleInterval() { | ||
HystrixTimer timer = HystrixTimer.getInstance(); | ||
|
@@ -163,6 +176,37 @@ public void testReset() { | |
HystrixTimer.reset(); | ||
} | ||
|
||
@Test | ||
public void testThreadPoolSizeDefault() { | ||
|
||
HystrixTimer hystrixTimer = HystrixTimer.getInstance(); | ||
hystrixTimer.startThreadIfNeeded(); | ||
assertEquals(Runtime.getRuntime().availableProcessors(), hystrixTimer.executor.get().getThreadPool().getCorePoolSize()); | ||
} | ||
|
||
@Test | ||
public void testThreadPoolSizeConfiguredWithBuilder() { | ||
|
||
HystrixTimerThreadPoolProperties.Setter builder = HystrixTimerThreadPoolProperties.Setter().withCoreSize(1); | ||
final HystrixTimerThreadPoolProperties props = new HystrixTimerThreadPoolProperties(builder) { | ||
}; | ||
|
||
HystrixPropertiesStrategy strategy = new HystrixPropertiesStrategy() { | ||
@Override | ||
public HystrixTimerThreadPoolProperties getTimerThreadPoolProperties() { | ||
return props; | ||
} | ||
}; | ||
|
||
HystrixPlugins.getInstance().registerPropertiesStrategy(strategy); | ||
|
||
HystrixTimer hystrixTimer = HystrixTimer.getInstance(); | ||
hystrixTimer.startThreadIfNeeded(); | ||
|
||
assertEquals(1, hystrixTimer.executor.get().getThreadPool().getCorePoolSize()); | ||
|
||
} | ||
|
||
private static class TestListener implements TimerListener { | ||
|
||
private final int interval; | ||
|
@@ -235,5 +279,5 @@ public int getIntervalTimeInMilliseconds() { | |
|
||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be here? It appears unused