@Override protected Boolean run() { assertEquals("OuterCommand", Hystrix.getCurrentThreadExecutingCommand().name()); System.out.println("Outer Thread : " + Thread.currentThread().getName()); //should be a single execution on this thread assertEquals(1, Hystrix.getCommandCount()); if (Hystrix.getCurrentThreadExecutingCommand() == null) { throw new RuntimeException("BEFORE expected it to run inside a thread"); } HystrixCommand<Boolean> command2 = new HystrixCommand<Boolean>(Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey("TestUtil")) .andCommandKey(HystrixCommandKey.Factory.asKey("InnerCommand"))) { @Override protected Boolean run() { assertEquals("InnerCommand", Hystrix.getCurrentThreadExecutingCommand().name()); System.out.println("Inner Thread : " + Thread.currentThread().getName()); //should be a single execution on this thread, since outer/inner are on different threads assertEquals(1, Hystrix.getCommandCount()); return Hystrix.getCurrentThreadExecutingCommand() != null; } }; if (Hystrix.getCurrentThreadExecutingCommand() == null) { throw new RuntimeException("AFTER expected it to run inside a thread"); } return command2.execute(); }
@Override protected Boolean run() { assertEquals("OuterSemaphoreCommand", Hystrix.getCurrentThreadExecutingCommand().name()); System.out.println("Outer Semaphore Thread : " + Thread.currentThread().getName()); //should be a single execution on the caller thread assertEquals(1, Hystrix.getCommandCount()); if (Hystrix.getCurrentThreadExecutingCommand() == null) { throw new RuntimeException("BEFORE expected it to run inside a semaphore"); } HystrixCommand<Boolean> command2 = new HystrixCommand<Boolean>(Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey("TestUtil")) .andCommandKey(HystrixCommandKey.Factory.asKey("InnerCommand"))) { @Override protected Boolean run() { assertEquals("InnerCommand", Hystrix.getCurrentThreadExecutingCommand().name()); System.out.println("Inner Thread : " + Thread.currentThread().getName()); //should be a single execution on the thread isolating the second command assertEquals(1, Hystrix.getCommandCount()); return Hystrix.getCurrentThreadExecutingCommand() != null; } }; if (Hystrix.getCurrentThreadExecutingCommand() == null) { throw new RuntimeException("AFTER expected it to run inside a semaphore"); } return command2.execute(); }