Package com.netflix.hystrix.contrib.javanica.test.spring.domain

Examples of com.netflix.hystrix.contrib.javanica.test.spring.domain.User


        }
    }

    private class FailoverService {
        public User getDefUser() {
            return new User("def", "def");
        }
View Full Code Here


    @Test
    public void testCollapserSync() throws ExecutionException, InterruptedException {
        HystrixRequestContext context = HystrixRequestContext.initializeContext();
        try {
            User u1 = userService.getUserSync("1", "name: ");
            User u2 = userService.getUserSync("2", "name: ");
            User u3 = userService.getUserSync("3", "name: ");
            User u4 = userService.getUserSync("4", "name: ");

            assertEquals("name: 1", u1.getName());
            assertEquals("name: 2", u2.getName());
            assertEquals("name: 3", u3.getName());
            assertEquals("name: 4", u4.getName());

            com.netflix.hystrix.HystrixExecutableInfo<?> command = HystrixRequestLog.getCurrentRequest()
                    .getAllExecutedCommands().iterator().next();
            assertEquals("GetUserCommand", command.getCommandKey().name());
            // confirm that it was a COLLAPSED command execution
View Full Code Here

    @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));
View Full Code Here

        public Future<User> getUserAsync(final String id, final String name) {
            emulateNotFound(id);
            return new AsyncResult<User>() {
                @Override
                public User invoke() {
                    return new User(id, name + id); // it should be network call
                }
            };
        }
View Full Code Here

        @HystrixCommand(commandKey = "GetUserCommand", fallbackMethod = "fallback")
        @HystrixCollapser(fallbackEnabled = true, collapserProperties = {@HystrixProperty(name = "timerDelayInMilliseconds", value = "200")})
        public User getUserSync(String id, String name) {
            emulateNotFound(id);
            return new User(id, name + id); // it should be network call
        }
View Full Code Here

    @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());
View Full Code Here

        @HystrixCommand(commandKey = "GetUserCommand", threadPoolKey = "CommandTestAsync")
        public Future<User> getUserAsync(final String id, final String name) {
            return new AsyncResult<User>() {
                @Override
                public User invoke() {
                    return new User(id, name + id); // it should be network call
                }
            };
        }
View Full Code Here

            };
        }

        @HystrixCommand(groupKey = "UserGroup")
        public User getUserSync(String id, String name) {
            return new User(id, name + id); // it should be network call
        }
View Full Code Here

    @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

    }

    public static class UserService {
        @HystrixCommand(cacheKeyMethod = "getUserIdCacheKey")
        public User getUser(String id, String name) {
            return new User(id, name + id); // it should be network call
        }
View Full Code Here

TOP

Related Classes of com.netflix.hystrix.contrib.javanica.test.spring.domain.User

Copyright © 2018 www.massapicom. 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.