Fix tests for Redis 2.6
This commit is contained in:
52
src/test/java/org/springframework/data/redis/Version.java
Normal file
52
src/test/java/org/springframework/data/redis/Version.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A {@link Comparable} software version
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
public class Version implements Comparable<Version> {
|
||||
Integer major;
|
||||
Integer minor;
|
||||
Integer patch;
|
||||
|
||||
public Version(int major, int minor, int patch) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
}
|
||||
|
||||
public int compareTo(Version o) {
|
||||
if (this.major != o.major) {
|
||||
return this.major.compareTo(o.major);
|
||||
}
|
||||
if (this.minor != o.minor) {
|
||||
return this.minor.compareTo(o.minor);
|
||||
}
|
||||
if (this.patch != o.patch) {
|
||||
return this.patch.compareTo(o.patch);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "" + major + "." + minor + "." + patch;
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,8 @@ 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;
|
||||
@@ -44,6 +46,7 @@ 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;
|
||||
@@ -82,10 +85,19 @@ 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
|
||||
@@ -1233,6 +1245,18 @@ 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);
|
||||
|
||||
@@ -15,12 +15,16 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection.jedis;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Integration test of {@link JedisConnection} transaction functionality.
|
||||
@@ -97,9 +101,15 @@ public class JedisConnectionTransactionIntegrationTests extends
|
||||
@Test
|
||||
public void exceptionExecuteNative() throws Exception {
|
||||
actual.add(connection.execute("ZadD", getClass() + "#foo\t0.90\titem"));
|
||||
// Syntax error on queued commands are swallowed and no results are
|
||||
// returned
|
||||
verifyResults(Arrays.asList(new Object[] {}), actual);
|
||||
try {
|
||||
// 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) {
|
||||
fail("Redis 2.6 should throw an Exception on exec if commands are invalid");
|
||||
}
|
||||
}catch(InvalidDataAccessApiUsageException e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void initConnection() {
|
||||
|
||||
@@ -22,12 +22,14 @@ import java.util.Arrays;
|
||||
|
||||
import org.jredis.protocol.BulkResponse;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.data.redis.connection.DefaultSortParameters;
|
||||
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -43,6 +45,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration
|
||||
public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
byteConnection = connectionFactory.getConnection();
|
||||
connection = new DefaultStringRedisConnection(byteConnection);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
try {
|
||||
@@ -85,6 +94,10 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
public void testKeys() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-171 JRedis StringIndexOutOfBoundsException in info() method in Redis 2.6")
|
||||
public void testInfo() throws Exception {
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testBitSet() throws Exception {
|
||||
super.testBitSet();
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package org.springframework.data.redis.connection.srp;
|
||||
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -26,7 +27,6 @@ import org.springframework.data.redis.connection.AbstractConnectionIntegrationTe
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import redis.client.RedisClientBase;
|
||||
import redis.reply.BulkReply;
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ public class SrpConnectionIntegrationTests extends AbstractConnectionIntegration
|
||||
|
||||
@Test
|
||||
public void testGetRangeSetRange() {
|
||||
assumeTrue(getRedisVersion() >= RedisClientBase.parseVersion("2.4.0"));
|
||||
assumeTrue(redisVersion.compareTo(parseVersion("2.4.0")) >= 0);
|
||||
super.testGetRangeSetRange();
|
||||
}
|
||||
|
||||
@@ -87,8 +87,4 @@ public class SrpConnectionIntegrationTests extends AbstractConnectionIntegration
|
||||
BulkReply reply = (BulkReply) connection.execute("GET", "foo");
|
||||
assertEquals("bar", stringSerializer.deserialize(reply.data()));
|
||||
}
|
||||
|
||||
private int getRedisVersion() {
|
||||
return RedisClientBase.parseVersion((String) connection.info().get("redis_version"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ 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 java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -34,10 +35,17 @@ import redis.client.RedisClientBase;
|
||||
public class SrpConnectionPipelineTxIntegrationTests extends
|
||||
SrpConnectionTransactionIntegrationTests {
|
||||
|
||||
@Test(expected = RedisPipelineException.class)
|
||||
@Test
|
||||
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.execute("ZadD", getClass() + "#foo\t0.90\titem");
|
||||
getResults();
|
||||
try {
|
||||
getResults();
|
||||
fail("Execute failures should result in a RedisPipelineException");
|
||||
} catch (RedisPipelineException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user