DATAREDIS-277 - Add support for 'SLAVEOF'.
'SLAVEOF' and 'SLAVEOF NO ONE' are available via 'RedisConnection' and 'RedisOperations' for 'jedis', 'jredis', 'lettuce' and 'srp'. Original Pull Request: #57
This commit is contained in:
committed by
Thomas Darimont
parent
2b280e57e8
commit
d35375ec74
@@ -115,6 +115,8 @@ public class JedisConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
/**
|
||||
* <<<<<<< HEAD
|
||||
*
|
||||
* @see DATAREDIS-267
|
||||
*/
|
||||
@Test
|
||||
@@ -134,6 +136,33 @@ public class JedisConnectionUnitTestSuite {
|
||||
verifyNativeConnectionInvocation().clientGetname();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void slaveOfShouldThrowExectpionWhenCalledForNullHost() {
|
||||
connection.slaveOf(null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test
|
||||
public void slaveOfShouldBeSentCorrectly() {
|
||||
|
||||
connection.slaveOf("127.0.0.1", 1001);
|
||||
verifyNativeConnectionInvocation().slaveof(eq("127.0.0.1"), eq(1001));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test
|
||||
public void slaveOfNoOneShouldBeSentCorrectly() {
|
||||
|
||||
connection.slaveOfNoOne();
|
||||
verifyNativeConnectionInvocation().slaveofNoOne();
|
||||
}
|
||||
}
|
||||
|
||||
public static class JedisConnectionPipelineUnitTests extends JedisConnectionUnitTests {
|
||||
@@ -179,6 +208,23 @@ public class JedisConnectionUnitTestSuite {
|
||||
super.getClientNameShouldSendRequestCorrectly();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Override
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void slaveOfShouldBeSentCorrectly() {
|
||||
super.slaveOfShouldBeSentCorrectly();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void slaveOfNoOneShouldBeSentCorrectly() {
|
||||
super.slaveOfNoOneShouldBeSentCorrectly();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -83,6 +83,8 @@ public class LettuceConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
/**
|
||||
* <<<<<<< HEAD
|
||||
*
|
||||
* @see DATAREDIS-267
|
||||
*/
|
||||
@Test
|
||||
@@ -103,6 +105,33 @@ public class LettuceConnectionUnitTestSuite {
|
||||
verifyNativeConnectionInvocation().clientGetname();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void slaveOfShouldThrowExectpionWhenCalledForNullHost() {
|
||||
connection.slaveOf(null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test
|
||||
public void slaveOfShouldBeSentCorrectly() {
|
||||
|
||||
connection.slaveOf("127.0.0.1", 1001);
|
||||
verifyNativeConnectionInvocation().slaveof(eq("127.0.0.1"), eq(1001));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test
|
||||
public void slaveOfNoOneShouldBeSentCorrectly() {
|
||||
|
||||
connection.slaveOfNoOne();
|
||||
verifyNativeConnectionInvocation().slaveofNoOne();
|
||||
}
|
||||
}
|
||||
|
||||
public static class LettucePipelineConnectionUnitTests extends LettuceConnectionUnitTests {
|
||||
|
||||
@@ -79,6 +79,8 @@ public class SrpConnectionUnitTestSuite {
|
||||
}
|
||||
|
||||
/**
|
||||
* <<<<<<< HEAD
|
||||
*
|
||||
* @see DATAREDIS-267
|
||||
*/
|
||||
@Test
|
||||
@@ -99,6 +101,33 @@ public class SrpConnectionUnitTestSuite {
|
||||
verifyNativeConnectionInvocation().client_getname();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void slaveOfShouldThrowExectpionWhenCalledForNullHost() {
|
||||
connection.slaveOf(null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test
|
||||
public void slaveOfShouldBeSentCorrectly() {
|
||||
|
||||
connection.slaveOf("127.0.0.1", 1001);
|
||||
verifyNativeConnectionInvocation().slaveof(eq("127.0.0.1"), eq(1001));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test
|
||||
public void slaveOfNoOneShouldBeSentCorrectly() {
|
||||
|
||||
connection.slaveOfNoOne();
|
||||
verifyNativeConnectionInvocation().slaveof(eq("NO"), eq("ONE"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class SrpConnectionPiplineUnitTests extends AbstractConnectionUnitTestBase<Pipeline> {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RedisTemplateUnitTests {
|
||||
|
||||
private RedisTemplate<String, String> template;
|
||||
private @Mock RedisConnectionFactory connectionFactoryMock;
|
||||
private @Mock RedisConnection redisConnectionMock;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
template = new RedisTemplate<String, String>();
|
||||
template.setConnectionFactory(connectionFactoryMock);
|
||||
when(connectionFactoryMock.getConnection()).thenReturn(redisConnectionMock);
|
||||
|
||||
template.afterPropertiesSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test
|
||||
public void slaveOfIsDelegatedToConnectionCorrectly() {
|
||||
|
||||
template.slaveOf("127.0.0.1", 1001);
|
||||
verify(redisConnectionMock, times(1)).slaveOf(eq("127.0.0.1"), eq(1001));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-277
|
||||
*/
|
||||
@Test
|
||||
public void slaveOfNoOneIsDelegatedToConnectionCorrectly() {
|
||||
|
||||
template.slaveOfNoOne();
|
||||
verify(redisConnectionMock, times(1)).slaveOfNoOne();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user