Move common test functionality to helper classes
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
|
||||
/**
|
||||
* Utilities for examining the Redis version
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
public abstract class RedisVersionUtils {
|
||||
|
||||
private static final Pattern VERSION_MATCHER = Pattern
|
||||
.compile("([0-9]+)\\.([0-9]+)(\\.([0-9]+))?");
|
||||
|
||||
public static Version getRedisVersion(RedisConnection connection) {
|
||||
return parseVersion((String) connection.info().get("redis_version"));
|
||||
}
|
||||
|
||||
public static boolean atLeast(String version, RedisConnection connection) {
|
||||
return getRedisVersion(connection).compareTo(parseVersion(version)) >= 0;
|
||||
}
|
||||
|
||||
public static boolean atMost(String version, RedisConnection connection) {
|
||||
return getRedisVersion(connection).compareTo(parseVersion(version)) <= 0;
|
||||
}
|
||||
|
||||
private static Version parseVersion(String version) {
|
||||
Matcher matcher = VERSION_MATCHER.matcher(version);
|
||||
if (matcher.matches()) {
|
||||
String major = matcher.group(1);
|
||||
String minor = matcher.group(2);
|
||||
String patch = matcher.group(4);
|
||||
return new Version(Integer.parseInt(major), Integer.parseInt(minor),
|
||||
Integer.parseInt(patch));
|
||||
}
|
||||
throw new IllegalArgumentException("Specified version cannot be parsed");
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,6 @@ import java.util.UUID;
|
||||
import java.util.concurrent.BlockingDeque;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -46,14 +44,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.Address;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.Version;
|
||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
@@ -85,19 +80,10 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
|
||||
protected RedisConnection byteConnection;
|
||||
|
||||
protected static Version redisVersion;
|
||||
|
||||
private static final Pattern VERSION_MATCHER = Pattern
|
||||
.compile("([0-9]+)\\.([0-9]+)(\\.([0-9]+))?");
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
byteConnection = connectionFactory.getConnection();
|
||||
connection = new DefaultStringRedisConnection(byteConnection);
|
||||
if (redisVersion == null) {
|
||||
redisVersion = parseVersion((String) connection.info().get(
|
||||
"redis_version"));
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -310,7 +296,7 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
// messages may be received if unsubscribing now.
|
||||
// Connection.close in teardown
|
||||
// will take care of unsubscribing.
|
||||
if (!(isAsync())) {
|
||||
if (!(ConnectionUtils.isAsync(connectionFactory))) {
|
||||
connection.getSubscription().unsubscribe();
|
||||
}
|
||||
}
|
||||
@@ -359,7 +345,7 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
// messages may be received if unsubscribing now.
|
||||
// Connection.close in teardown
|
||||
// will take care of unsubscribing.
|
||||
if (!(isAsync())) {
|
||||
if (!(ConnectionUtils.isAsync(connectionFactory))) {
|
||||
connection.getSubscription().pUnsubscribe(expectedPattern.getBytes());
|
||||
}
|
||||
}
|
||||
@@ -1244,21 +1230,4 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
|
||||
protected Version parseVersion(String version) {
|
||||
Matcher matcher = VERSION_MATCHER.matcher(version);
|
||||
if (matcher.matches()) {
|
||||
String major = matcher.group(1);
|
||||
String minor = matcher.group(2);
|
||||
String patch = matcher.group(4);
|
||||
return new Version(Integer.parseInt(major),
|
||||
Integer.parseInt(minor), Integer.parseInt(patch));
|
||||
}
|
||||
throw new IllegalArgumentException("Specified version cannot be parsed");
|
||||
}
|
||||
|
||||
private boolean isAsync() {
|
||||
return (connectionFactory instanceof LettuceConnectionFactory)
|
||||
|| (connectionFactory instanceof SrpConnectionFactory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.connection;
|
||||
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.rjc.RjcConnectionFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
|
||||
/**
|
||||
* Utilities for examining a {@link RedisConnection}
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
public abstract class ConnectionUtils {
|
||||
|
||||
public static boolean isAsync(RedisConnectionFactory connectionFactory) {
|
||||
return (connectionFactory instanceof LettuceConnectionFactory)
|
||||
|| (connectionFactory instanceof SrpConnectionFactory);
|
||||
}
|
||||
|
||||
public static boolean isRjc(RedisConnectionFactory connectionFactory) {
|
||||
return connectionFactory instanceof RjcConnectionFactory;
|
||||
}
|
||||
|
||||
public static boolean isSrp(RedisConnectionFactory connectionFactory) {
|
||||
return connectionFactory instanceof SrpConnectionFactory;
|
||||
}
|
||||
|
||||
public static boolean isJredis(RedisConnectionFactory connectionFactory) {
|
||||
return connectionFactory instanceof JredisConnectionFactory;
|
||||
}
|
||||
|
||||
public static boolean isLettuce(RedisConnectionFactory connectionFactory) {
|
||||
return connectionFactory instanceof LettuceConnectionFactory;
|
||||
}
|
||||
|
||||
public static boolean isJedis(RedisConnectionFactory connectionFactory) {
|
||||
return connectionFactory instanceof JedisConnectionFactory;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.RedisVersionUtils;
|
||||
|
||||
/**
|
||||
* Integration test of {@link JedisConnection} transaction functionality.
|
||||
@@ -105,7 +105,7 @@ public class JedisConnectionTransactionIntegrationTests extends
|
||||
// Syntax error on queued commands are swallowed and no results are
|
||||
// returned
|
||||
verifyResults(Arrays.asList(new Object[] {}), actual);
|
||||
if(redisVersion.compareTo(parseVersion("2.6.5")) >= 0) {
|
||||
if(RedisVersionUtils.atLeast("2.6.5", connection)) {
|
||||
fail("Redis 2.6 should throw an Exception on exec if commands are invalid");
|
||||
}
|
||||
}catch(InvalidDataAccessApiUsageException e) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.RedisVersionUtils;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -77,7 +78,7 @@ public class SrpConnectionIntegrationTests extends AbstractConnectionIntegration
|
||||
|
||||
@Test
|
||||
public void testGetRangeSetRange() {
|
||||
assumeTrue(redisVersion.compareTo(parseVersion("2.4.0")) >= 0);
|
||||
assumeTrue(RedisVersionUtils.atLeast("2.4.0", connection));
|
||||
super.testGetRangeSetRange();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.Set;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.RedisVersionUtils;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultStringTuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
@@ -39,7 +40,6 @@ import org.springframework.data.redis.serializer.SerializationUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import redis.client.RedisClientBase;
|
||||
import redis.reply.BulkReply;
|
||||
import redis.reply.Reply;
|
||||
|
||||
@@ -136,15 +136,11 @@ public class SrpConnectionPipelineIntegrationTests extends
|
||||
|
||||
@Test
|
||||
public void testGetRangeSetRange() {
|
||||
assumeTrue(getRedisVersion() >= RedisClientBase.parseVersion("2.4.0"));
|
||||
super.testGetRangeSetRange();
|
||||
}
|
||||
|
||||
protected int getRedisVersion() {
|
||||
connection.closePipeline();
|
||||
int version = RedisClientBase.parseVersion((String)connection.info().get("redis_version"));
|
||||
boolean getRangeSupported = RedisVersionUtils.atLeast("2.4.0", connection);
|
||||
connection.openPipeline();
|
||||
return version;
|
||||
assumeTrue(getRangeSupported);
|
||||
super.testGetRangeSetRange();
|
||||
}
|
||||
|
||||
protected Object convertResult(Object result) {
|
||||
|
||||
@@ -17,15 +17,16 @@ package org.springframework.data.redis.connection.srp;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.RedisVersionUtils;
|
||||
import org.springframework.data.redis.connection.RedisPipelineException;
|
||||
|
||||
import redis.client.RedisClientBase;
|
||||
|
||||
/**
|
||||
* Integration test of {@link SrpConnection} transactions within a pipeline
|
||||
*
|
||||
@@ -39,7 +40,11 @@ public class SrpConnectionPipelineTxIntegrationTests extends
|
||||
public void exceptionExecuteNative() throws Exception {
|
||||
// DATAREDIS-172 SRP ClassCastException when exec() returns an
|
||||
// ErrorReply in Redis 2.6
|
||||
assumeTrue(redisVersion.compareTo(parseVersion("2.6.5")) < 0);
|
||||
connection.exec();
|
||||
connection.closePipeline();
|
||||
boolean execErrorSupported = RedisVersionUtils.atMost("2.6.4", connection);
|
||||
initConnection();
|
||||
assumeTrue(execErrorSupported);
|
||||
connection.execute("ZadD", getClass() + "#foo\t0.90\titem");
|
||||
try {
|
||||
getResults();
|
||||
@@ -77,6 +82,20 @@ public class SrpConnectionPipelineTxIntegrationTests extends
|
||||
assertEquals("baz", new String((byte[]) results.get(3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRangeSetRange() {
|
||||
connection.exec();
|
||||
connection.closePipeline();
|
||||
boolean getRangeSupported = RedisVersionUtils.atLeast("2.4.0", connection);
|
||||
initConnection();
|
||||
assumeTrue(getRangeSupported);
|
||||
connection.set("rangekey", "supercalifrag");
|
||||
actual.add(connection.getRange("rangekey", 0l, 2l));
|
||||
connection.setRange("rangekey", "ck", 2);
|
||||
actual.add(connection.get("rangekey"));
|
||||
verifyResults(Arrays.asList(new Object[] { "sup", 13l, "suckrcalifrag" }), actual);
|
||||
}
|
||||
|
||||
protected void initConnection() {
|
||||
connection.openPipeline();
|
||||
connection.multi();
|
||||
@@ -86,13 +105,4 @@ public class SrpConnectionPipelineTxIntegrationTests extends
|
||||
assertNull(connection.exec());
|
||||
return connection.closePipeline();
|
||||
}
|
||||
|
||||
protected int getRedisVersion() {
|
||||
connection.exec();
|
||||
connection.closePipeline();
|
||||
int version = RedisClientBase.parseVersion((String) connection.info()
|
||||
.get("redis_version"));
|
||||
initConnection();
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection.srp;
|
||||
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
|
||||
import redis.client.RedisClientBase;
|
||||
import org.springframework.data.redis.RedisVersionUtils;
|
||||
|
||||
/**
|
||||
* Integration test of {@link SrpConnection} functionality within a transaction
|
||||
@@ -85,6 +87,19 @@ public class SrpConnectionTransactionIntegrationTests extends
|
||||
getResults();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRangeSetRange() {
|
||||
connection.exec();
|
||||
boolean getRangeSupported = RedisVersionUtils.atLeast("2.4.0", connection);
|
||||
connection.multi();
|
||||
assumeTrue(getRangeSupported);
|
||||
connection.set("rangekey", "supercalifrag");
|
||||
actual.add(connection.getRange("rangekey", 0l, 2l));
|
||||
connection.setRange("rangekey", "ck", 2);
|
||||
actual.add(connection.get("rangekey"));
|
||||
verifyResults(Arrays.asList(new Object[] { "sup", 13l, "suckrcalifrag" }), actual);
|
||||
}
|
||||
|
||||
protected void initConnection() {
|
||||
connection.multi();
|
||||
}
|
||||
@@ -92,12 +107,4 @@ public class SrpConnectionTransactionIntegrationTests extends
|
||||
protected List<Object> getResults() {
|
||||
return connection.exec();
|
||||
}
|
||||
|
||||
protected int getRedisVersion() {
|
||||
connection.exec();
|
||||
int version = RedisClientBase.parseVersion((String) connection.info()
|
||||
.get("redis_version"));
|
||||
connection.multi();
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.connection.ConnectionUtils;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.rjc.RjcConnectionFactory;
|
||||
import org.springframework.data.redis.support.collections.CollectionTestParams;
|
||||
import org.springframework.data.redis.support.collections.ObjectFactory;
|
||||
|
||||
@@ -72,7 +72,7 @@ public class TemplateTest {
|
||||
@Test
|
||||
public void testIncrement() throws Exception {
|
||||
// disable in case of Rjc
|
||||
if (isRjc()) {
|
||||
if (ConnectionUtils.isRjc(template.getConnectionFactory())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -86,10 +86,6 @@ public class TemplateTest {
|
||||
assertEquals(-10, Integer.valueOf(valueOps.get(key)).intValue());
|
||||
}
|
||||
|
||||
private boolean isRjc() {
|
||||
return (template.getConnectionFactory() instanceof RjcConnectionFactory);
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void testGetNonExistingKey() throws Exception {
|
||||
List<Object> res = (List<Object>) template.execute(new RedisCallback<List<Object>>() {
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.connection.ConnectionUtils;
|
||||
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
|
||||
import org.springframework.data.redis.core.BoundKeyOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -99,7 +100,7 @@ public class BoundKeyOperationsTest {
|
||||
|
||||
@Test
|
||||
public void testPersist() throws Exception {
|
||||
assumeTrue(!isJredis());
|
||||
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
|
||||
keyOps.persist();
|
||||
assertEquals(Long.valueOf(-1), keyOps.getExpire());
|
||||
if (keyOps.expire(10, TimeUnit.SECONDS)) {
|
||||
@@ -108,8 +109,4 @@ public class BoundKeyOperationsTest {
|
||||
keyOps.persist();
|
||||
assertEquals(-1, keyOps.getExpire().longValue());
|
||||
}
|
||||
|
||||
private boolean isJredis() {
|
||||
return template.getConnectionFactory() instanceof JredisConnectionFactory;
|
||||
}
|
||||
}
|
||||
@@ -31,12 +31,9 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.connection.ConnectionUtils;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.rjc.RjcConnectionFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
@@ -77,7 +74,7 @@ public class RedisAtomicTests {
|
||||
@Test
|
||||
public void testIntCheckAndSet() throws Exception {
|
||||
// Txs not supported in Jredis
|
||||
assumeTrue(!isJredis());
|
||||
assumeTrue(!ConnectionUtils.isJredis(factory));
|
||||
intCounter.set(0);
|
||||
assertFalse(intCounter.compareAndSet(1, 10));
|
||||
assertTrue(intCounter.compareAndSet(0, 10));
|
||||
@@ -87,7 +84,7 @@ public class RedisAtomicTests {
|
||||
@Test
|
||||
public void testLongCheckAndSet() throws Exception {
|
||||
// Txs not supported in Jredis
|
||||
assumeTrue(!isJredis());
|
||||
assumeTrue(!ConnectionUtils.isJredis(factory));
|
||||
longCounter.set(0);
|
||||
assertFalse(longCounter.compareAndSet(1, 10));
|
||||
assertTrue(longCounter.compareAndSet(0, 10));
|
||||
@@ -97,7 +94,7 @@ public class RedisAtomicTests {
|
||||
@Test
|
||||
public void testLongIncrement() throws Exception {
|
||||
// DATAREDIS-121 incr/decr broken in RJC
|
||||
assumeTrue(!isRjc());
|
||||
assumeTrue(!ConnectionUtils.isRjc(factory));
|
||||
longCounter.set(0);
|
||||
assertEquals(1, longCounter.incrementAndGet());
|
||||
}
|
||||
@@ -105,7 +102,7 @@ public class RedisAtomicTests {
|
||||
@Test
|
||||
public void testIntIncrement() throws Exception {
|
||||
// DATAREDIS-121 incr/decr broken in RJC
|
||||
assumeTrue(!isRjc());
|
||||
assumeTrue(!ConnectionUtils.isRjc(factory));
|
||||
intCounter.set(0);
|
||||
assertEquals(1, intCounter.incrementAndGet());
|
||||
}
|
||||
@@ -113,7 +110,7 @@ public class RedisAtomicTests {
|
||||
@Test
|
||||
public void testLongCustomIncrement() throws Exception {
|
||||
// DATAREDIS-121 incr/decr broken in RJC
|
||||
assumeTrue(!isRjc());
|
||||
assumeTrue(!ConnectionUtils.isRjc(factory));
|
||||
longCounter.set(0);
|
||||
long delta = 5;
|
||||
assertEquals(delta, longCounter.addAndGet(delta));
|
||||
@@ -122,7 +119,7 @@ public class RedisAtomicTests {
|
||||
@Test
|
||||
public void testIntCustomIncrement() throws Exception {
|
||||
// DATAREDIS-121 incr/decr broken in RJC
|
||||
assumeTrue(!isRjc());
|
||||
assumeTrue(!ConnectionUtils.isRjc(factory));
|
||||
intCounter.set(0);
|
||||
int delta = 5;
|
||||
assertEquals(delta, intCounter.addAndGet(delta));
|
||||
@@ -131,7 +128,7 @@ public class RedisAtomicTests {
|
||||
@Test
|
||||
public void testLongDecrement() throws Exception {
|
||||
// DATAREDIS-121 incr/decr broken in RJC
|
||||
assumeTrue(!isRjc());
|
||||
assumeTrue(!ConnectionUtils.isRjc(factory));
|
||||
longCounter.set(1);
|
||||
assertEquals(0, longCounter.decrementAndGet());
|
||||
}
|
||||
@@ -139,7 +136,7 @@ public class RedisAtomicTests {
|
||||
@Test
|
||||
public void testIntDecrement() throws Exception {
|
||||
// DATAREDIS-121 incr/decr broken in RJC
|
||||
assumeTrue(!isRjc());
|
||||
assumeTrue(!ConnectionUtils.isRjc(factory));
|
||||
intCounter.set(1);
|
||||
assertEquals(0, intCounter.decrementAndGet());
|
||||
}
|
||||
@@ -156,7 +153,7 @@ public class RedisAtomicTests {
|
||||
public void testCompareSet() throws Exception {
|
||||
// Txs not supported in Jredis, Lettuce checkAndSet not working DATAREDIS-122,
|
||||
// SRP checkAndSet not working DATAREDIS-123
|
||||
assumeTrue(!isJredis() && !isLettuce() && !isSrp());
|
||||
assumeTrue(!ConnectionUtils.isJredis(factory) && !ConnectionUtils.isLettuce(factory) && !ConnectionUtils.isSrp(factory));
|
||||
final AtomicBoolean alreadySet = new AtomicBoolean(false);
|
||||
final int NUM = 50;
|
||||
final String KEY = getClass().getSimpleName() + ":atomic:counter";
|
||||
@@ -185,20 +182,4 @@ public class RedisAtomicTests {
|
||||
|
||||
assertFalse("counter already modified", failed.get());
|
||||
}
|
||||
|
||||
private boolean isRjc() {
|
||||
return factory instanceof RjcConnectionFactory;
|
||||
}
|
||||
|
||||
private boolean isSrp() {
|
||||
return factory instanceof SrpConnectionFactory;
|
||||
}
|
||||
|
||||
private boolean isJredis() {
|
||||
return factory instanceof JredisConnectionFactory;
|
||||
}
|
||||
|
||||
private boolean isLettuce() {
|
||||
return factory instanceof LettuceConnectionFactory;
|
||||
}
|
||||
}
|
||||
@@ -306,8 +306,4 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
public void testGetKey() throws Exception {
|
||||
assertNotNull(collection.getKey());
|
||||
}
|
||||
|
||||
protected boolean isJredis() {
|
||||
return template.getConnectionFactory().getClass().getSimpleName().startsWith("Jredis");
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,9 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
@@ -46,6 +46,7 @@ import org.junit.runners.Parameterized;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.connection.ConnectionUtils;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
@@ -194,7 +195,7 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
|
||||
@Test
|
||||
public void testIncrement() {
|
||||
assumeTrue(!isJredis());
|
||||
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
|
||||
K k1 = getKey();
|
||||
V v1 = getValue();
|
||||
|
||||
@@ -252,7 +253,7 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
|
||||
@Test
|
||||
public void testPutAll() {
|
||||
assumeTrue(!isJredis());
|
||||
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
|
||||
Map<K, V> m = new LinkedHashMap<K, V>();
|
||||
K k1 = getKey();
|
||||
K k2 = getKey();
|
||||
@@ -331,7 +332,7 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
|
||||
@Test
|
||||
public void testEntrySet() {
|
||||
assumeTrue(!isJredis());
|
||||
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
|
||||
Set<Entry<K, V>> entries = map.entrySet();
|
||||
assertTrue(entries.isEmpty());
|
||||
|
||||
@@ -421,8 +422,4 @@ public abstract class AbstractRedisMapTests<K, V> {
|
||||
assertEquals(v2, map.get(k1));
|
||||
|
||||
}
|
||||
|
||||
private boolean isJredis() {
|
||||
return template.getConnectionFactory().getClass().getSimpleName().startsWith("Jredis");
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.junit.matchers.JUnitMatchers.*;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItem;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItems;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
@@ -26,10 +31,9 @@ import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.connection.ConnectionUtils;
|
||||
import org.springframework.data.redis.core.BoundZSetOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.support.collections.DefaultRedisZSet;
|
||||
import org.springframework.data.redis.support.collections.RedisZSet;
|
||||
|
||||
/**
|
||||
* Integration test for Redis ZSet.
|
||||
@@ -190,7 +194,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
|
||||
@Test
|
||||
public void testIntersectAndStore() {
|
||||
assumeTrue(!isJredis());
|
||||
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
|
||||
RedisZSet<T> interSet1 = createZSetFor("test:zset:inter1");
|
||||
RedisZSet<T> interSet2 = createZSetFor("test:zset:inter");
|
||||
|
||||
@@ -312,7 +316,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
|
||||
@Test
|
||||
public void testUnionAndStore() {
|
||||
assumeTrue(!isJredis());
|
||||
assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()));
|
||||
RedisZSet<T> unionSet1 = createZSetFor("test:zset:union1");
|
||||
RedisZSet<T> unionSet2 = createZSetFor("test:zset:union2");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user