From aac726d816594ba79fa790f2e015b0268032d97c Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 5 Nov 2010 13:06:55 +0200 Subject: [PATCH] + fixed some of the integration tests + added basic integration tests for both Jredis and Jedis --- .../jedis/JedisConnectionIntegrationTest.java | 64 +++++++++++ .../JRedisConnectionIntegrationTests.java} | 27 +++-- .../core/AbstractClientIntegrationTests.java | 108 ------------------ .../AbstractConnectionIntegrationTests.java | 65 +++++++++++ .../core/RedisTemplateIntegrationTests.java | 2 +- .../JedisRedisClientIntegrationTests.java | 67 ----------- 6 files changed, 145 insertions(+), 188 deletions(-) create mode 100644 spring-datastore-redis/src/test/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionIntegrationTest.java rename spring-datastore-redis/src/test/java/org/springframework/datastore/redis/{core/jredis/JRedisClientIntegrationTests.java => connection/jredis/JRedisConnectionIntegrationTests.java} (51%) delete mode 100644 spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/AbstractClientIntegrationTests.java create mode 100644 spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/AbstractConnectionIntegrationTests.java delete mode 100644 spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/jedis/JedisRedisClientIntegrationTests.java diff --git a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionIntegrationTest.java b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionIntegrationTest.java new file mode 100644 index 000000000..5c02bc577 --- /dev/null +++ b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/connection/jedis/JedisConnectionIntegrationTest.java @@ -0,0 +1,64 @@ +/* + * 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.connection.jedis; + +import org.springframework.datastore.redis.connection.RedisConnectionFactory; +import org.springframework.datastore.redis.core.AbstractConnectionIntegrationTests; + +public class JedisConnectionIntegrationTest extends AbstractConnectionIntegrationTests { + + JedisConnectionFactory factory; + + public JedisConnectionIntegrationTest() { + factory = new JedisConnectionFactory(); + factory.setPooling(false); + factory.afterPropertiesSet(); + } + + @Override + protected RedisConnectionFactory getConnectionFactory() { + return factory; + } + +// @Test +// public void setAdd() { +// connection.sadd("s1", "1"); +// connection.sadd("s1", "2"); +// connection.sadd("s1", "3"); +// connection.sadd("s2", "2"); +// connection.sadd("s2", "3"); +// Set intersection = connection.sinter("s1", "s2"); +// System.out.println(intersection); +// +// +// } +// +// @Test +// public void setIntersectionTests() { +// RedisTemplate template = new RedisTemplate(clientFactory); +// RedisSet s1 = new RedisSet(template, "s1"); +// s1.add("1"); +// s1.add("2"); +// s1.add("3"); +// RedisSet s2 = new RedisSet(template, "s2"); +// s2.add("2"); +// s2.add("3"); +// Set s3 = s1.intersection("s3", s1, s2); +// for (Object object : s3) { +// System.out.println(object); +// } +} \ No newline at end of file diff --git a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/jredis/JRedisClientIntegrationTests.java b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/connection/jredis/JRedisConnectionIntegrationTests.java similarity index 51% rename from spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/jredis/JRedisClientIntegrationTests.java rename to spring-datastore-redis/src/test/java/org/springframework/datastore/redis/connection/jredis/JRedisConnectionIntegrationTests.java index 478730048..e4975cfa9 100644 --- a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/jredis/JRedisClientIntegrationTests.java +++ b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/connection/jredis/JRedisConnectionIntegrationTests.java @@ -14,20 +14,23 @@ * limitations under the License. */ -package org.springframework.datastore.redis.core.jredis; +package org.springframework.datastore.redis.connection.jredis; -import org.junit.Before; -import org.springframework.datastore.redis.core.AbstractClientIntegrationTests; -import org.springframework.datastore.redis.core.RedisClientFactory; +import org.springframework.datastore.redis.connection.RedisConnectionFactory; +import org.springframework.datastore.redis.core.AbstractConnectionIntegrationTests; -public class JRedisClientIntegrationTests extends AbstractClientIntegrationTests { +public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrationTests { - - @Before - public void setUp() { - RedisClientFactory clientFactory = new JRedisClientFactory(); - clientFactory.setPassword("foobared"); - client = clientFactory.createClient(); + JredisConnectionFactory factory; + + public JRedisConnectionIntegrationTests() { + factory = new JredisConnectionFactory(); + factory.setPooling(false); + factory.afterPropertiesSet(); + } + + @Override + protected RedisConnectionFactory getConnectionFactory() { + return factory; } - } diff --git a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/AbstractClientIntegrationTests.java b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/AbstractClientIntegrationTests.java deleted file mode 100644 index de205e044..000000000 --- a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/AbstractClientIntegrationTests.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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.core; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.Map; -import java.util.Set; - -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Test; -import org.springframework.dao.InvalidDataAccessApiUsageException; - -import redis.clients.jedis.JedisException; - -public abstract class AbstractClientIntegrationTests { - - protected RedisClient client; - - @After - public void tearDown() throws IOException { - client.disconnect(); - } - @Test - public void save() { - String status = client.save(); - assertEquals("OK", status); - } - - @Test - public void bgsave() { - try { - String status = client.bgsave(); - assertEquals("Background saving started", status); - } catch (InvalidDataAccessApiUsageException e) { - assertEquals("ERR Background save already in progress", - e.getMessage()); - } - } - - @Test - public void bgrewriteaof() { - String status = client.bgrewriteaof(); - assertEquals("Background append only file rewriting started", status); - } - - @Test - public void lastsave() throws InterruptedException { - int before = client.lastsave(); - String st = ""; - while (!st.equals("OK")) { - try { - Thread.sleep(1000); - st = client.save(); - } catch (JedisException e) { - - } - } - int after = client.lastsave(); - assertTrue((after - before) > 0); - } - - - - @Test - public void info() { - Map infoResponse = client.info(); - Assert.assertNotNull(infoResponse); - Assert.assertTrue(infoResponse.containsKey("redis_version")); - //Map infoResponse = client.info(); - //Assert.assertTrue("Expected non empty map of info about the server.", infoResponse.size() > 0); - //Assert.assertTrue("Expected key 'redis_version' in map of info about the server.", - // infoResponse.containsKey("redis_version")); - } - - @Test - public void setAndGet() { - client.set("foo", "blah blah"); - String value = client.get("foo"); - Assert.assertEquals("blah blah", value); - } - - @Test - public void conversions() { - Person p = new Person("Joe", "Trader", 33); - - } - - -} diff --git a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/AbstractConnectionIntegrationTests.java b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/AbstractConnectionIntegrationTests.java new file mode 100644 index 000000000..c2ec4ebba --- /dev/null +++ b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/AbstractConnectionIntegrationTests.java @@ -0,0 +1,65 @@ +/* + * 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.core; + +import static org.junit.Assert.assertEquals; +import junit.framework.Assert; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.datastore.redis.connection.RedisConnection; +import org.springframework.datastore.redis.connection.RedisConnectionFactory; + +public abstract class AbstractConnectionIntegrationTests { + + protected RedisConnection connection; + private static final String listName = "test-list"; + + @Before + public void setUp() { + connection = getConnectionFactory().getConnection(); + } + + protected abstract RedisConnectionFactory getConnectionFactory(); + + @After + public void tearDown() { + connection.close(); + connection = null; + } + + @Test + public void testLPush() throws Exception { + Integer index = connection.lPush(listName, "bar"); + if (index != null) { + assertEquals((Integer) (index + 1), connection.lPush(listName, "bar")); + } + } + + @Test + public void testSetAndGet() { + connection.set("foo", "blah blah"); + String value = connection.get("foo"); + Assert.assertEquals("blah blah", value); + } + + + public void conversions() { + Person p = new Person("Joe", "Trader", 33); + } +} \ No newline at end of file diff --git a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/RedisTemplateIntegrationTests.java b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/RedisTemplateIntegrationTests.java index a962d31f5..265e9a7b8 100644 --- a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/RedisTemplateIntegrationTests.java +++ b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/RedisTemplateIntegrationTests.java @@ -19,7 +19,7 @@ package org.springframework.datastore.redis.core; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.springframework.datastore.redis.core.jredis.JRedisClientFactory; +import org.springframework.datastore.redis.connection.jredis.JRedisClientFactory; public class RedisTemplateIntegrationTests { diff --git a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/jedis/JedisRedisClientIntegrationTests.java b/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/jedis/JedisRedisClientIntegrationTests.java deleted file mode 100644 index 40d4f22fa..000000000 --- a/spring-datastore-redis/src/test/java/org/springframework/datastore/redis/core/jedis/JedisRedisClientIntegrationTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.core.jedis; - -import java.util.Set; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.datastore.redis.core.AbstractClientIntegrationTests; -import org.springframework.datastore.redis.core.RedisClientFactory; -import org.springframework.datastore.redis.core.RedisTemplate; -import org.springframework.datastore.redis.util.RedisSet; - -public class JedisRedisClientIntegrationTests extends - AbstractClientIntegrationTests { - - RedisClientFactory clientFactory; - @Before - public void setUp() { - clientFactory = new JedisClientFactory(); - clientFactory.setPassword("foobared"); - client = clientFactory.createClient(); - client.flushAll(); - } - - @Test - public void setAdd() { - client.sadd("s1", "1"); - client.sadd("s1", "2"); - client.sadd("s1", "3"); - client.sadd("s2", "2"); - client.sadd("s2", "3"); - Set intersection = client.sinter("s1", "s2"); - System.out.println(intersection); - - - } - - @Test - public void setIntersectionTests() { - RedisTemplate template = new RedisTemplate(clientFactory); - RedisSet s1 = new RedisSet(template, "s1"); - s1.add("1"); s1.add("2"); s1.add("3"); - RedisSet s2 = new RedisSet(template, "s2"); - s2.add("2"); s2.add("3"); - Set s3 = s1.intersection("s3", s1, s2); - for (Object object : s3) { - System.out.println(object); - } - - } - -}