+ improve parameterized redis collection even more
This commit is contained in:
@@ -21,6 +21,7 @@ import static org.junit.Assert.*;
|
||||
import static org.junit.matchers.JUnitMatchers.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -32,8 +33,11 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnection;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisCallback;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
|
||||
|
||||
@@ -81,6 +85,11 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> testParams() {
|
||||
return CollectionTestParams.testParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new instance of T
|
||||
* @return
|
||||
@@ -93,6 +102,14 @@ public abstract class AbstractRedisCollectionTests<T> {
|
||||
public void tearDown() throws Exception {
|
||||
// remove the collection entirely since clear() doesn't always work
|
||||
collection.getOperations().delete(collection.getKey());
|
||||
template.execute(new RedisCallback<Object>() {
|
||||
|
||||
@Override
|
||||
public Object doInRedis(RedisConnection connection) throws Exception {
|
||||
connection.flushDb();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010 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.keyvalue.redis.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.Person;
|
||||
import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public abstract class CollectionTestParams {
|
||||
|
||||
public static Collection<Object[]> testParams() {
|
||||
// create Jedis Factory
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<Person> personFactory = new PersonObjectFactory();
|
||||
|
||||
JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
|
||||
jedisConnFactory.setPooling(false);
|
||||
jedisConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, String> stringTemplate = new RedisTemplate<String, String>(jedisConnFactory);
|
||||
RedisTemplate<String, Person> personTemplate = new RedisTemplate<String, Person>(jedisConnFactory);
|
||||
|
||||
return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate } });
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.data.keyvalue.redis.Person;
|
||||
import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
@@ -40,23 +34,6 @@ public class RedisListTests extends AbstractRedisListTests<Object> {
|
||||
super(factory, template);
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> testParams() {
|
||||
// create Jedis Factory
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<Person> personFactory = new PersonObjectFactory();
|
||||
|
||||
JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
|
||||
jedisConnFactory.setPooling(false);
|
||||
jedisConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, String> stringTemplate = new RedisTemplate<String, String>(jedisConnFactory);
|
||||
RedisTemplate<String, Person> personTemplate = new RedisTemplate<String, Person>(jedisConnFactory);
|
||||
|
||||
return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate } });
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
RedisStore copyStore(RedisStore store) {
|
||||
return new DefaultRedisList(store.getKey().toString(), store.getOperations());
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010 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.keyvalue.redis.util;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
* Parameterized instance of Redis tests.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class RedisSetTests extends AbstractRedisSetTests<Object> {
|
||||
|
||||
/**
|
||||
* Constructs a new <code>RedisSetTests</code> instance.
|
||||
*
|
||||
* @param factory
|
||||
* @param template
|
||||
*/
|
||||
public RedisSetTests(ObjectFactory<Object> factory, RedisTemplate template) {
|
||||
super(factory, template);
|
||||
}
|
||||
|
||||
@Override
|
||||
RedisStore copyStore(RedisStore store) {
|
||||
return new DefaultRedisSet(store.getKey().toString(), store.getOperations());
|
||||
}
|
||||
|
||||
@Override
|
||||
AbstractRedisCollection<Object> createCollection() {
|
||||
String redisName = getClass().getName();
|
||||
return new DefaultRedisSet(redisName, template);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user