Redis timeouts should not be converted to 0

DATAREDIS-176

Only convert timeouts in Redis commands to 0 sec if
the value to convert is 0, otherwise round up to 1
This commit is contained in:
Jennifer Hickey
2013-05-30 11:05:03 -07:00
parent db7b07788f
commit 7c8dafce67
5 changed files with 118 additions and 8 deletions

View File

@@ -0,0 +1,63 @@
/*
* Copyright 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.core;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Unit test of {@link TimeoutUtils}
*
* @author Jennifer Hickey
*
*/
public class TimeoutUtilsTests {
@Test
public void testConvertMoreThanOneSecond() {
assertEquals(2, TimeoutUtils.toSeconds(2010, TimeUnit.MILLISECONDS));
}
@Test
public void testConvertLessThanOneSecond() {
assertEquals(1, TimeoutUtils.toSeconds(999, TimeUnit.NANOSECONDS));
}
@Test
public void testConvertZero() {
assertEquals(0, TimeoutUtils.toSeconds(0, TimeUnit.MINUTES));
}
@Test
public void testConvertNegativeGreaterThanNegativeOne() {
// Ensure we convert this to 0 as before, though ideally we wouldn't accept negative values
assertEquals(0,TimeoutUtils.toSeconds(-123, TimeUnit.MILLISECONDS));
}
@Test
public void testConvertNegativeEqualNegativeOne() {
assertEquals(-1,TimeoutUtils.toSeconds(-1111, TimeUnit.MILLISECONDS));
}
@Test
public void testConvertNegativeLessThanNegativeOne() {
assertEquals(-2,TimeoutUtils.toSeconds(-2344, TimeUnit.MILLISECONDS));
}
}