Search in sources :

Example 1 with HystrixThreadPoolProperties

use of com.netflix.hystrix.HystrixThreadPoolProperties in project Hystrix by Netflix.

the class BasicHystrixTest method getThreadPoolProperties.

protected final HystrixThreadPoolProperties getThreadPoolProperties(HystrixInvokableInfo<?> command) {
    try {
        Field field = command.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("threadPool");
        field.setAccessible(true);
        HystrixThreadPool threadPool = (HystrixThreadPool) field.get(command);
        Field field2 = HystrixThreadPool.HystrixThreadPoolDefault.class.getDeclaredField("properties");
        field2.setAccessible(true);
        return (HystrixThreadPoolProperties) field2.get(threadPool);
    } catch (NoSuchFieldException e) {
        throw Throwables.propagate(e);
    } catch (IllegalAccessException e) {
        throw Throwables.propagate(e);
    }
}
Also used : Field(java.lang.reflect.Field) HystrixThreadPool(com.netflix.hystrix.HystrixThreadPool) HystrixThreadPoolProperties(com.netflix.hystrix.HystrixThreadPoolProperties)

Example 2 with HystrixThreadPoolProperties

use of com.netflix.hystrix.HystrixThreadPoolProperties in project Hystrix by Netflix.

the class BasicFallbackDefaultPropertiesTest method testFallbackOverridesThreadPollProperties.

@Test
public void testFallbackOverridesThreadPollProperties() {
    service.commandWithFallbackOverridesDefaultProperties();
    com.netflix.hystrix.HystrixInvokableInfo fallbackCommand = getHystrixCommandByKey("fallbackOverridesDefaultProperties");
    HystrixThreadPoolProperties properties = getThreadPoolProperties(fallbackCommand);
    assertEquals(321, properties.maxQueueSize().get().intValue());
}
Also used : HystrixThreadPoolProperties(com.netflix.hystrix.HystrixThreadPoolProperties) Test(org.junit.Test) BasicHystrixTest(com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)

Example 3 with HystrixThreadPoolProperties

use of com.netflix.hystrix.HystrixThreadPoolProperties in project Hystrix by Netflix.

the class HystrixPropertiesFactory method getThreadPoolProperties.

/**
     * Get an instance of {@link HystrixThreadPoolProperties} with the given factory {@link HystrixPropertiesStrategy} implementation for each {@link HystrixThreadPool} instance.
     * 
     * @param key
     *            Pass-thru to {@link HystrixPropertiesStrategy#getThreadPoolProperties} implementation.
     * @param builder
     *            Pass-thru to {@link HystrixPropertiesStrategy#getThreadPoolProperties} implementation.
     * @return {@link HystrixThreadPoolProperties} instance
     */
public static HystrixThreadPoolProperties getThreadPoolProperties(HystrixThreadPoolKey key, HystrixThreadPoolProperties.Setter builder) {
    HystrixPropertiesStrategy hystrixPropertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
    String cacheKey = hystrixPropertiesStrategy.getThreadPoolPropertiesCacheKey(key, builder);
    if (cacheKey != null) {
        HystrixThreadPoolProperties properties = threadPoolProperties.get(cacheKey);
        if (properties != null) {
            return properties;
        } else {
            if (builder == null) {
                builder = HystrixThreadPoolProperties.Setter();
            }
            // create new instance
            properties = hystrixPropertiesStrategy.getThreadPoolProperties(key, builder);
            // cache and return
            HystrixThreadPoolProperties existing = threadPoolProperties.putIfAbsent(cacheKey, properties);
            if (existing == null) {
                return properties;
            } else {
                return existing;
            }
        }
    } else {
        // no cacheKey so we generate it with caching
        return hystrixPropertiesStrategy.getThreadPoolProperties(key, builder);
    }
}
Also used : HystrixThreadPoolProperties(com.netflix.hystrix.HystrixThreadPoolProperties)

Example 4 with HystrixThreadPoolProperties

use of com.netflix.hystrix.HystrixThreadPoolProperties in project Hystrix by Netflix.

the class BasicCommandDefaultPropertiesTest method testCommandInheritsThreadPollProperties.

@Test
public void testCommandInheritsThreadPollProperties() {
    service.commandInheritsDefaultProperties();
    HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();
    HystrixThreadPoolProperties properties = getThreadPoolProperties(command);
    assertEquals(123, properties.maxQueueSize().get().intValue());
}
Also used : HystrixThreadPoolProperties(com.netflix.hystrix.HystrixThreadPoolProperties) Test(org.junit.Test) BasicHystrixTest(com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)

Example 5 with HystrixThreadPoolProperties

use of com.netflix.hystrix.HystrixThreadPoolProperties in project Hystrix by Netflix.

the class BasicCommandDefaultPropertiesTest method testCommandOverridesDefaultThreadPollProperties.

@Test
public void testCommandOverridesDefaultThreadPollProperties() {
    service.commandOverridesDefaultThreadPoolProperties();
    HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();
    HystrixThreadPoolProperties properties = getThreadPoolProperties(command);
    assertEquals(321, properties.maxQueueSize().get().intValue());
}
Also used : HystrixThreadPoolProperties(com.netflix.hystrix.HystrixThreadPoolProperties) Test(org.junit.Test) BasicHystrixTest(com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)

Aggregations

HystrixThreadPoolProperties (com.netflix.hystrix.HystrixThreadPoolProperties)8 BasicHystrixTest (com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest)6 Test (org.junit.Test)6 HystrixThreadPool (com.netflix.hystrix.HystrixThreadPool)1 User (com.netflix.hystrix.contrib.javanica.test.common.domain.User)1 Field (java.lang.reflect.Field)1