DATAREDIS-415 - Polishing.
Update license headers and fix minor code format issues. Original Pull Request: #168
This commit is contained in:
@@ -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<RedisClusterNode> resolvedRedisClusterNodes = new ArrayList<RedisClusterNode>();
|
||||
ClusterTopology topology = topologyProvider.getTopology();
|
||||
|
||||
|
||||
for (final RedisClusterNode node : nodes) {
|
||||
try {
|
||||
resolvedRedisClusterNodes.add(topology.lookup(node));
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<Object>() {
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user