Examples of HystrixRequestContext


Examples of com.netflix.hystrix.strategy.concurrency.HystrixRequestContext

        }
    }

    @Test
    public void testCollapserSyncWithFallbackCommand() throws ExecutionException, InterruptedException {
        HystrixRequestContext context = HystrixRequestContext.initializeContext();
        try {
            User u1 = userService.getUserSync("5", "name: ");
            assertEquals("name: 5", u1.getName());
            com.netflix.hystrix.HystrixExecutableInfo<?> command = HystrixRequestLog.getCurrentRequest()
                    .getAllExecutedCommands().iterator().next();
            assertEquals("GetUserCommand", command.getCommandKey().name());
            // confirm that it was a COLLAPSED command execution
            assertTrue(command.getExecutionEvents().contains(HystrixEventType.COLLAPSED));
        } finally {
            context.shutdown();
        }
    }
View Full Code Here

Examples of com.netflix.hystrix.strategy.concurrency.HystrixRequestContext

    @Autowired
    private UserService userService;

    @Test
    public void testGetUserAsync() throws ExecutionException, InterruptedException {
        HystrixRequestContext context = HystrixRequestContext.initializeContext();
        try {
            Future<User> f1 = userService.getUserAsync("1", "name: ");

            assertEquals("name: 1", f1.get().getName());
            assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
            com.netflix.hystrix.HystrixExecutableInfo<?> command = HystrixRequestLog.getCurrentRequest()
                    .getAllExecutedCommands().iterator().next();
            // assert the command key name is the we're expecting
            assertEquals("GetUserCommand", command.getCommandKey().name());
            // assert the command group key name is the we're expecting
            assertEquals("UserService", command.getCommandGroup().name());
            // assert the command thread pool key name is the we're expecting
            assertEquals("CommandTestAsync", command.getThreadPoolKey().name());
            // it was successful
            assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
        } finally {
            context.shutdown();
        }
    }
View Full Code Here

Examples of com.netflix.hystrix.strategy.concurrency.HystrixRequestContext

        }
    }

    @Test
    public void testGetUserSync() {
        HystrixRequestContext context = HystrixRequestContext.initializeContext();
        try {
            User u1 = userService.getUserSync("1", "name: ");
            assertEquals("name: 1", u1.getName());
            assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
            com.netflix.hystrix.HystrixExecutableInfo<?> command = HystrixRequestLog.getCurrentRequest()
                    .getAllExecutedCommands().iterator().next();
            assertEquals("getUserSync", command.getCommandKey().name());
            assertEquals("UserGroup", command.getCommandGroup().name());
            assertEquals("UserGroup", command.getThreadPoolKey().name());
            assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
        } finally {
            context.shutdown();
        }
    }
View Full Code Here

Examples of com.netflix.hystrix.strategy.concurrency.HystrixRequestContext

    @Autowired
    private UserService userService;

    @Test
    public void testGetUserCache() {
        HystrixRequestContext context = HystrixRequestContext.initializeContext();
        try {

            User user = userService.getUser("1", "name");
            HystrixExecutableInfo getUserByIdCommand = getLastExecutedCommand();
            assertEquals("1", user.getId());

            // this is the first time we've executed this command with
            // the value of "1" so it should not be from cache
            assertFalse(getUserByIdCommand.isResponseFromCache());

            user = userService.getUser("1", "name");
            assertEquals("1", user.getId());
            getUserByIdCommand = getLastExecutedCommand();
            // this is the second time we've executed this command with
            // the same value so it should return from cache
            assertTrue(getUserByIdCommand.isResponseFromCache());
        } finally {
            context.shutdown();
        }

        // start a new request context
        context = HystrixRequestContext.initializeContext();
        try {
            User user = userService.getUser("1", "name");
            HystrixExecutableInfo getUserByIdCommand = getLastExecutedCommand();
            assertEquals("1", user.getId());
            // this is a new request context so this
            // should not come from cache
            assertFalse(getUserByIdCommand.isResponseFromCache());
        } finally {
            context.shutdown();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.