Add Redis 2.6 dump and restore commands to RedisTemplate
DATAREDIS-182
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.TestCondition;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.data.redis.SpinBarrier.waitFor;
|
||||
|
||||
/**
|
||||
*
|
||||
* Integration test of {@link RedisTemplate}
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class RedisTemplateTests {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
redisTemplate.getConnectionFactory().getConnection().flushDb();
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testDumpAndRestoreNoTtl() {
|
||||
redisTemplate.boundValueOps("testing").set("123");
|
||||
byte[] serializedValue = redisTemplate.dump("testing");
|
||||
assertNotNull(serializedValue);
|
||||
redisTemplate.delete("testing");
|
||||
redisTemplate.restore("testing", serializedValue, 0, TimeUnit.SECONDS);
|
||||
assertEquals("123", redisTemplate.boundValueOps("testing").get());
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testRestoreTtl() {
|
||||
redisTemplate.boundValueOps("testing").set("123");
|
||||
byte[] serializedValue = redisTemplate.dump("testing");
|
||||
assertNotNull(serializedValue);
|
||||
redisTemplate.delete("testing");
|
||||
redisTemplate.restore("testing", serializedValue, 200, TimeUnit.MILLISECONDS);
|
||||
assertEquals("123", redisTemplate.boundValueOps("testing").get());
|
||||
waitFor(new TestCondition() {
|
||||
public boolean passes() {
|
||||
return (!redisTemplate.hasKey("testing"));
|
||||
}
|
||||
}, 400);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,24 +40,54 @@ public class TimeoutUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertZero() {
|
||||
public void testConvertZeroSeconds() {
|
||||
assertEquals(0, TimeoutUtils.toSeconds(0, TimeUnit.MINUTES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeGreaterThanNegativeOne() {
|
||||
public void testConvertNegativeSecondsGreaterThanNegativeOne() {
|
||||
// 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() {
|
||||
public void testConvertNegativeSecondsEqualNegativeOne() {
|
||||
assertEquals(-1,TimeoutUtils.toSeconds(-1111, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeLessThanNegativeOne() {
|
||||
public void testConvertNegativeSecondsLessThanNegativeOne() {
|
||||
assertEquals(-2,TimeoutUtils.toSeconds(-2344, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertMoreThanOneMilli() {
|
||||
assertEquals(2, TimeoutUtils.toMillis(2010, TimeUnit.MICROSECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLessThanOneMilli() {
|
||||
assertEquals(1, TimeoutUtils.toMillis(999, TimeUnit.NANOSECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertZeroMillis() {
|
||||
assertEquals(0, TimeoutUtils.toMillis(0, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeMillisGreaterThanNegativeOne() {
|
||||
// Ensure we convert this to 0 as before, though ideally we wouldn't accept negative values
|
||||
assertEquals(0,TimeoutUtils.toMillis(-123, TimeUnit.MICROSECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeMillisEqualNegativeOne() {
|
||||
assertEquals(-1,TimeoutUtils.toMillis(-1111, TimeUnit.MICROSECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeMillisLessThanNegativeOne() {
|
||||
assertEquals(-2,TimeoutUtils.toMillis(-2344, TimeUnit.MICROSECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user