diff --git a/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java b/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java index 2bf922775..961da321f 100644 --- a/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java +++ b/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -156,6 +156,7 @@ public class ClusterCommandExecutor implements DisposableBean { /** * Lookup node from the topology. + * * @param node * @return * @throws IllegalArgumentException in case the node could not be resolved to a topology-known node @@ -163,7 +164,7 @@ public class ClusterCommandExecutor implements DisposableBean { private RedisClusterNode lookupNode(RedisClusterNode node) { try { return topologyProvider.getTopology().lookup(node); - }catch (ClusterStateFailureException e){ + } catch (ClusterStateFailureException e) { throw new IllegalArgumentException(String.format("Node %s is unknown to cluster", node), e); } } @@ -192,10 +193,9 @@ public class ClusterCommandExecutor implements DisposableBean { Assert.notNull(callback, "Callback must not be null!"); Assert.notNull(nodes, "Nodes must not be null!"); - List resolvedRedisClusterNodes = new ArrayList(); ClusterTopology topology = topologyProvider.getTopology(); - + for (final RedisClusterNode node : nodes) { try { resolvedRedisClusterNodes.add(topology.lookup(node)); diff --git a/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java b/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java index bd3b3d971..1bcba13f0 100644 --- a/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java +++ b/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerTest.java b/src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerTests.java similarity index 81% rename from src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerTest.java rename to src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerTests.java index 4cb3ebc0a..62592c34a 100644 --- a/src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerTest.java +++ b/src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerTests.java @@ -16,20 +16,17 @@ package org.springframework.data.redis.listener; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doAnswer; +import static org.hamcrest.core.Is.*; +import static org.junit.Assert.*; +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.*; import java.util.concurrent.Executor; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import org.springframework.core.task.SyncTaskExecutor; import org.springframework.data.redis.SettingsUtils; @@ -38,25 +35,27 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; /** * @author Mark Paluch + * @author Christoph Strobl */ -@RunWith(MockitoJUnitRunner.class) -public class RedisMessageListenerContainerTest { - - private JedisConnectionFactory connectionFactory; - private RedisMessageListenerContainer container; +public class RedisMessageListenerContainerTests { private final Object handler = new Object() { + @SuppressWarnings("unused") - public void handleMessage(Object message) { - } + public void handleMessage(Object message) {} }; private final MessageListenerAdapter adapter = new MessageListenerAdapter(handler); - @Mock private Executor executor; + private JedisConnectionFactory connectionFactory; + private RedisMessageListenerContainer container; + + private Executor executorMock; @Before - public void before() throws Exception { + public void setUp() throws Exception { + + executorMock = mock(Executor.class); connectionFactory = new JedisConnectionFactory(); connectionFactory.setPort(SettingsUtils.getPort()); @@ -69,10 +68,17 @@ public class RedisMessageListenerContainerTest { container.setConnectionFactory(connectionFactory); container.setBeanName("container"); container.setTaskExecutor(new SyncTaskExecutor()); - container.setSubscriptionExecutor(executor); + container.setSubscriptionExecutor(executorMock); container.afterPropertiesSet(); } + @After + public void tearDown() throws Exception { + + container.destroy(); + connectionFactory.destroy(); + } + /* * @see DATAREDIS-415 */ @@ -82,13 +88,15 @@ public class RedisMessageListenerContainerTest { final Thread main = Thread.currentThread(); // interrupt thread once Executor.execute is called - doAnswer(new Answer() { + doAnswer(new Answer() { + @Override public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { + main.interrupt(); return null; } - }).when(executor).execute(any(Runnable.class)); + }).when(executorMock).execute(any(Runnable.class)); container.addMessageListener(adapter, new ChannelTopic("a")); container.start(); @@ -99,10 +107,4 @@ public class RedisMessageListenerContainerTest { assertThat(container.isRunning(), is(false)); } - @After - public void tearDown() throws Exception { - - container.destroy(); - connectionFactory.destroy(); - } }