Search in sources :

Example 1 with HystrixConcurrencyStrategy

use of com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy in project Hystrix by Netflix.

the class HystrixCommandTestWithCustomConcurrencyStrategy method testCommandDoesNotRequireContextConcurrencyStrategyProvidesItContextLeftUninitialized.

/**
     * HystrixConcurrencyStrategy
     ** useDefaultRequestContext : true
     * HystrixCommand
     ** useRequestCache   : false
     ** useRequestLog     : false
     *
     * OUTCOME: RequestLog not set up in command, static access is null
     */
@Test
public void testCommandDoesNotRequireContextConcurrencyStrategyProvidesItContextLeftUninitialized() {
    HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(true);
    HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);
    //context is not set up
    HystrixRequestContext.setContextOnCurrentThread(null);
    HystrixCommand<Boolean> cmd = new TestCommand(false, false);
    //command execution not affected by missing context
    assertTrue(cmd.execute());
    printRequestLog();
    assertNull(HystrixRequestLog.getCurrentRequest());
    assertNull(HystrixRequestLog.getCurrentRequest(strategy));
    assertNull(cmd.currentRequestLog);
}
Also used : HystrixConcurrencyStrategy(com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy) Test(org.junit.Test)

Example 2 with HystrixConcurrencyStrategy

use of com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy in project Hystrix by Netflix.

the class HystrixCommandTestWithCustomConcurrencyStrategy method testCommandRequiresContextConcurrencyStrategyDoesNotProvideItContextLeftUninitialized.

/**
     * HystrixConcurrencyStrategy
     ** useDefaultRequestContext : false
     * HystrixCommand
     ** useRequestCache   : true
     ** useRequestLog     : true
     *
     * OUTCOME: RequestLog not set up in command, not available statically
     */
@Test
public void testCommandRequiresContextConcurrencyStrategyDoesNotProvideItContextLeftUninitialized() {
    HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(false);
    HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);
    //context is not set up
    HystrixRequestContext.setContextOnCurrentThread(null);
    HystrixCommand<Boolean> cmd = new TestCommand(true, true);
    //command execution not affected by missing context
    assertTrue(cmd.execute());
    printRequestLog();
    assertNull(HystrixRequestLog.getCurrentRequest());
    assertNull(HystrixRequestLog.getCurrentRequest(strategy));
    assertNull(cmd.currentRequestLog);
}
Also used : HystrixConcurrencyStrategy(com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy) Test(org.junit.Test)

Example 3 with HystrixConcurrencyStrategy

use of com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy in project Hystrix by Netflix.

the class HystrixCommandTestWithCustomConcurrencyStrategy method testCommandRequiresContextConcurrencyStrategyDoesNotProvideItContextSetUpCorrectly.

/**
     * HystrixConcurrencyStrategy
     ** useDefaultRequestContext : false
     * HystrixCommand
     ** useRequestCache   : true
     ** useRequestLog     : true
     *
     * OUTCOME: RequestLog not set up in command, not available statically
     */
@Test
public void testCommandRequiresContextConcurrencyStrategyDoesNotProvideItContextSetUpCorrectly() {
    HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(false);
    HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);
    //context is set up properly
    HystrixRequestContext context = HystrixRequestContext.initializeContext();
    HystrixCommand<Boolean> cmd = new TestCommand(true, true);
    assertTrue(cmd.execute());
    printRequestLog();
    assertNull(HystrixRequestLog.getCurrentRequest());
    assertNull(HystrixRequestLog.getCurrentRequest(strategy));
    assertNull(cmd.currentRequestLog);
    context.shutdown();
}
Also used : HystrixConcurrencyStrategy(com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy) HystrixRequestContext(com.netflix.hystrix.strategy.concurrency.HystrixRequestContext) Test(org.junit.Test)

Example 4 with HystrixConcurrencyStrategy

use of com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy in project Hystrix by Netflix.

the class HystrixCommandTestWithCustomConcurrencyStrategy method testCommandDoesNotRequireContextConcurrencyStrategyDoesNotProvideItContextLeftUninitialized.

/**
     * HystrixConcurrencyStrategy
     ** useDefaultRequestContext : false
     * HystrixCommand
     ** useRequestCache   : false
     ** useRequestLog     : false
     *
     * OUTCOME: RequestLog not set up in command, not available statically
     */
@Test
public void testCommandDoesNotRequireContextConcurrencyStrategyDoesNotProvideItContextLeftUninitialized() {
    HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(false);
    HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);
    //context is not set up
    HystrixRequestContext.setContextOnCurrentThread(null);
    HystrixCommand<Boolean> cmd = new TestCommand(true, true);
    //command execution unaffected by missing context
    assertTrue(cmd.execute());
    printRequestLog();
    assertNull(HystrixRequestLog.getCurrentRequest());
    assertNull(HystrixRequestLog.getCurrentRequest(strategy));
    assertNull(cmd.currentRequestLog);
}
Also used : HystrixConcurrencyStrategy(com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy) Test(org.junit.Test)

Example 5 with HystrixConcurrencyStrategy

use of com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy in project Hystrix by Netflix.

the class HystrixCommandTestWithCustomConcurrencyStrategy method testCommandRequiresContextConcurrencyStrategyProvidesItContextLeftUninitialized.

/**
     * HystrixConcurrencyStrategy
     ** useDefaultRequestContext : true
     * HystrixCommand
     ** useRequestCache   : true
     ** useRequestLog     : true
     *
     * OUTCOME: RequestLog not set up properly in command, static access is null
     */
@Test
public void testCommandRequiresContextConcurrencyStrategyProvidesItContextLeftUninitialized() {
    HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(true);
    HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);
    //context is not set up
    HystrixRequestContext.setContextOnCurrentThread(null);
    HystrixCommand<Boolean> cmd = new TestCommand(true, true);
    //command execution not affected by missing context
    assertTrue(cmd.execute());
    printRequestLog();
    assertNull(HystrixRequestLog.getCurrentRequest());
    assertNull(HystrixRequestLog.getCurrentRequest(strategy));
    assertNull(cmd.currentRequestLog);
}
Also used : HystrixConcurrencyStrategy(com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy) Test(org.junit.Test)

Aggregations

HystrixConcurrencyStrategy (com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy)11 Test (org.junit.Test)11 HystrixRequestContext (com.netflix.hystrix.strategy.concurrency.HystrixRequestContext)6