DATAREDIS-241 - Add a Jackson2 based RedisSerializer.
Introduced Jackson2JsonRedisSerializer and added optional dependency for Jackson2 core/databind (fasterxml) library. Added additional parameterised test cases. Needed to increase the max active connections limit for the connection pools used in RedisMapTests.
This commit is contained in:
committed by
Christoph Strobl
parent
e1b421f942
commit
c6d2d7f9c9
@@ -55,6 +55,8 @@ dependencies {
|
||||
// Mappers
|
||||
compile("org.codehaus.jackson:jackson-mapper-asl:$jacksonVersion", optional)
|
||||
compile("commons-beanutils:commons-beanutils-core:1.8.3", optional)
|
||||
compile("com.fasterxml.jackson.core:jackson-core:$fasterXmlJacksonVersion", optional)
|
||||
compile("com.fasterxml.jackson.core:jackson-databind:$fasterXmlJacksonDatabindVersion", optional)
|
||||
|
||||
// Pool
|
||||
compile("commons-pool:commons-pool:1.5.6", optional)
|
||||
|
||||
@@ -394,8 +394,8 @@
|
||||
(package <literal>org.springframework.data.redis.serializer</literal>) which as the name implies, takes care of the serialization process. Multiple implementations are
|
||||
available out of the box, two of which have been already mentioned before in this documentation: the <literal>StringRedisSerializer</literal> and
|
||||
the <literal>JdkSerializationRedisSerializer</literal>. However one can use <classname>OxmSerializer</classname> for Object/XML mapping through Spring 3
|
||||
<ulink url="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/oxm.html">OXM</ulink> support or <classname>JacksonJsonRedisSerializer</classname> for storing
|
||||
data in <ulink url="http://en.wikipedia.org/wiki/JSON">JSON</ulink> format. Do note that the storage format is not limited only to values - it can be used for keys, values or hashes
|
||||
<ulink url="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/oxm.html">OXM</ulink> support or either <classname>JacksonJsonRedisSerializer</classname> or
|
||||
<classname>Jackson2JsonRedisSerializer</classname> for storing data in <ulink url="http://en.wikipedia.org/wiki/JSON">JSON</ulink> format. Do note that the storage format is not limited only to values - it can be used for keys, values or hashes
|
||||
without any restrictions.</para>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -9,3 +9,5 @@ srpVersion=0.7
|
||||
jacksonVersion=1.8.8
|
||||
lettuceVersion=2.3.3
|
||||
mockitoVersion=1.9.5
|
||||
fasterXmlJacksonVersion=2.2.0
|
||||
fasterXmlJacksonDatabindVersion=2.2.2
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2011-2014 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.serializer;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ser.SerializerFactory;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
|
||||
/**
|
||||
* {@link RedisSerializer} that can read and write JSON using <a
|
||||
* href="https://github.com/FasterXML/jackson-core">Jackson's</a> and <a
|
||||
* href="https://github.com/FasterXML/jackson-databind">Jackson Databind<a> {@link ObjectMapper}.
|
||||
* <p>
|
||||
* This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances.
|
||||
* <b>Note:</b>Null objects are serialized as empty arrays and vice versa.
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
* @since 1.2
|
||||
*/
|
||||
public class Jackson2JsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||
|
||||
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
|
||||
private final JavaType javaType;
|
||||
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public Jackson2JsonRedisSerializer(Class<T> type) {
|
||||
this.javaType = TypeFactory.defaultInstance().constructType(type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T deserialize(byte[] bytes) throws SerializationException {
|
||||
|
||||
if (SerializationUtils.isEmpty(bytes)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (T) this.objectMapper.readValue(bytes, 0, bytes.length, javaType);
|
||||
} catch (Exception ex) {
|
||||
throw new SerializationException("Could not read JSON: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] serialize(Object t) throws SerializationException {
|
||||
|
||||
if (t == null) {
|
||||
return SerializationUtils.EMPTY_ARRAY;
|
||||
}
|
||||
try {
|
||||
return this.objectMapper.writeValueAsBytes(t);
|
||||
} catch (Exception ex) {
|
||||
throw new SerializationException("Could not write JSON: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@code ObjectMapper} for this view. If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper}
|
||||
* is used.
|
||||
* <p>
|
||||
* Setting a custom-configured {@code ObjectMapper} is one way to take further control of the JSON serialization
|
||||
* process. For example, an extended {@link SerializerFactory} can be configured that provides custom serializers for
|
||||
* specific types. The other option for refining the serialization process is to use Jackson's provided annotations on
|
||||
* the types to be serialized, in which case a custom-configured ObjectMapper is unnecessary.
|
||||
*/
|
||||
public void setObjectMapper(ObjectMapper objectMapper) {
|
||||
|
||||
Assert.notNull(objectMapper, "'objectMapper' must not be null");
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Jackson {@link JavaType} for the specific class.
|
||||
* <p>
|
||||
* Default implementation returns {@link TypeFactory#constructType(java.lang.reflect.Type)}, but this can be
|
||||
* overridden in subclasses, to allow for custom generic collection handling. For instance:
|
||||
*
|
||||
* <pre class="code">
|
||||
* protected JavaType getJavaType(Class<?> clazz) {
|
||||
* if (List.class.isAssignableFrom(clazz)) {
|
||||
* return TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, MyBean.class);
|
||||
* } else {
|
||||
* return super.getJavaType(clazz);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @param clazz the class to return the java type for
|
||||
* @return the java type
|
||||
*/
|
||||
protected JavaType getJavaType(Class<?> clazz) {
|
||||
return TypeFactory.defaultInstance().constructType(clazz);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013 - 2014 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.
|
||||
@@ -28,6 +28,7 @@ import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
@@ -35,13 +36,17 @@ import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
|
||||
/**
|
||||
* Parameters for testing implementations of {@link AbstractOperations}
|
||||
*
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
abstract public class AbstractOperationsTestParams {
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-241
|
||||
*/
|
||||
public static Collection<Object[]> testParams() {
|
||||
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<Long> longFactory = new LongObjectFactory();
|
||||
ObjectFactory<Double> doubleFactory = new DoubleObjectFactory();
|
||||
@@ -56,31 +61,28 @@ abstract public class AbstractOperationsTestParams {
|
||||
throw new RuntimeException("Cannot init XStream", ex);
|
||||
}
|
||||
|
||||
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
|
||||
JacksonJsonRedisSerializer<Person> jsonSerializer = new JacksonJsonRedisSerializer<Person>(Person.class);
|
||||
|
||||
SrpConnectionFactory srConnFactory = new SrpConnectionFactory();
|
||||
srConnFactory.setPort(SettingsUtils.getPort());
|
||||
srConnFactory.setHostName(SettingsUtils.getHost());
|
||||
srConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String,String> stringTemplate = new StringRedisTemplate();
|
||||
RedisTemplate<String, String> stringTemplate = new StringRedisTemplate();
|
||||
stringTemplate.setConnectionFactory(srConnFactory);
|
||||
stringTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String,Long> longTemplate = new RedisTemplate<String,Long>();
|
||||
RedisTemplate<String, Long> longTemplate = new RedisTemplate<String, Long>();
|
||||
longTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
longTemplate.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
|
||||
longTemplate.setConnectionFactory(srConnFactory);
|
||||
longTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String,Double> doubleTemplate = new RedisTemplate<String,Double>();
|
||||
RedisTemplate<String, Double> doubleTemplate = new RedisTemplate<String, Double>();
|
||||
doubleTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
doubleTemplate.setValueSerializer(new GenericToStringSerializer<Double>(Double.class));
|
||||
doubleTemplate.setConnectionFactory(srConnFactory);
|
||||
doubleTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[],byte[]> rawTemplate = new RedisTemplate<byte[],byte[]>();
|
||||
RedisTemplate<byte[], byte[]> rawTemplate = new RedisTemplate<byte[], byte[]>();
|
||||
rawTemplate.setEnableDefaultSerializer(false);
|
||||
rawTemplate.setConnectionFactory(srConnFactory);
|
||||
rawTemplate.afterPropertiesSet();
|
||||
@@ -89,6 +91,7 @@ abstract public class AbstractOperationsTestParams {
|
||||
personTemplate.setConnectionFactory(srConnFactory);
|
||||
personTemplate.afterPropertiesSet();
|
||||
|
||||
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
|
||||
RedisTemplate<String, String> xstreamStringTemplate = new RedisTemplate<String, String>();
|
||||
xstreamStringTemplate.setConnectionFactory(srConnFactory);
|
||||
xstreamStringTemplate.setDefaultSerializer(serializer);
|
||||
@@ -99,15 +102,28 @@ abstract public class AbstractOperationsTestParams {
|
||||
xstreamPersonTemplate.setValueSerializer(serializer);
|
||||
xstreamPersonTemplate.afterPropertiesSet();
|
||||
|
||||
JacksonJsonRedisSerializer<Person> jacksonJsonSerializer = new JacksonJsonRedisSerializer<Person>(Person.class);
|
||||
RedisTemplate<String, Person> jsonPersonTemplate = new RedisTemplate<String, Person>();
|
||||
jsonPersonTemplate.setConnectionFactory(srConnFactory);
|
||||
jsonPersonTemplate.setValueSerializer(jsonSerializer);
|
||||
jsonPersonTemplate.setValueSerializer(jacksonJsonSerializer);
|
||||
jsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
return Arrays.asList(new Object[][] { { stringTemplate, stringFactory, stringFactory },
|
||||
{ longTemplate, stringFactory, longFactory }, { doubleTemplate, stringFactory, doubleFactory },
|
||||
{ rawTemplate, rawFactory, rawFactory}, { personTemplate, stringFactory, personFactory },
|
||||
{ xstreamStringTemplate, stringFactory, stringFactory }, { xstreamPersonTemplate, stringFactory, personFactory },
|
||||
{ jsonPersonTemplate, stringFactory, personFactory }});
|
||||
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplate.setConnectionFactory(srConnFactory);
|
||||
jackson2JsonPersonTemplate.setValueSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
return Arrays.asList(new Object[][] { //
|
||||
{ stringTemplate, stringFactory, stringFactory }, //
|
||||
{ longTemplate, stringFactory, longFactory }, //
|
||||
{ doubleTemplate, stringFactory, doubleFactory }, //
|
||||
{ rawTemplate, rawFactory, rawFactory }, //
|
||||
{ personTemplate, stringFactory, personFactory }, //
|
||||
{ xstreamStringTemplate, stringFactory, stringFactory }, //
|
||||
{ xstreamPersonTemplate, stringFactory, personFactory }, //
|
||||
{ jsonPersonTemplate, stringFactory, personFactory }, //
|
||||
{ jackson2JsonPersonTemplate, stringFactory, personFactory } //
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2014 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.serializer;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.hamcrest.core.Is;
|
||||
import org.hamcrest.core.IsNull;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.PersonObjectFactory;
|
||||
|
||||
/**
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class Jackson2JsonRedisSerializerTests {
|
||||
|
||||
private Jackson2JsonRedisSerializer<Person> serializer;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.serializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-241
|
||||
*/
|
||||
@Test
|
||||
public void testJackson2JsonSerializer() throws Exception {
|
||||
|
||||
Person person = new PersonObjectFactory().instance();
|
||||
assertEquals(person, serializer.deserialize(serializer.serialize(person)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-241
|
||||
*/
|
||||
@Test
|
||||
public void testJackson2JsonSerializerShouldReturnEmptyByteArrayWhenSerializingNull() {
|
||||
assertThat(serializer.serialize(null), Is.is(new byte[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DTATREDIS-241
|
||||
*/
|
||||
@Test
|
||||
public void testJackson2JsonSerializerShouldReturnNullWhenDerserializingEmtyByteArray() {
|
||||
assertThat(serializer.deserialize(new byte[0]), IsNull.nullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DTATREDIS-241
|
||||
*/
|
||||
@Test(expected=SerializationException.class)
|
||||
public void testJackson2JsonSerilizerShouldThrowExceptionWhenDeserializingInvalidByteArray() {
|
||||
|
||||
Person person = new PersonObjectFactory().instance();
|
||||
byte [] serializedValue = serializer.serialize(person);
|
||||
Arrays.sort(serializedValue); //corrupt serialization result
|
||||
|
||||
serializer.deserialize(serializedValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DTATREDIS-241
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testJackson2JsonSerilizerThrowsExceptionWhenSettingNullObjectMapper() {
|
||||
serializer.setObjectMapper(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,19 +25,16 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.Address;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
|
||||
|
||||
/**
|
||||
* @author Jennifer Hickey
|
||||
*/
|
||||
public class SimpleRedisSerializerTests {
|
||||
|
||||
private static class A implements Serializable {
|
||||
private Integer value = Integer.valueOf(30);
|
||||
|
||||
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
@@ -45,7 +42,6 @@ public class SimpleRedisSerializerTests {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
@@ -57,8 +53,7 @@ public class SimpleRedisSerializerTests {
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
}
|
||||
else if (!value.equals(other.value))
|
||||
} else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -68,7 +63,6 @@ public class SimpleRedisSerializerTests {
|
||||
private String name = getClass().getName();
|
||||
private A a = new A();
|
||||
|
||||
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
@@ -77,7 +71,6 @@ public class SimpleRedisSerializerTests {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
@@ -89,14 +82,12 @@ public class SimpleRedisSerializerTests {
|
||||
if (a == null) {
|
||||
if (other.a != null)
|
||||
return false;
|
||||
}
|
||||
else if (!a.equals(other.a))
|
||||
} else if (!a.equals(other.a))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
}
|
||||
else if (!name.equals(other.name))
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -164,4 +155,5 @@ public class SimpleRedisSerializerTests {
|
||||
assertEquals(p1, serializer.deserialize(serializer.serialize(p1)));
|
||||
assertEquals(p1, serializer.deserialize(serializer.serialize(p1)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2014 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.
|
||||
@@ -31,6 +31,7 @@ import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactor
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
@@ -38,6 +39,7 @@ import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public abstract class CollectionTestParams {
|
||||
|
||||
@@ -51,6 +53,7 @@ public abstract class CollectionTestParams {
|
||||
}
|
||||
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
|
||||
JacksonJsonRedisSerializer<Person> jsonSerializer = new JacksonJsonRedisSerializer<Person>(Person.class);
|
||||
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
|
||||
StringRedisSerializer stringSerializer = new StringRedisSerializer();
|
||||
|
||||
// create Jedis Factory
|
||||
@@ -87,15 +90,21 @@ public abstract class CollectionTestParams {
|
||||
jsonPersonTemplate.setValueSerializer(jsonSerializer);
|
||||
jsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[],byte[]> rawTemplate = new RedisTemplate<byte[],byte[]>();
|
||||
// jackson2
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplate.setConnectionFactory(jedisConnFactory);
|
||||
jackson2JsonPersonTemplate.setValueSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[], byte[]> rawTemplate = new RedisTemplate<byte[], byte[]>();
|
||||
rawTemplate.setConnectionFactory(jedisConnFactory);
|
||||
rawTemplate.setEnableDefaultSerializer(false);
|
||||
rawTemplate.setKeySerializer(stringSerializer);
|
||||
rawTemplate.afterPropertiesSet();
|
||||
|
||||
// jredis
|
||||
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(
|
||||
SettingsUtils.getHost(), SettingsUtils.getPort()));
|
||||
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
|
||||
SettingsUtils.getPort()));
|
||||
jredisConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, String> stringTemplateJR = new StringRedisTemplate(jredisConnFactory);
|
||||
@@ -118,7 +127,12 @@ public abstract class CollectionTestParams {
|
||||
jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
|
||||
jsonPersonTemplateJR.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[],byte[]> rawTemplateJR = new RedisTemplate<byte[],byte[]>();
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplateJR = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplateJR.setValueSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
|
||||
jackson2JsonPersonTemplateJR.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[], byte[]> rawTemplateJR = new RedisTemplate<byte[], byte[]>();
|
||||
rawTemplateJR.setConnectionFactory(jredisConnFactory);
|
||||
rawTemplateJR.setEnableDefaultSerializer(false);
|
||||
rawTemplateJR.setKeySerializer(stringSerializer);
|
||||
@@ -150,7 +164,12 @@ public abstract class CollectionTestParams {
|
||||
jsonPersonTemplateSRP.setConnectionFactory(srConnFactory);
|
||||
jsonPersonTemplateSRP.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[],byte[]> rawTemplateSRP = new RedisTemplate<byte[],byte[]>();
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplateSRP = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplateSRP.setValueSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateSRP.setConnectionFactory(srConnFactory);
|
||||
jackson2JsonPersonTemplateSRP.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[], byte[]> rawTemplateSRP = new RedisTemplate<byte[], byte[]>();
|
||||
rawTemplateSRP.setConnectionFactory(srConnFactory);
|
||||
rawTemplateSRP.setEnableDefaultSerializer(false);
|
||||
rawTemplateSRP.setKeySerializer(stringSerializer);
|
||||
@@ -182,30 +201,44 @@ public abstract class CollectionTestParams {
|
||||
jsonPersonTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
jsonPersonTemplateLtc.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[],byte[]> rawTemplateLtc = new RedisTemplate<byte[],byte[]>();
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplateLtc = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplateLtc.setValueSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
jackson2JsonPersonTemplateLtc.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<byte[], byte[]> rawTemplateLtc = new RedisTemplate<byte[], byte[]>();
|
||||
rawTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
rawTemplateLtc.setEnableDefaultSerializer(false);
|
||||
rawTemplateLtc.setKeySerializer(stringSerializer);
|
||||
rawTemplateLtc.afterPropertiesSet();
|
||||
|
||||
return Arrays.asList(new Object[][] { { stringFactory, stringTemplate },
|
||||
return Arrays.asList(new Object[][] {
|
||||
{ stringFactory, stringTemplate },
|
||||
{ personFactory, personTemplate },
|
||||
{ stringFactory, xstreamStringTemplate }, { personFactory, xstreamPersonTemplate },
|
||||
{ personFactory, jsonPersonTemplate }, {rawFactory, rawTemplate},
|
||||
{ stringFactory, xstreamStringTemplate },
|
||||
{ personFactory, xstreamPersonTemplate },
|
||||
{ personFactory, jsonPersonTemplate },
|
||||
{ personFactory, jackson2JsonPersonTemplate },
|
||||
{ rawFactory, rawTemplate },
|
||||
// Jredis
|
||||
{ stringFactory, stringTemplateJR },
|
||||
{ personFactory, personTemplateJR },
|
||||
{ stringFactory, xstreamStringTemplateJR },
|
||||
{ personFactory, xstreamPersonTemplateJR },
|
||||
{ personFactory, jsonPersonTemplateJR }, {rawFactory, rawTemplateJR},
|
||||
{ personFactory, jsonPersonTemplateJR },
|
||||
{ personFactory, jackson2JsonPersonTemplateJR },
|
||||
{ rawFactory, rawTemplateJR },
|
||||
// srp
|
||||
{ stringFactory, stringTemplateSRP },{ personFactory, personTemplateSRP },
|
||||
{ stringFactory, xstreamStringTemplateSRP }, { personFactory, xstreamPersonTemplateSRP },
|
||||
{ personFactory, jsonPersonTemplateSRP }, {rawFactory, rawTemplateSRP},
|
||||
{ stringFactory, stringTemplateSRP }, { personFactory, personTemplateSRP },
|
||||
{ stringFactory, xstreamStringTemplateSRP },
|
||||
{ personFactory, xstreamPersonTemplateSRP },
|
||||
{ personFactory, jsonPersonTemplateSRP },
|
||||
{ personFactory, jackson2JsonPersonTemplateSRP },
|
||||
{ rawFactory, rawTemplateSRP },
|
||||
// lettuce
|
||||
{ stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
|
||||
{ stringFactory, xstreamStringTemplateLtc }, { personFactory, xstreamPersonTemplateLtc },
|
||||
{ personFactory, jsonPersonTemplateLtc }, {rawFactory, rawTemplateLtc}
|
||||
});
|
||||
{ personFactory, jsonPersonTemplateLtc }, { personFactory, jackson2JsonPersonTemplateLtc },
|
||||
{ rawFactory, rawTemplateLtc } });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2014 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.
|
||||
@@ -27,13 +27,15 @@ import org.springframework.data.redis.PersonObjectFactory;
|
||||
import org.springframework.data.redis.RawObjectFactory;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.PoolConfig;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisPool;
|
||||
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisPool;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
@@ -44,6 +46,7 @@ import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Jennifer Hickey
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
|
||||
@@ -52,16 +55,19 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
super(keyFactory, valueFactory, template);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
RedisMap<Object, Object> createMap() {
|
||||
String redisName = getClass().getSimpleName();
|
||||
return new DefaultRedisMap<Object, Object>(redisName, template);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-241
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Parameters
|
||||
public static Collection<Object[]> testParams() {
|
||||
|
||||
// XStream serializer
|
||||
XStreamMarshaller xstream = new XStreamMarshaller();
|
||||
try {
|
||||
@@ -72,8 +78,14 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
|
||||
JacksonJsonRedisSerializer<Person> jsonSerializer = new JacksonJsonRedisSerializer<Person>(Person.class);
|
||||
JacksonJsonRedisSerializer<String> jsonStringSerializer = new JacksonJsonRedisSerializer<String>(String.class);
|
||||
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
|
||||
Jackson2JsonRedisSerializer<String> jackson2JsonStringSerializer = new Jackson2JsonRedisSerializer<String>(
|
||||
String.class);
|
||||
StringRedisSerializer stringSerializer = new StringRedisSerializer();
|
||||
|
||||
PoolConfig defaultPoolConfig = new PoolConfig();
|
||||
defaultPoolConfig.setMaxActive(1000);
|
||||
|
||||
// create Jedis Factory
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
ObjectFactory<Person> personFactory = new PersonObjectFactory();
|
||||
@@ -82,6 +94,7 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
ObjectFactory<byte[]> rawFactory = new RawObjectFactory();
|
||||
|
||||
JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
|
||||
jedisConnFactory.getPoolConfig().setMaxActive(defaultPoolConfig.maxActive);
|
||||
jedisConnFactory.setUsePool(true);
|
||||
jedisConnFactory.setPort(SettingsUtils.getPort());
|
||||
jedisConnFactory.setHostName(SettingsUtils.getHost());
|
||||
@@ -103,6 +116,13 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
jsonPersonTemplate.setHashValueSerializer(jsonStringSerializer);
|
||||
jsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplate.setConnectionFactory(jedisConnFactory);
|
||||
jackson2JsonPersonTemplate.setDefaultSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplate.setHashKeySerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplate.setHashValueSerializer(jackson2JsonStringSerializer);
|
||||
jackson2JsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, byte[]> rawTemplate = new RedisTemplate<String, byte[]>();
|
||||
rawTemplate.setEnableDefaultSerializer(false);
|
||||
rawTemplate.setConnectionFactory(jedisConnFactory);
|
||||
@@ -110,8 +130,8 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
rawTemplate.afterPropertiesSet();
|
||||
|
||||
// JRedis
|
||||
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(
|
||||
SettingsUtils.getHost(), SettingsUtils.getPort()));
|
||||
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
|
||||
SettingsUtils.getPort(), defaultPoolConfig));
|
||||
jredisConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate genericTemplateJR = new RedisTemplate();
|
||||
@@ -130,6 +150,13 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer);
|
||||
jsonPersonTemplateJR.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplateJR = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
|
||||
jackson2JsonPersonTemplateJR.setDefaultSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateJR.setHashKeySerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateJR.setHashValueSerializer(jackson2JsonStringSerializer);
|
||||
jackson2JsonPersonTemplateJR.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, byte[]> rawTemplateJR = new RedisTemplate<String, byte[]>();
|
||||
rawTemplateJR.setEnableDefaultSerializer(false);
|
||||
rawTemplateJR.setConnectionFactory(jredisConnFactory);
|
||||
@@ -138,8 +165,8 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
|
||||
// Lettuce
|
||||
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
|
||||
lettuceConnFactory.setPort(SettingsUtils.getPort());
|
||||
lettuceConnFactory.setHostName(SettingsUtils.getHost());
|
||||
lettuceConnFactory.setPort(SettingsUtils.getPort());
|
||||
lettuceConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate genericTemplateLettuce = new RedisTemplate();
|
||||
@@ -158,6 +185,13 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
jsonPersonTemplateLettuce.setHashValueSerializer(jsonStringSerializer);
|
||||
jsonPersonTemplateLettuce.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplateLettuce = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplateLettuce.setConnectionFactory(lettuceConnFactory);
|
||||
jackson2JsonPersonTemplateLettuce.setDefaultSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateLettuce.setHashKeySerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateLettuce.setHashValueSerializer(jackson2JsonStringSerializer);
|
||||
jackson2JsonPersonTemplateLettuce.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, String> stringTemplateLtc = new StringRedisTemplate();
|
||||
stringTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
stringTemplateLtc.afterPropertiesSet();
|
||||
@@ -190,6 +224,13 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
jsonPersonTemplateSrp.setHashValueSerializer(jsonStringSerializer);
|
||||
jsonPersonTemplateSrp.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplateSrp = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplateSrp.setConnectionFactory(srpConnFactory);
|
||||
jackson2JsonPersonTemplateSrp.setDefaultSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateSrp.setHashKeySerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateSrp.setHashValueSerializer(jackson2JsonStringSerializer);
|
||||
jackson2JsonPersonTemplateSrp.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, String> stringTemplateSrp = new StringRedisTemplate();
|
||||
stringTemplateSrp.setConnectionFactory(srpConnFactory);
|
||||
stringTemplateSrp.afterPropertiesSet();
|
||||
@@ -200,39 +241,28 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
rawTemplateSrp.setKeySerializer(stringSerializer);
|
||||
rawTemplateSrp.afterPropertiesSet();
|
||||
|
||||
|
||||
return Arrays.asList(new Object[][] {
|
||||
{ stringFactory, stringFactory, genericTemplate },
|
||||
{ personFactory, personFactory, genericTemplate },
|
||||
{ stringFactory, personFactory, genericTemplate },
|
||||
{ personFactory, stringFactory, genericTemplate },
|
||||
{ personFactory, stringFactory, xstreamGenericTemplate },
|
||||
return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate },
|
||||
{ personFactory, personFactory, genericTemplate }, { stringFactory, personFactory, genericTemplate },
|
||||
{ personFactory, stringFactory, genericTemplate }, { personFactory, stringFactory, xstreamGenericTemplate },
|
||||
{ personFactory, stringFactory, jsonPersonTemplate },
|
||||
{ rawFactory, rawFactory, rawTemplate},
|
||||
{ stringFactory, stringFactory, genericTemplateJR },
|
||||
{ personFactory, personFactory, genericTemplateJR },
|
||||
{ stringFactory, personFactory, genericTemplateJR },
|
||||
{ personFactory, stringFactory, genericTemplateJR },
|
||||
{ personFactory, stringFactory, xGenericTemplateJR },
|
||||
{ personFactory, stringFactory, jsonPersonTemplateJR },
|
||||
{ rawFactory, rawFactory, rawTemplateJR},
|
||||
{ personFactory, stringFactory, jackson2JsonPersonTemplate }, { rawFactory, rawFactory, rawTemplate },
|
||||
{ stringFactory, stringFactory, genericTemplateJR }, { personFactory, personFactory, genericTemplateJR },
|
||||
{ stringFactory, personFactory, genericTemplateJR }, { personFactory, stringFactory, genericTemplateJR },
|
||||
{ personFactory, stringFactory, xGenericTemplateJR }, { personFactory, stringFactory, jsonPersonTemplateJR },
|
||||
{ personFactory, stringFactory, jackson2JsonPersonTemplateJR }, { rawFactory, rawFactory, rawTemplateJR },
|
||||
{ stringFactory, stringFactory, genericTemplateLettuce },
|
||||
{ personFactory, personFactory, genericTemplateLettuce },
|
||||
{ stringFactory, personFactory, genericTemplateLettuce },
|
||||
{ personFactory, stringFactory, genericTemplateLettuce },
|
||||
{ personFactory, stringFactory, xGenericTemplateLettuce },
|
||||
{ personFactory, stringFactory, jsonPersonTemplateLettuce },
|
||||
{ stringFactory, doubleFactory, stringTemplateLtc},
|
||||
{ stringFactory, longFactory, stringTemplateLtc},
|
||||
{ rawFactory, rawFactory, rawTemplateLtc},
|
||||
{ stringFactory, stringFactory, genericTemplateSrp },
|
||||
{ personFactory, personFactory, genericTemplateSrp },
|
||||
{ stringFactory, personFactory, genericTemplateSrp },
|
||||
{ personFactory, stringFactory, genericTemplateSrp },
|
||||
{ personFactory, stringFactory, xGenericTemplateSrp },
|
||||
{ stringFactory, doubleFactory, stringTemplateSrp},
|
||||
{ stringFactory, longFactory, stringTemplateSrp},
|
||||
{ personFactory, stringFactory, jackson2JsonPersonTemplateLettuce },
|
||||
{ stringFactory, doubleFactory, stringTemplateLtc }, { stringFactory, longFactory, stringTemplateLtc },
|
||||
{ rawFactory, rawFactory, rawTemplateLtc }, { stringFactory, stringFactory, genericTemplateSrp },
|
||||
{ personFactory, personFactory, genericTemplateSrp }, { stringFactory, personFactory, genericTemplateSrp },
|
||||
{ personFactory, stringFactory, genericTemplateSrp }, { personFactory, stringFactory, xGenericTemplateSrp },
|
||||
{ stringFactory, doubleFactory, stringTemplateSrp }, { stringFactory, longFactory, stringTemplateSrp },
|
||||
{ personFactory, stringFactory, jsonPersonTemplateSrp },
|
||||
{ rawFactory, rawFactory, rawTemplateSrp}});
|
||||
{ personFactory, stringFactory, jackson2JsonPersonTemplateSrp }, { rawFactory, rawFactory, rawTemplateSrp } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2014 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.
|
||||
@@ -15,11 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.redis.support.collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
@@ -42,18 +38,20 @@ import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.StringObjectFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisPool;
|
||||
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisPool;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.OxmSerializer;
|
||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class RedisPropertiesTests extends RedisMapTests {
|
||||
|
||||
@@ -62,7 +60,7 @@ public class RedisPropertiesTests extends RedisMapTests {
|
||||
|
||||
/**
|
||||
* Constructs a new <code>RedisPropertiesTests</code> instance.
|
||||
*
|
||||
*
|
||||
* @param keyFactory
|
||||
* @param valueFactory
|
||||
* @param template
|
||||
@@ -72,14 +70,12 @@ public class RedisPropertiesTests extends RedisMapTests {
|
||||
super(keyFactory, valueFactory, template);
|
||||
}
|
||||
|
||||
|
||||
RedisMap<Object, Object> createMap() {
|
||||
String redisName = getClass().getSimpleName();
|
||||
props = new RedisProperties(defaults, redisName, new StringRedisTemplate(template.getConnectionFactory()));
|
||||
return props;
|
||||
}
|
||||
|
||||
|
||||
protected RedisStore copyStore(RedisStore store) {
|
||||
return new RedisProperties(store.getKey(), store.getOperations());
|
||||
}
|
||||
@@ -139,7 +135,6 @@ public class RedisPropertiesTests extends RedisMapTests {
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
props.store(writer, "no-comment");
|
||||
//System.out.println(writer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -225,8 +220,12 @@ public class RedisPropertiesTests extends RedisMapTests {
|
||||
assertTrue(keys.contains(key3));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-241
|
||||
*/
|
||||
@Parameters
|
||||
public static Collection<Object[]> testParams() {
|
||||
|
||||
// XStream serializer
|
||||
XStreamMarshaller xstream = new XStreamMarshaller();
|
||||
try {
|
||||
@@ -237,6 +236,9 @@ public class RedisPropertiesTests extends RedisMapTests {
|
||||
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
|
||||
JacksonJsonRedisSerializer<Person> jsonSerializer = new JacksonJsonRedisSerializer<Person>(Person.class);
|
||||
JacksonJsonRedisSerializer<String> jsonStringSerializer = new JacksonJsonRedisSerializer<String>(String.class);
|
||||
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
|
||||
Jackson2JsonRedisSerializer<String> jackson2JsonStringSerializer = new Jackson2JsonRedisSerializer<String>(
|
||||
String.class);
|
||||
|
||||
// create Jedis Factory
|
||||
ObjectFactory<String> stringFactory = new StringObjectFactory();
|
||||
@@ -265,9 +267,16 @@ public class RedisPropertiesTests extends RedisMapTests {
|
||||
jsonPersonTemplate.setHashValueSerializer(jsonStringSerializer);
|
||||
jsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplate.setConnectionFactory(jedisConnFactory);
|
||||
jackson2JsonPersonTemplate.setDefaultSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplate.setHashKeySerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplate.setHashValueSerializer(jackson2JsonStringSerializer);
|
||||
jackson2JsonPersonTemplate.afterPropertiesSet();
|
||||
|
||||
// JRedis
|
||||
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(
|
||||
SettingsUtils.getHost(), SettingsUtils.getPort()));
|
||||
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
|
||||
SettingsUtils.getPort()));
|
||||
jredisConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, String> genericTemplateJR = new StringRedisTemplate(jredisConnFactory);
|
||||
@@ -283,6 +292,12 @@ public class RedisPropertiesTests extends RedisMapTests {
|
||||
jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer);
|
||||
jsonPersonTemplateJR.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplateJR = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
|
||||
jackson2JsonPersonTemplateJR.setDefaultSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateJR.setHashKeySerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateJR.setHashValueSerializer(jackson2JsonStringSerializer);
|
||||
jackson2JsonPersonTemplateJR.afterPropertiesSet();
|
||||
|
||||
// Lettuce
|
||||
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
|
||||
@@ -303,6 +318,13 @@ public class RedisPropertiesTests extends RedisMapTests {
|
||||
jsonPersonTemplateLtc.setHashValueSerializer(jsonStringSerializer);
|
||||
jsonPersonTemplateLtc.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplateLtc = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
jackson2JsonPersonTemplateLtc.setDefaultSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateLtc.setHashKeySerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateLtc.setHashValueSerializer(jackson2JsonStringSerializer);
|
||||
jackson2JsonPersonTemplateLtc.afterPropertiesSet();
|
||||
|
||||
// SRP
|
||||
SrpConnectionFactory srpConnFactory = new SrpConnectionFactory();
|
||||
srpConnFactory.setPort(SettingsUtils.getPort());
|
||||
@@ -322,34 +344,31 @@ public class RedisPropertiesTests extends RedisMapTests {
|
||||
jsonPersonTemplateSrp.setHashValueSerializer(jsonStringSerializer);
|
||||
jsonPersonTemplateSrp.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jackson2JsonPersonTemplateSrp = new RedisTemplate<String, Person>();
|
||||
jackson2JsonPersonTemplateSrp.setConnectionFactory(srpConnFactory);
|
||||
jackson2JsonPersonTemplateSrp.setDefaultSerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateSrp.setHashKeySerializer(jackson2JsonSerializer);
|
||||
jackson2JsonPersonTemplateSrp.setHashValueSerializer(jackson2JsonStringSerializer);
|
||||
jackson2JsonPersonTemplateSrp.afterPropertiesSet();
|
||||
|
||||
return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate },
|
||||
{ stringFactory, stringFactory, genericTemplate },
|
||||
{ stringFactory, stringFactory, genericTemplate },
|
||||
{ stringFactory, stringFactory, genericTemplate },
|
||||
{ stringFactory, stringFactory, xstreamGenericTemplate },
|
||||
{ stringFactory, stringFactory, genericTemplateJR },
|
||||
{ stringFactory, stringFactory, genericTemplateJR },
|
||||
{ stringFactory, stringFactory, genericTemplateJR },
|
||||
{ stringFactory, stringFactory, genericTemplateJR },
|
||||
{ stringFactory, stringFactory, xGenericTemplateJR },
|
||||
{ stringFactory, stringFactory, jsonPersonTemplate },
|
||||
{ stringFactory, stringFactory, genericTemplate }, { stringFactory, stringFactory, genericTemplate },
|
||||
{ stringFactory, stringFactory, genericTemplate }, { stringFactory, stringFactory, xstreamGenericTemplate },
|
||||
{ stringFactory, stringFactory, genericTemplateJR }, { stringFactory, stringFactory, genericTemplateJR },
|
||||
{ stringFactory, stringFactory, genericTemplateJR }, { stringFactory, stringFactory, genericTemplateJR },
|
||||
{ stringFactory, stringFactory, xGenericTemplateJR }, { stringFactory, stringFactory, jsonPersonTemplate },
|
||||
{ stringFactory, stringFactory, jackson2JsonPersonTemplate },
|
||||
{ stringFactory, stringFactory, jsonPersonTemplateJR },
|
||||
{ stringFactory, stringFactory, genericTemplateLtc },
|
||||
{ stringFactory, stringFactory, genericTemplateLtc },
|
||||
{ stringFactory, stringFactory, genericTemplateLtc },
|
||||
{ stringFactory, stringFactory, genericTemplateLtc },
|
||||
{ stringFactory, doubleFactory, genericTemplateLtc },
|
||||
{ stringFactory, longFactory, genericTemplateLtc },
|
||||
{ stringFactory, stringFactory, xGenericTemplateLtc },
|
||||
{ stringFactory, stringFactory, jsonPersonTemplateLtc },
|
||||
{ stringFactory, stringFactory, genericTemplateSrp },
|
||||
{ stringFactory, stringFactory, genericTemplateSrp },
|
||||
{ stringFactory, stringFactory, genericTemplateSrp },
|
||||
{ stringFactory, stringFactory, genericTemplateSrp },
|
||||
{ stringFactory, doubleFactory, genericTemplateSrp },
|
||||
{ stringFactory, longFactory, genericTemplateSrp },
|
||||
{ stringFactory, stringFactory, xGenericTemplateSrp },
|
||||
{ stringFactory, stringFactory, jsonPersonTemplateSrp }});
|
||||
{ stringFactory, stringFactory, jackson2JsonPersonTemplateJR },
|
||||
{ stringFactory, stringFactory, genericTemplateLtc }, { stringFactory, stringFactory, genericTemplateLtc },
|
||||
{ stringFactory, stringFactory, genericTemplateLtc }, { stringFactory, stringFactory, genericTemplateLtc },
|
||||
{ stringFactory, doubleFactory, genericTemplateLtc }, { stringFactory, longFactory, genericTemplateLtc },
|
||||
{ stringFactory, stringFactory, xGenericTemplateLtc }, { stringFactory, stringFactory, jsonPersonTemplateLtc },
|
||||
{ stringFactory, stringFactory, jackson2JsonPersonTemplateLtc },
|
||||
{ stringFactory, stringFactory, genericTemplateSrp }, { stringFactory, stringFactory, genericTemplateSrp },
|
||||
{ stringFactory, stringFactory, genericTemplateSrp }, { stringFactory, stringFactory, genericTemplateSrp },
|
||||
{ stringFactory, doubleFactory, genericTemplateSrp }, { stringFactory, longFactory, genericTemplateSrp },
|
||||
{ stringFactory, stringFactory, xGenericTemplateSrp }, { stringFactory, stringFactory, jsonPersonTemplateSrp },
|
||||
{ stringFactory, stringFactory, jackson2JsonPersonTemplateSrp } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ Import-Template:
|
||||
redis.clients.*;resolution:="optional";version="[2.1.0, 2.1.0]",
|
||||
org.apache.commons.pool.*;resolution:="optional";version="[1.0.0, 3.0.0)",
|
||||
org.codehaus.jackson.*;resolution:="optional";version="[1.6, 2.0.0)",
|
||||
com.fasterxml.jackson.*;resolution:="optional";version="[2.0.0, 3.0.0)",
|
||||
org.apache.commons.beanutils.*;resolution:="optional";version=1.8.5,
|
||||
redis.*;resolution:="optional";version="[0.2, 1.0)",
|
||||
com.google.common.*;resolution:="optional";version="[11.0.0, 20.0.0)",
|
||||
|
||||
Reference in New Issue
Block a user