From 3dbbbaad45b12b541787012943807bd3b896093a Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 10 Nov 2010 18:47:44 +0200 Subject: [PATCH] + trying to add serializer into place + added more integration tests + added generics for RedisList - still having serialization/deserialization problems --- .../jedis/JedisConnectionFactory.java | 1 + .../datastore/redis/core/RedisTemplate.java | 2 +- .../redis/serializer/RedisSerializer.java | 10 +- .../serializer/SimpleRedisSerializer.java | 37 ++++- .../redis/util/AbstractRedisCollection.java | 21 ++- .../datastore/redis/util/CollectionUtils.java | 38 +++++ .../redis/util/DefaultRedisList.java | 74 ++++----- .../datastore/redis/util/DefaultRedisSet.java | 4 +- .../redis/util/DefaultRedisSortedSet.java | 4 +- .../datastore/redis/util/RedisIterator.java | 12 +- .../datastore/redis/util/RedisList.java | 6 +- .../serializer/SimpleRedisSerializerTest.java | 130 ++++++++++++++++ .../util/AbstractRedisCollectionTest.java | 143 ++++++++++++++++++ .../redis/util/StringRedisListTest.java | 47 ++++++ 14 files changed, 463 insertions(+), 66 deletions(-) create mode 100644 spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/CollectionUtils.java create mode 100644 spring-datastore-redis/src/test/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializerTest.java create mode 100644 spring-datastore-redis/src/test/java/org/springframework/datastore/redis/util/AbstractRedisCollectionTest.java create mode 100644 spring-datastore-redis/src/test/java/org/springframework/datastore/redis/util/StringRedisListTest.java diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionFactory.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionFactory.java index 296c7f672..a628a7fc6 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionFactory.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionFactory.java @@ -117,6 +117,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, int size = getPoolSize(); pool = new JedisPool(shardInfo); pool.setResourcesNumber(size); + pool.init(); } } diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java index 3cfa23777..89673c6f0 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java @@ -46,7 +46,7 @@ import org.springframework.util.ClassUtils; public class RedisTemplate extends RedisAccessor { private boolean exposeConnection = false; - private RedisSerializer converter = new SimpleRedisSerializer(); + private RedisSerializer converter = new SimpleRedisSerializer(); public RedisTemplate() { } diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/RedisSerializer.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/RedisSerializer.java index 486155e26..9a7215598 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/RedisSerializer.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/RedisSerializer.java @@ -21,9 +21,13 @@ package org.springframework.datastore.redis.serializer; * @author Mark Pollack * @author Costin Leau */ -public interface RedisSerializer { +public interface RedisSerializer { - byte[] serialize(T object); + byte[] serialize(Object object); - T deserialize(byte[] bytes); + String serializeAsString(Object object); + + T deserialize(byte[] bytes); + + T deserialize(String bytes); } diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializer.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializer.java index 308f2e33f..5dad43221 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializer.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializer.java @@ -18,6 +18,7 @@ package org.springframework.datastore.redis.serializer; import org.springframework.core.convert.converter.Converter; import org.springframework.core.serializer.support.DeserializingConverter; import org.springframework.core.serializer.support.SerializingConverter; +import org.springframework.datastore.redis.UncategorizedRedisException; /** * Simple Redis serializer delegating to the default serializer in Spring 3. @@ -25,18 +26,42 @@ import org.springframework.core.serializer.support.SerializingConverter; * @author Mark Pollack * @author Costin Leau */ -public class SimpleRedisSerializer implements RedisSerializer { +public class SimpleRedisSerializer implements RedisSerializer { private Converter serializer = new SerializingConverter(); private Converter deserializer = new DeserializingConverter(); + + @SuppressWarnings("unchecked") @Override - public T deserialize(byte[] bytes) { - return (T) deserializer.convert(bytes); + public T deserialize(byte[] bytes) { + try { + return (T) deserializer.convert(bytes); + } catch (Exception ex) { + throw new UncategorizedRedisException("Cannot deserialize", ex); + } } @Override - public byte[] serialize(T object) { - return serializer.convert(object); + public T deserialize(String bytes) { + // try { + return deserialize(bytes.getBytes()); + // } catch (UnsupportedEncodingException ex) { + // throw new DataRetrievalFailureException("Unsupported encoding " + encoding, ex); + // } } -} + + @Override + public byte[] serialize(Object object) { + try { + return serializer.convert(object); + } catch (Exception ex) { + throw new UncategorizedRedisException("Cannot serialize", ex); + } + } + + @Override + public String serializeAsString(Object object) { + return new String(serialize(object)); + } +} \ No newline at end of file diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/AbstractRedisCollection.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/AbstractRedisCollection.java index c9b7ffa1b..8f886d35f 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/AbstractRedisCollection.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/AbstractRedisCollection.java @@ -19,20 +19,30 @@ import java.util.AbstractCollection; import java.util.Collection; import org.springframework.datastore.redis.connection.RedisCommands; +import org.springframework.datastore.redis.serializer.RedisSerializer; +import org.springframework.datastore.redis.serializer.SimpleRedisSerializer; /** * Base implementation for Redis collections. * * @author Costin Leau */ -public abstract class AbstractRedisCollection extends AbstractCollection implements RedisStore { +public abstract class AbstractRedisCollection extends AbstractCollection implements RedisStore { + + public static final String ENCODING = "UTF-8"; protected final String key; protected final RedisCommands commands; + protected final RedisSerializer serializer; public AbstractRedisCollection(String key, RedisCommands commands) { + this(key, commands, new SimpleRedisSerializer()); + } + + public AbstractRedisCollection(String key, RedisCommands commands, RedisSerializer serializer) { this.key = key; this.commands = commands; + this.serializer = serializer; } @Override @@ -41,15 +51,15 @@ public abstract class AbstractRedisCollection extends AbstractCollection } @Override - public boolean addAll(Collection c) { + public boolean addAll(Collection c) { boolean modified = false; - for (String string : c) { - modified |= add(string); + for (E e : c) { + modified |= add(e); } return modified; } - public abstract boolean add(String e); + public abstract boolean add(E e); public abstract void clear(); @@ -77,5 +87,4 @@ public abstract class AbstractRedisCollection extends AbstractCollection public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } - } \ No newline at end of file diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/CollectionUtils.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/CollectionUtils.java new file mode 100644 index 000000000..0613805e3 --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/CollectionUtils.java @@ -0,0 +1,38 @@ +/* + * 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.datastore.redis.util; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.datastore.redis.serializer.RedisSerializer; + +/** + * Utility class used mainly for type conversion by the default collection implementations. + * + * @author Costin Leau + */ +abstract class CollectionUtils { + + static List deserializeAsList(List input, RedisSerializer serializer) { + List result = new ArrayList(input.size()); + for (String string : input) { + E item = serializer.deserialize(string); + result.add(item); + } + return result; + } +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisList.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisList.java index 4226dd581..ce934cf89 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisList.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisList.java @@ -28,16 +28,16 @@ import org.springframework.datastore.redis.connection.RedisCommands; * * @author Costin Leau */ -public class DefaultRedisList extends AbstractRedisCollection implements RedisList { +public class DefaultRedisList extends AbstractRedisCollection implements RedisList { - private class DefaultRedisListIterator extends RedisIterator { + private class DefaultRedisListIterator extends RedisIterator { - public DefaultRedisListIterator(Iterator delegate) { + public DefaultRedisListIterator(Iterator delegate) { super(delegate); } @Override - protected void removeFromRedisStorage(String item) { + protected void removeFromRedisStorage(E item) { DefaultRedisList.this.remove(item); } } @@ -47,22 +47,22 @@ public class DefaultRedisList extends AbstractRedisCollection implements RedisLi } @Override - public List range(int start, int end) { - return commands.lRange(key, start, end); + public List range(int start, int end) { + return CollectionUtils.deserializeAsList(commands.lRange(key, start, end), serializer); } @Override - public RedisList trim(int start, int end) { + public RedisList trim(int start, int end) { commands.lTrim(key, start, end); return this; } - private List content() { - return commands.lRange(key, 0, -1); + private List content() { + return CollectionUtils.deserializeAsList(commands.lRange(key, 0, -1), serializer); } @Override - public Iterator iterator() { + public Iterator iterator() { return content().iterator(); } @@ -73,8 +73,8 @@ public class DefaultRedisList extends AbstractRedisCollection implements RedisLi @Override - public boolean add(String value) { - commands.rPush(key, value); + public boolean add(E value) { + commands.rPush(key, serializer.serializeAsString(value)); return true; } @@ -90,29 +90,29 @@ public class DefaultRedisList extends AbstractRedisCollection implements RedisLi } @Override - public void add(int index, String element) { + public void add(int index, E element) { if (index == 0) { - commands.lPush(key, element); + commands.lPush(key, serializer.serializeAsString(element)); } else if (index == size()) { - commands.rPush(key, element); + commands.rPush(key, serializer.serializeAsString(element)); } throw new IllegalArgumentException("Redis supports insertion only at the beginning or the end of the list"); } @Override - public boolean addAll(int index, Collection c) { - for (String string : c) { - add(index, string); + public boolean addAll(int index, Collection c) { + for (E e : c) { + add(index, e); } return true; } @Override - public String get(int index) { - return commands.lIndex(key, index); + public E get(int index) { + return serializer.deserialize(commands.lIndex(key, index)); } @Override @@ -126,37 +126,37 @@ public class DefaultRedisList extends AbstractRedisCollection implements RedisLi } @Override - public ListIterator listIterator() { + public ListIterator listIterator() { throw new UnsupportedOperationException(); } @Override - public ListIterator listIterator(int index) { + public ListIterator listIterator(int index) { throw new UnsupportedOperationException(); } @Override - public String remove(int index) { + public E remove(int index) { throw new UnsupportedOperationException(); } @Override - public String set(int index, String element) { - String object = get(index); - commands.lSet(key, index, element); + public E set(int index, E e) { + E object = get(index); + commands.lSet(key, index, serializer.serializeAsString(e)); return object; } @Override - public List subList(int fromIndex, int toIndex) { + public List subList(int fromIndex, int toIndex) { throw new UnsupportedOperationException(); } @Override - public String element() { - String value = peek(); + public E element() { + E value = peek(); if (value == null) throw new NoSuchElementException(); @@ -165,27 +165,27 @@ public class DefaultRedisList extends AbstractRedisCollection implements RedisLi @Override - public boolean offer(String e) { - commands.lPush(key, e); + public boolean offer(E e) { + commands.lPush(key, serializer.serializeAsString(e)); return true; } @Override - public String peek() { - return commands.lIndex(key, 0); + public E peek() { + return serializer.deserialize(commands.lIndex(key, 0)); } @Override - public String poll() { - return commands.lPop(key); + public E poll() { + return serializer.deserialize(commands.lPop(key)); } @Override - public String remove() { - String value = poll(); + public E remove() { + E value = poll(); if (value == null) throw new NoSuchElementException(); diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisSet.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisSet.java index 6dcbf749e..e08a25d1b 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisSet.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisSet.java @@ -25,9 +25,9 @@ import org.springframework.datastore.redis.connection.RedisCommands; * * @author Costin Leau */ -public class DefaultRedisSet extends AbstractRedisCollection implements RedisSet { +public class DefaultRedisSet extends AbstractRedisCollection implements RedisSet { - private class DefaultRedisSetIterator extends RedisIterator { + private class DefaultRedisSetIterator extends RedisIterator { public DefaultRedisSetIterator(Iterator delegate) { super(delegate); diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisSortedSet.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisSortedSet.java index 4343b8b1d..8228de6ff 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisSortedSet.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisSortedSet.java @@ -27,9 +27,9 @@ import org.springframework.datastore.redis.connection.RedisCommands; * * @author Costin Leau */ -class DefaultRedisSortedSet extends AbstractRedisCollection implements RedisSortedSet { +class DefaultRedisSortedSet extends AbstractRedisCollection implements RedisSortedSet { - private class DefaultRedisSortedSetIterator extends RedisIterator { + private class DefaultRedisSortedSetIterator extends RedisIterator { public DefaultRedisSortedSetIterator(Iterator delegate) { super(delegate); diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/RedisIterator.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/RedisIterator.java index ae22f2e28..a65a4fa8c 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/RedisIterator.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/RedisIterator.java @@ -22,18 +22,18 @@ import java.util.Iterator; * * @author Costin Leau */ -abstract class RedisIterator implements Iterator { +abstract class RedisIterator implements Iterator { - private final Iterator delegate; + private final Iterator delegate; - private String item; + private E item; /** * Constructs a new RedisIterator instance. * * @param delegate */ - RedisIterator(Iterator delegate) { + RedisIterator(Iterator delegate) { this.delegate = delegate; } @@ -49,7 +49,7 @@ abstract class RedisIterator implements Iterator { * @return * @see java.util.Iterator#next() */ - public String next() { + public E next() { item = delegate.next(); return item; } @@ -64,5 +64,5 @@ abstract class RedisIterator implements Iterator { item = null; } - protected abstract void removeFromRedisStorage(String item); + protected abstract void removeFromRedisStorage(E item); } \ No newline at end of file diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/RedisList.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/RedisList.java index 82baa0f89..492eef424 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/RedisList.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/RedisList.java @@ -24,9 +24,9 @@ import java.util.Queue; * * @author Costin Leau */ -public interface RedisList extends RedisStore, List, Queue { +public interface RedisList extends RedisStore, List, Queue { - List range(int start, int end); + List range(int start, int end); - RedisList trim(int start, int end); + RedisList trim(int start, int end); } diff --git a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializerTest.java b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializerTest.java new file mode 100644 index 000000000..9106acf86 --- /dev/null +++ b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializerTest.java @@ -0,0 +1,130 @@ +/* + * 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.datastore.redis.serializer; + +import static org.junit.Assert.*; + +import java.io.Serializable; +import java.util.UUID; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +public class SimpleRedisSerializerTest { + + private static class A implements Serializable { + private Integer value = Integer.valueOf(30); + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + A other = (A) obj; + if (value == null) { + if (other.value != null) + return false; + } + else if (!value.equals(other.value)) + return false; + return true; + } + } + + private static class B implements Serializable { + private String name = getClass().getName(); + private A a = new A(); + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((a == null) ? 0 : a.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + B other = (B) obj; + if (a == null) { + if (other.a != null) + return false; + } + else if (!a.equals(other.a)) + return false; + if (name == null) { + if (other.name != null) + return false; + } + else if (!name.equals(other.name)) + return false; + return true; + } + } + + private RedisSerializer serializer; + + @Before + public void setUp() { + serializer = new SimpleRedisSerializer(); + } + + @After + public void tearDown() { + serializer = null; + } + + @Test + public void testBasicSerializationRoundtrip() throws Exception { + Integer integer = new Integer(300); + verifySerializedObjects(new Integer(300), new Double(200), new B()); + } + + private void verifySerializedObjects(Object... objects) { + for (Object object : objects) { + assertEquals("Incorrectly (de)serialized object " + object, object, + serializer.deserialize(serializer.serialize(object))); + } + } + + @Test + public void testStringEncodedSerialization() { + String value = UUID.randomUUID().toString(); + assertEquals(value, serializer.deserialize(serializer.serializeAsString(value))); + assertEquals(value, serializer.deserialize(serializer.serializeAsString(value))); + assertEquals(value, serializer.deserialize(serializer.serializeAsString(value))); + } +} \ No newline at end of file diff --git a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/util/AbstractRedisCollectionTest.java b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/util/AbstractRedisCollectionTest.java new file mode 100644 index 000000000..d5b3dcf1f --- /dev/null +++ b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/util/AbstractRedisCollectionTest.java @@ -0,0 +1,143 @@ +/* + * 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.datastore.redis.util; + + +import static org.hamcrest.CoreMatchers.*; +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.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +/** + * Base test for Redis collections. + * + * @author Costin Leau + */ +public abstract class AbstractRedisCollectionTest { + + private AbstractRedisCollection collection; + + @Before + public void setUp() throws Exception { + collection = getCollection(); + } + + abstract AbstractRedisCollection getCollection(); + + /** + * Return a new instance of T + * @return + */ + abstract T getT(); + + @After + public void tearDown() throws Exception { + collection.clear(); + } + + @Test + public void testAdd() { + T t1 = getT(); + assertThat(collection.add(t1), is(Boolean.TRUE)); + assertThat(collection, hasItem(t1)); + assertEquals(collection.size(), 1); + } + + @SuppressWarnings("unchecked") + @Test + public void testAddAll() { + T t1 = getT(); + T t2 = getT(); + T t3 = getT(); + + List list = Arrays.asList(t1, t2, t3); + + assertThat(collection.addAll(list), is(Boolean.TRUE)); + assertThat(collection, hasItem(t1)); + assertThat(collection, hasItem(t2)); + assertThat(collection, hasItem(t3)); + assertEquals(collection.size(), 3); + } + + public void clear() { + collection.clear(); + } + + public boolean contains(Object o) { + return collection.contains(o); + } + + public boolean containsAll(Collection c) { + return collection.containsAll(c); + } + + public boolean equals(Object obj) { + return collection.equals(obj); + } + + public String getKey() { + return collection.getKey(); + } + + public int hashCode() { + return collection.hashCode(); + } + + public boolean isEmpty() { + return collection.isEmpty(); + } + + public Iterator iterator() { + return collection.iterator(); + } + + public boolean remove(Object o) { + return collection.remove(o); + } + + public boolean removeAll(Collection c) { + return collection.removeAll(c); + } + + public boolean retainAll(Collection c) { + return collection.retainAll(c); + } + + public int size() { + return collection.size(); + } + + public Object[] toArray() { + return collection.toArray(); + } + + public T[] toArray(T[] a) { + return collection.toArray(a); + } + + public String toString() { + return collection.toString(); + } +} \ No newline at end of file diff --git a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/util/StringRedisListTest.java b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/util/StringRedisListTest.java new file mode 100644 index 000000000..e44bcbf34 --- /dev/null +++ b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/util/StringRedisListTest.java @@ -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.datastore.redis.util; + +import java.util.UUID; + +import org.springframework.datastore.redis.connection.jredis.JredisConnectionFactory; + + +/** + * String-based Redis List test. + * + * @author Costin Leau + */ +public class StringRedisListTest extends AbstractRedisCollectionTest { + + private DefaultRedisList redisList; + + public StringRedisListTest() { + JredisConnectionFactory factory = new JredisConnectionFactory(); + factory.afterPropertiesSet(); + redisList = new DefaultRedisList(getClass().getName(), factory.getConnection()); + } + + @Override + AbstractRedisCollection getCollection() { + return redisList; + } + + @Override + String getT() { + return UUID.randomUUID().toString(); + } +}