+ fixed some of the integration tests

+ added basic integration tests for both Jredis and Jedis
This commit is contained in:
Costin Leau
2010-11-05 13:06:55 +02:00
parent 80fe08d3fd
commit aac726d816
6 changed files with 145 additions and 188 deletions

View File

@@ -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<String> 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);
// }
}

View File

@@ -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;
}
}

View File

@@ -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<String,String> infoResponse = client.info();
Assert.assertNotNull(infoResponse);
Assert.assertTrue(infoResponse.containsKey("redis_version"));
//Map<String, String> 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);
}
}

View File

@@ -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);
}
}

View File

@@ -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 {

View File

@@ -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<String> 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);
}
}
}