RedissonMapTest added

pull/6/head
Nikita 11 years ago
parent e2f47e7b48
commit e00d03f1db

@ -0,0 +1,126 @@
package org.redisson;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
public class RedissonMapTest {
public static class SimpleKey {
private String key;
public SimpleKey() {
}
public SimpleKey(String field) {
this.key = field;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override
public String toString() {
return "key: " + key;
}
}
public static class SimpleValue {
private String value;
public SimpleValue() {
}
public SimpleValue(String field) {
this.value = field;
}
public void setValue(String field) {
this.value = field;
}
public String getValue() {
return value;
}
@Override
public String toString() {
return "value: " + value;
}
}
@Test
public void testReplace() {
Redisson redisson = Redisson.create();
Map<SimpleKey, SimpleValue> map = redisson.getMap("simple");
map.put(new SimpleKey("1"), new SimpleValue("2"));
map.put(new SimpleKey("33"), new SimpleValue("44"));
map.put(new SimpleKey("5"), new SimpleValue("6"));
SimpleValue val1 = map.get(new SimpleKey("33"));
Assert.assertEquals("44", val1.getValue());
map.put(new SimpleKey("33"), new SimpleValue("abc"));
SimpleValue val2 = map.get(new SimpleKey("33"));
Assert.assertEquals("abc", val2.getValue());
clear(map);
}
@Test
public void testPutGet() {
Redisson redisson = Redisson.create();
Map<SimpleKey, SimpleValue> map = redisson.getMap("simple");
map.put(new SimpleKey("1"), new SimpleValue("2"));
map.put(new SimpleKey("33"), new SimpleValue("44"));
map.put(new SimpleKey("5"), new SimpleValue("6"));
SimpleValue val1 = map.get(new SimpleKey("33"));
Assert.assertEquals("44", val1.getValue());
SimpleValue val2 = map.get(new SimpleKey("5"));
Assert.assertEquals("6", val2.getValue());
clear(map);
}
private void clear(Map<?, ?> map) {
map.clear();
Assert.assertEquals(0, map.size());
}
@Test
public void testSize() {
Redisson redisson = Redisson.create();
Map<SimpleKey, SimpleValue> map = redisson.getMap("simple");
map.put(new SimpleKey("1"), new SimpleValue("2"));
map.put(new SimpleKey("3"), new SimpleValue("4"));
map.put(new SimpleKey("5"), new SimpleValue("6"));
Assert.assertEquals(3, map.size());
map.put(new SimpleKey("1"), new SimpleValue("2"));
map.put(new SimpleKey("3"), new SimpleValue("4"));
Assert.assertEquals(3, map.size());
map.put(new SimpleKey("1"), new SimpleValue("21"));
map.put(new SimpleKey("3"), new SimpleValue("41"));
Assert.assertEquals(3, map.size());
map.put(new SimpleKey("51"), new SimpleValue("6"));
Assert.assertEquals(4, map.size());
clear(map);
}
}
Loading…
Cancel
Save