DATAREDIS-472 - Add guards to JedisConnection before casting long to int.

This commit is contained in:
Christoph Strobl
2016-03-04 11:35:15 +01:00
parent b630744564
commit 5a85ac47a3
2 changed files with 81 additions and 22 deletions

View File

@@ -20,9 +20,6 @@ import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,7 +31,6 @@ import org.springframework.data.redis.connection.AbstractConnectionUnitTestBase;
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
import org.springframework.data.redis.connection.jedis.JedisConnectionUnitTestSuite.JedisConnectionPipelineUnitTests;
import org.springframework.data.redis.connection.jedis.JedisConnectionUnitTestSuite.JedisConnectionUnitTests;
import org.springframework.data.redis.core.TimeoutUtils;
import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;
@@ -97,24 +93,6 @@ public class JedisConnectionUnitTestSuite {
assertThat(captor.getValue(), equalTo("return redis.call('SHUTDOWN','SAVE')".getBytes()));
}
/**
* @see DATAREDIS-286
*/
@Test
public void pExpireHavingIntOverflowShouldUseRedisServerTimeAsReferenceForPExpireAt() {
long msec = Long.valueOf((long) Integer.MAX_VALUE + 1);
long expected = msec + TimeoutUtils.toMillis(1, TimeUnit.SECONDS);
/* redis time as list containing [0] = seconds, [1] = microseconds
* @see http://redis.io/commands/time
*/
when(jedisSpy.time()).thenReturn(Arrays.asList("1", "0"));
connection.pExpire("foo".getBytes(), msec);
verifyNativeConnectionInvocation().pexpireAt(any(byte[].class), eq(expected));
}
/**
* @see DATAREDIS-267
*/
@@ -171,6 +149,62 @@ public class JedisConnectionUnitTestSuite {
connection.getSentinelConnection();
}
/**
* @see DATAREDIS-472
*/
@Test(expected = IllegalArgumentException.class)
public void restoreShouldThrowExceptionWhenTtlInMillisExceedsIntegerRange() {
connection.restore("foo".getBytes(), new Long(Integer.MAX_VALUE) + 1L, "bar".getBytes());
}
/**
* @see DATAREDIS-472
*/
@Test(expected = IllegalArgumentException.class)
public void setExShouldThrowExceptionWhenTimeExceedsIntegerRange() {
connection.setEx("foo".getBytes(), new Long(Integer.MAX_VALUE) + 1L, "bar".getBytes());
}
/**
* @see DATAREDIS-472
*/
@Test(expected = IllegalArgumentException.class)
public void getRangeShouldThrowExceptionWhenStartExceedsIntegerRange() {
connection.getRange("foo".getBytes(), new Long(Integer.MAX_VALUE) + 1L, Integer.MAX_VALUE);
}
/**
* @see DATAREDIS-472
*/
@Test(expected = IllegalArgumentException.class)
public void getRangeShouldThrowExceptionWhenEndExceedsIntegerRange() {
connection.getRange("foo".getBytes(), Integer.MAX_VALUE, new Long(Integer.MAX_VALUE) + 1L);
}
/**
* @see DATAREDIS-472
*/
@Test(expected = IllegalArgumentException.class)
public void sRandMemberShouldThrowExceptionWhenCountExceedsIntegerRange() {
connection.sRandMember("foo".getBytes(), new Long(Integer.MAX_VALUE) + 1L);
}
/**
* @see DATAREDIS-472
*/
@Test(expected = IllegalArgumentException.class)
public void zRangeByScoreShouldThrowExceptionWhenOffsetExceedsIntegerRange() {
connection.zRangeByScore("foo".getBytes(), "foo", "bar", new Long(Integer.MAX_VALUE) + 1L, Integer.MAX_VALUE);
}
/**
* @see DATAREDIS-472
*/
@Test(expected = IllegalArgumentException.class)
public void zRangeByScoreShouldThrowExceptionWhenCountExceedsIntegerRange() {
connection.zRangeByScore("foo".getBytes(), "foo", "bar", Integer.MAX_VALUE, new Long(Integer.MAX_VALUE) + 1L);
}
}
public static class JedisConnectionPipelineUnitTests extends JedisConnectionUnitTests {