Merge branch 'master' into 3.0.0

pull/1303/head
Nikita 7 years ago
commit ee21b88ec4

@ -17,7 +17,7 @@
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>catalina</artifactId>
<version>6.0.48</version>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>
</dependencies>

@ -17,25 +17,25 @@
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>7.0.73</version>
<version>7.0.84</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>7.0.73</version>
<version>7.0.84</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.73</version>
<version>7.0.84</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>7.0.73</version>
<version>7.0.84</version>
<scope>provided</scope>
</dependency>
</dependencies>

@ -17,25 +17,25 @@
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.0.39</version>
<version>8.0.48</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>8.0.39</version>
<version>8.0.48</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.0.39</version>
<version>8.0.48</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>8.0.39</version>
<version>8.0.48</version>
<scope>provided</scope>
</dependency>
</dependencies>

@ -17,25 +17,19 @@
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>9.0.0.M6</version>
<version>9.0.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.2</version>
<version>9.0.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.2</version>
<version>9.0.4</version>
<scope>provided</scope>
</dependency>
</dependencies>

@ -112,31 +112,31 @@
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>7.0.73</version>
<version>8.0.48</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>7.0.73</version>
<version>8.0.48</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.73</version>
<version>8.0.48</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>7.0.73</version>
<version>8.0.48</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
<version>4.5.2</version>
<version>4.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
@ -156,7 +156,7 @@
<dependency>
<groupId>org.msgpack</groupId>
<artifactId>jackson-dataformat-msgpack</artifactId>
<version>0.8.11</version>
<version>0.8.14</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
@ -193,7 +193,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.9</version>
<version>2.7.9.2</version>
</dependency>
<dependency>
@ -227,7 +227,7 @@
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.6.14</version>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.jodd</groupId>

@ -62,12 +62,13 @@ public class RedissonListMultimap<K, V> extends RedissonMultimap<K, V> implement
"local size = 0; " +
"for i, v in ipairs(keys) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[1] .. v; " +
"size = size + redis.call('llen', name); " +
"end;" +
"end; " +
"return size; ",
Arrays.<Object>asList(getName()));
Arrays.<Object>asList(getName()),
prefix);
}
@Override
@ -87,7 +88,7 @@ public class RedissonListMultimap<K, V> extends RedissonMultimap<K, V> implement
"local keys = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(keys) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[2] .. v; " +
"local items = redis.call('lrange', name, 0, -1) " +
"for i=1,#items do " +
@ -98,7 +99,8 @@ public class RedissonListMultimap<K, V> extends RedissonMultimap<K, V> implement
"end;" +
"end; " +
"return 0; ",
Arrays.<Object>asList(getName()), valueState);
Arrays.<Object>asList(getName()),
valueState, prefix);
}
@Override

@ -43,13 +43,13 @@ public class RedissonListMultimapCache<K, V> extends RedissonListMultimap<K, V>
RedissonListMultimapCache(UUID id, EvictionScheduler evictionScheduler, CommandAsyncExecutor connectionManager, String name) {
super(id, connectionManager, name);
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName());
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
}
RedissonListMultimapCache(UUID id, EvictionScheduler evictionScheduler, Codec codec, CommandAsyncExecutor connectionManager, String name) {
super(id, codec, connectionManager, name);
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName());
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
}
public RFuture<Boolean> containsKeyAsync(Object key) {
@ -76,7 +76,7 @@ public class RedissonListMultimapCache<K, V> extends RedissonListMultimap<K, V>
}
String getTimeoutSetName() {
return "redisson_list_multimap_ttl{" + getName() + "}";
return suffixName(getName(), "redisson_list_multimap_ttl");
}
@ -93,7 +93,7 @@ public class RedissonListMultimapCache<K, V> extends RedissonListMultimap<K, V>
+ "expireDate = tonumber(expireDateScore) "
+ "end; "
+ "if expireDate > tonumber(ARGV[2]) then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[3] .. v; " +
"local items = redis.call('lrange', name, 0, -1) " +
"for i=1,#items do " +
@ -106,7 +106,8 @@ public class RedissonListMultimapCache<K, V> extends RedissonListMultimap<K, V>
"end;" +
"end; " +
"return 0; ",
Arrays.<Object>asList(getName(), getTimeoutSetName()), valueState, System.currentTimeMillis());
Arrays.<Object>asList(getName(), getTimeoutSetName()),
valueState, System.currentTimeMillis(), prefix);
}
public RFuture<Boolean> containsEntryAsync(Object key, Object value) {
@ -130,7 +131,8 @@ public class RedissonListMultimapCache<K, V> extends RedissonListMultimap<K, V>
"end; " +
"end; " +
"return 0; ",
Arrays.<Object>asList(valuesName, getTimeoutSetName()), System.currentTimeMillis(), keyState, valueState);
Arrays.<Object>asList(valuesName, getTimeoutSetName()),
System.currentTimeMillis(), keyState, valueState);
}
@Override

@ -15,7 +15,6 @@
*/
package org.redisson;
import java.net.InetSocketAddress;
import java.util.AbstractCollection;
import java.util.AbstractSet;
import java.util.ArrayList;
@ -58,15 +57,18 @@ import io.netty.buffer.ByteBuf;
public abstract class RedissonMultimap<K, V> extends RedissonExpirable implements RMultimap<K, V> {
private final UUID id;
final String prefix;
RedissonMultimap(UUID id, CommandAsyncExecutor connectionManager, String name) {
super(connectionManager, name);
this.id = id;
prefix = suffixName(getName(), "");
}
RedissonMultimap(UUID id, Codec codec, CommandAsyncExecutor connectionManager, String name) {
super(codec, connectionManager, name);
this.id = id;
prefix = suffixName(getName(), "");
}
@Override
@ -139,7 +141,7 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
}
String getValuesName(String hash) {
return "{" + getName() + "}:" + hash;
return suffixName(getName(), hash);
}
@Override
@ -239,7 +241,7 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
"local keys = {KEYS[1]}; " +
"for i, v in ipairs(entries) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[1] .. v; " +
"table.insert(keys, name); " +
"end;" +
"end; " +
@ -249,7 +251,7 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
+ "n = n + redis.call('del', unpack(keys, i, math.min(i+4999, table.getn(keys)))) "
+ "end; "
+ "return n;",
Arrays.<Object>asList(getName()));
Arrays.<Object>asList(getName()), prefix);
}
@Override
@ -258,12 +260,13 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
"local entries = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(entries) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[2] .. v; " +
"redis.call('pexpire', name, ARGV[1]); " +
"end;" +
"end; " +
"return redis.call('pexpire', KEYS[1], ARGV[1]); ",
Arrays.<Object>asList(getName()), timeUnit.toMillis(timeToLive));
Arrays.<Object>asList(getName()),
timeUnit.toMillis(timeToLive), prefix);
}
@Override
@ -272,12 +275,13 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
"local entries = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(entries) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[2] .. v; " +
"redis.call('pexpireat', name, ARGV[1]); " +
"end;" +
"end; " +
"return redis.call('pexpireat', KEYS[1], ARGV[1]); ",
Arrays.<Object>asList(getName()), timestamp);
Arrays.<Object>asList(getName()),
timestamp, prefix);
}
@Override
@ -286,12 +290,13 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
"local entries = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(entries) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[1] .. v; " +
"redis.call('persist', name); " +
"end;" +
"end; " +
"return redis.call('persist', KEYS[1]); ",
Arrays.<Object>asList(getName()));
Arrays.<Object>asList(getName()),
prefix);
}
@Override

@ -24,16 +24,24 @@ import org.redisson.client.codec.LongCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor;
/**
*
* @author Nikita Koksharov
*
* @param <K> key type
*/
public class RedissonMultimapCache<K> {
private final CommandAsyncExecutor commandExecutor;
private final RObject object;
private final String timeoutSetName;
private final String prefix;
public RedissonMultimapCache(CommandAsyncExecutor commandExecutor, RObject object, String timeoutSetName) {
public RedissonMultimapCache(CommandAsyncExecutor commandExecutor, RObject object, String timeoutSetName, String prefix) {
this.commandExecutor = commandExecutor;
this.object = object;
this.timeoutSetName = timeoutSetName;
this.prefix = prefix;
}
public RFuture<Boolean> expireKeyAsync(K key, long timeToLive, TimeUnit timeUnit) {
@ -60,7 +68,7 @@ public class RedissonMultimapCache<K> {
"local keys = {KEYS[1], KEYS[2]}; " +
"for i, v in ipairs(entries) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[1] .. v; " +
"table.insert(keys, name); " +
"end;" +
"end; " +
@ -70,7 +78,8 @@ public class RedissonMultimapCache<K> {
+ "n = n + redis.call('del', unpack(keys, i, math.min(i+4999, table.getn(keys)))) "
+ "end; "
+ "return n;",
Arrays.<Object>asList(object.getName(), timeoutSetName));
Arrays.<Object>asList(object.getName(), timeoutSetName),
prefix);
}
public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit) {
@ -79,13 +88,14 @@ public class RedissonMultimapCache<K> {
"local entries = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(entries) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[2] .. v; " +
"redis.call('pexpire', name, ARGV[1]); " +
"end;" +
"end; " +
"redis.call('pexpire', KEYS[2], ARGV[1]); " +
"return redis.call('pexpire', KEYS[1], ARGV[1]); ",
Arrays.<Object>asList(object.getName(), timeoutSetName), timeUnit.toMillis(timeToLive));
Arrays.<Object>asList(object.getName(), timeoutSetName),
timeUnit.toMillis(timeToLive), prefix);
}
public RFuture<Boolean> expireAtAsync(long timestamp) {
@ -94,13 +104,14 @@ public class RedissonMultimapCache<K> {
"local entries = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(entries) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[2] .. v; " +
"redis.call('pexpireat', name, ARGV[1]); " +
"end;" +
"end; " +
"redis.call('pexpireat', KEYS[2], ARGV[1]); " +
"return redis.call('pexpireat', KEYS[1], ARGV[1]); ",
Arrays.<Object>asList(object.getName(), timeoutSetName), timestamp);
Arrays.<Object>asList(object.getName(), timeoutSetName),
timestamp, prefix);
}
public RFuture<Boolean> clearExpireAsync() {
@ -109,13 +120,14 @@ public class RedissonMultimapCache<K> {
"local entries = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(entries) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[1] .. v; " +
"redis.call('persist', name); " +
"end;" +
"end; " +
"redis.call('persist', KEYS[2]); " +
"return redis.call('persist', KEYS[1]); ",
Arrays.<Object>asList(object.getName(), timeoutSetName));
Arrays.<Object>asList(object.getName(), timeoutSetName),
prefix);
}

@ -203,6 +203,13 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
}
final RemoteServiceRequest request = future.getNow();
if (request == null) {
log.debug("Task can't be found for request: {}", requestId);
// re-subscribe after a skipped ackTimeout
subscribe(remoteInterface, requestQueue, executor);
return;
}
long elapsedTime = System.currentTimeMillis() - request.getDate();
// check the ack only if expected
if (request.getOptions().isAckExpected() && elapsedTime > request

@ -65,12 +65,13 @@ public class RedissonSetMultimap<K, V> extends RedissonMultimap<K, V> implements
"local size = 0; " +
"for i, v in ipairs(keys) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[1] .. v; " +
"size = size + redis.call('scard', name); " +
"end;" +
"end; " +
"return size; ",
Arrays.<Object>asList(getName()));
Arrays.<Object>asList(getName()),
prefix);
}
@Override
@ -90,14 +91,15 @@ public class RedissonSetMultimap<K, V> extends RedissonMultimap<K, V> implements
"local keys = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(keys) do " +
"if i % 2 == 0 then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[2] .. v; " +
"if redis.call('sismember', name, ARGV[1]) == 1 then "
+ "return 1; " +
"end;" +
"end;" +
"end; " +
"return 0; ",
Arrays.<Object>asList(getName()), valueState);
Arrays.<Object>asList(getName()),
valueState, prefix);
}
@Override

@ -43,13 +43,13 @@ public class RedissonSetMultimapCache<K, V> extends RedissonSetMultimap<K, V> im
RedissonSetMultimapCache(UUID id, EvictionScheduler evictionScheduler, CommandAsyncExecutor connectionManager, String name) {
super(id, connectionManager, name);
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName());
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
}
RedissonSetMultimapCache(UUID id, EvictionScheduler evictionScheduler, Codec codec, CommandAsyncExecutor connectionManager, String name) {
super(id, codec, connectionManager, name);
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName());
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
}
@Override
@ -73,11 +73,12 @@ public class RedissonSetMultimapCache<K, V> extends RedissonSetMultimap<K, V> im
+ "return redis.call('scard', ARGV[3]) > 0 and 1 or 0;" +
"end;" +
"return 0; ",
Arrays.<Object>asList(getName(), getTimeoutSetName()), System.currentTimeMillis(), keyState, setName);
Arrays.<Object>asList(getName(), getTimeoutSetName()),
System.currentTimeMillis(), keyState, setName);
}
String getTimeoutSetName() {
return "redisson_set_multimap_ttl{" + getName() + "}";
return suffixName(getName(), "redisson_set_multimap_ttl");
}
@ -95,7 +96,7 @@ public class RedissonSetMultimapCache<K, V> extends RedissonSetMultimap<K, V> im
+ "expireDate = tonumber(expireDateScore) "
+ "end; "
+ "if expireDate > tonumber(ARGV[2]) then " +
"local name = '{' .. KEYS[1] .. '}:' .. v; " +
"local name = ARGV[3] .. v; " +
"if redis.call('sismember', name, ARGV[1]) == 1 then "
+ "return 1; " +
"end;" +
@ -103,7 +104,8 @@ public class RedissonSetMultimapCache<K, V> extends RedissonSetMultimap<K, V> im
"end;" +
"end; " +
"return 0; ",
Arrays.<Object>asList(getName(), getTimeoutSetName()), valueState, System.currentTimeMillis());
Arrays.<Object>asList(getName(), getTimeoutSetName()),
valueState, System.currentTimeMillis(), prefix);
}
@Override

@ -17,6 +17,7 @@ package org.redisson.client.codec;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
@ -52,7 +53,7 @@ public class JsonJacksonMapCodec extends JsonJacksonCodec {
ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
try {
ByteBufOutputStream os = new ByteBufOutputStream(out);
mapper.writeValue(os, in);
mapper.writeValue((OutputStream)os, in);
return os.buffer();
} catch (IOException e) {
out.release();

@ -17,6 +17,7 @@ package org.redisson.codec;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.datatype.XMLGregorianCalendar;
@ -72,7 +73,7 @@ public class JsonJacksonCodec implements Codec {
ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
try {
ByteBufOutputStream os = new ByteBufOutputStream(out);
mapObjectMapper.writeValue(os, in);
mapObjectMapper.writeValue((OutputStream)os, in);
return os.buffer();
} catch (IOException e) {
out.release();

@ -107,13 +107,13 @@ public interface ConnectionManager {
RFuture<PubSubConnectionEntry> psubscribe(String pattern, Codec codec, AsyncSemaphore semaphore, RedisPubSubListener<?>... listeners);
Codec unsubscribe(String channelName, AsyncSemaphore lock);
void unsubscribe(String channelName, AsyncSemaphore lock);
RFuture<Codec> unsubscribe(String channelName, boolean temporaryDown);
RFuture<Codec> punsubscribe(String channelName, boolean temporaryDown);
Codec punsubscribe(String channelName, AsyncSemaphore lock);
void punsubscribe(String channelName, AsyncSemaphore lock);
void shutdown();

@ -587,14 +587,13 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
});
}
public Codec unsubscribe(final String channelName, final AsyncSemaphore lock) {
public void unsubscribe(final String channelName, final AsyncSemaphore lock) {
final PubSubConnectionEntry entry = name2PubSubConnection.remove(channelName);
if (entry == null) {
lock.release();
return null;
return;
}
Codec entryCodec = entry.getConnection().getChannels().get(channelName);
entry.unsubscribe(channelName, new BaseRedisPubSubListener() {
@Override
@ -612,8 +611,6 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
}
});
return entryCodec;
}
@Override
@ -645,14 +642,13 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
return RedissonPromise.newSucceededFuture(entryCodec);
}
public Codec punsubscribe(final String channelName, final AsyncSemaphore lock) {
public void punsubscribe(final String channelName, final AsyncSemaphore lock) {
final PubSubConnectionEntry entry = name2PubSubConnection.remove(channelName);
if (entry == null) {
lock.release();
return null;
return;
}
Codec entryCodec = entry.getConnection().getPatternChannels().get(channelName);
entry.punsubscribe(channelName, new BaseRedisPubSubListener() {
@Override
@ -670,8 +666,6 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
}
});
return entryCodec;
}

@ -83,6 +83,9 @@ public class AccessorInterceptor {
}
}
if (result != null && fieldType.isEnum()) {
return Enum.valueOf((Class)fieldType, (String)result);
}
if (result instanceof RedissonReference) {
return RedissonObjectFactory.fromReference(redisson, (RedissonReference) result);
}

@ -0,0 +1,172 @@
package org.redisson;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.redisson.api.RMultimapCache;
public abstract class RedissonBaseMultimapCacheTest extends BaseTest {
abstract RMultimapCache<String, String> getMultimapCache(String name);
@Test
public void testContains() {
RMultimapCache<String, String> multimap = getMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
assertThat(multimap.containsKey("1")).isTrue();
assertThat(multimap.containsKey("2")).isFalse();
assertThat(multimap.containsValue("1")).isTrue();
assertThat(multimap.containsValue("3")).isTrue();
assertThat(multimap.containsValue("4")).isFalse();
assertThat(multimap.containsEntry("1", "1")).isTrue();
assertThat(multimap.containsEntry("1", "3")).isTrue();
assertThat(multimap.containsEntry("1", "4")).isFalse();
}
@Test
public void testContainsExpired() throws InterruptedException {
RMultimapCache<String, String> multimap = getMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.expireKey("1", 1, TimeUnit.SECONDS);
Thread.sleep(1000);
assertThat(multimap.containsKey("1")).isFalse();
assertThat(multimap.containsKey("2")).isFalse();
assertThat(multimap.containsValue("1")).isFalse();
assertThat(multimap.containsValue("3")).isFalse();
assertThat(multimap.containsValue("4")).isFalse();
assertThat(multimap.containsEntry("1", "1")).isFalse();
assertThat(multimap.containsEntry("1", "3")).isFalse();
assertThat(multimap.containsEntry("1", "4")).isFalse();
}
@Test
public void testGetAll() throws InterruptedException {
RMultimapCache<String, String> multimap = getMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
assertThat(multimap.getAll("1")).containsOnlyOnce("1", "2", "3");
}
@Test
public void testGetAllExpired() throws InterruptedException {
RMultimapCache<String, String> multimap = getMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.expireKey("1", 1, TimeUnit.SECONDS);
Thread.sleep(1000);
assertThat(multimap.getAll("1")).isEmpty();
}
@Test
public void testValuesExpired() throws InterruptedException {
RMultimapCache<String, String> multimap = getMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.expireKey("1", 1, TimeUnit.SECONDS);
Thread.sleep(1500);
assertThat(multimap.get("1").size()).isZero();
assertThat(multimap.get("1").isEmpty()).isTrue();
assertThat(multimap.get("1").remove("3")).isFalse();
assertThat(multimap.get("1").contains("3")).isFalse();
assertThat(multimap.get("1").retainAll(Arrays.asList("1"))).isFalse();
assertThat(multimap.get("1").containsAll(Arrays.asList("1"))).isFalse();
assertThat(multimap.get("1").removeAll(Arrays.asList("1"))).isFalse();
}
@Test
public void testScheduler() throws InterruptedException {
RMultimapCache<String, String> cache = getMultimapCache("simple33");
assertThat(cache.put("1", "1")).isTrue();
assertThat(cache.put("1", "2")).isTrue();
assertThat(cache.put("1", "3")).isTrue();
assertThat(cache.put("2", "1")).isTrue();
assertThat(cache.put("2", "2")).isTrue();
assertThat(cache.put("2", "3")).isTrue();
assertThat(cache.expireKey("1", 2, TimeUnit.SECONDS)).isTrue();
assertThat(cache.expireKey("2", 3, TimeUnit.SECONDS)).isTrue();
assertThat(cache.expireKey("3", 3, TimeUnit.SECONDS)).isFalse();
assertThat(cache.size()).isEqualTo(6);
Thread.sleep(10000);
assertThat(cache.size()).isZero();
}
@Test
public void testExpire() throws InterruptedException {
RMultimapCache<String, String> map = getMultimapCache("simple");
map.put("1", "2");
map.put("2", "3");
map.expire(100, TimeUnit.MILLISECONDS);
Thread.sleep(500);
assertThat(map.size()).isZero();
}
@Test
public void testExpireAt() throws InterruptedException {
RMultimapCache<String, String> map = getMultimapCache("simple");
map.put("1", "2");
map.put("2", "3");
map.expireAt(System.currentTimeMillis() + 100);
Thread.sleep(500);
assertThat(map.size()).isZero();
}
@Test
public void testClearExpire() throws InterruptedException {
RMultimapCache<String, String> map = getMultimapCache("simple");
map.put("1", "2");
map.put("2", "3");
map.expireAt(System.currentTimeMillis() + 100);
map.clearExpire();
Thread.sleep(500);
assertThat(map.size()).isEqualTo(2);
}
@Test
public void testDelete() {
RMultimapCache<String, String> map = getMultimapCache("simple");
map.put("1", "2");
map.put("2", "3");
assertThat(map.delete()).isTrue();
RMultimapCache<String, String> map2 = getMultimapCache("simple1");
assertThat(map2.delete()).isFalse();
}
}

@ -3,80 +3,20 @@ package org.redisson;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.redisson.api.RMultimapCache;
public class RedissonListMultimapCacheTest extends BaseTest {
public class RedissonListMultimapCacheTest extends RedissonBaseMultimapCacheTest {
@Test
public void testContains() {
RMultimapCache<String, String> multimap = redisson.getListMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
assertThat(multimap.containsKey("1")).isTrue();
assertThat(multimap.containsKey("2")).isFalse();
assertThat(multimap.containsValue("1")).isTrue();
assertThat(multimap.containsValue("3")).isTrue();
assertThat(multimap.containsValue("4")).isFalse();
assertThat(multimap.containsEntry("1", "1")).isTrue();
assertThat(multimap.containsEntry("1", "3")).isTrue();
assertThat(multimap.containsEntry("1", "4")).isFalse();
}
@Test
public void testContainsExpired() throws InterruptedException {
RMultimapCache<String, String> multimap = redisson.getListMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.expireKey("1", 1, TimeUnit.SECONDS);
Thread.sleep(1000);
assertThat(multimap.containsKey("1")).isFalse();
assertThat(multimap.containsKey("2")).isFalse();
assertThat(multimap.containsValue("1")).isFalse();
assertThat(multimap.containsValue("3")).isFalse();
assertThat(multimap.containsValue("4")).isFalse();
assertThat(multimap.containsEntry("1", "1")).isFalse();
assertThat(multimap.containsEntry("1", "3")).isFalse();
assertThat(multimap.containsEntry("1", "4")).isFalse();
}
@Test
public void testGetAll() throws InterruptedException {
RMultimapCache<String, String> multimap = redisson.getListMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
assertThat(multimap.getAll("1")).containsOnlyOnce("1", "2", "3");
}
@Test
public void testGetAllExpired() throws InterruptedException {
RMultimapCache<String, String> multimap = redisson.getListMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.expireKey("1", 1, TimeUnit.SECONDS);
Thread.sleep(1000);
assertThat(multimap.getAll("1")).isEmpty();
@Override
RMultimapCache<String, String> getMultimapCache(String name) {
return redisson.getListMultimapCache(name);
}
@Test
public void testValues() throws InterruptedException {
RMultimapCache<String, String> multimap = redisson.getListMultimapCache("test");
RMultimapCache<String, String> multimap = getMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
@ -86,6 +26,7 @@ public class RedissonListMultimapCacheTest extends BaseTest {
assertThat(multimap.get("1")).containsExactly("1", "2", "3", "3");
assertThat(multimap.get("1").remove("3")).isTrue();
assertThat(multimap.get("1").remove("3")).isTrue();
assertThat(multimap.get("1").remove("3")).isFalse();
assertThat(multimap.get("1").contains("3")).isFalse();
assertThat(multimap.get("1").contains("2")).isTrue();
assertThat(multimap.get("1").containsAll(Arrays.asList("1"))).isTrue();
@ -94,46 +35,4 @@ public class RedissonListMultimapCacheTest extends BaseTest {
assertThat(multimap.get("1").removeAll(Arrays.asList("1"))).isTrue();
}
@Test
public void testValuesExpired() throws InterruptedException {
RMultimapCache<String, String> multimap = redisson.getListMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.expireKey("1", 1, TimeUnit.SECONDS);
Thread.sleep(1000);
assertThat(multimap.get("1").size()).isZero();
assertThat(multimap.get("1").isEmpty()).isTrue();
assertThat(multimap.get("1").remove("3")).isFalse();
assertThat(multimap.get("1").contains("3")).isFalse();
assertThat(multimap.get("1").retainAll(Arrays.asList("1"))).isFalse();
assertThat(multimap.get("1").containsAll(Arrays.asList("1"))).isFalse();
assertThat(multimap.get("1").removeAll(Arrays.asList("1"))).isFalse();
}
@Test
public void testScheduler() throws InterruptedException {
RMultimapCache<String, String> cache = redisson.getListMultimapCache("simple33");
assertThat(cache.put("1", "1")).isTrue();
assertThat(cache.put("1", "2")).isTrue();
assertThat(cache.put("1", "3")).isTrue();
assertThat(cache.put("2", "1")).isTrue();
assertThat(cache.put("2", "2")).isTrue();
assertThat(cache.put("2", "3")).isTrue();
assertThat(cache.expireKey("1", 2, TimeUnit.SECONDS)).isTrue();
assertThat(cache.expireKey("2", 3, TimeUnit.SECONDS)).isTrue();
assertThat(cache.expireKey("3", 3, TimeUnit.SECONDS)).isFalse();
assertThat(cache.size()).isEqualTo(6);
Thread.sleep(10000);
assertThat(cache.size()).isZero();
}
}

@ -161,7 +161,7 @@ public class RedissonListMultimapTest extends BaseTest {
@Test
public void testPut() {
RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("test1");
RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("{multi.map}.some.key");
map.put(new SimpleKey("0"), new SimpleValue("1"));
map.put(new SimpleKey("0"), new SimpleValue("2"));
map.put(new SimpleKey("0"), new SimpleValue("3"));
@ -219,7 +219,7 @@ public class RedissonListMultimapTest extends BaseTest {
@Test
public void testContainsValue() {
RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("test1");
RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("{1}test1");
map.put(new SimpleKey("0"), new SimpleValue("1"));
assertThat(map.containsValue(new SimpleValue("1"))).isTrue();

@ -26,6 +26,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.redisson.RedissonLiveObjectServiceTest.TestEnum.MyEnum;
import org.redisson.api.RBlockingDeque;
import org.redisson.api.RBlockingQueue;
import org.redisson.api.RCascadeType;
@ -43,7 +44,6 @@ import org.redisson.api.annotation.RCascade;
import org.redisson.api.annotation.REntity;
import org.redisson.api.annotation.RFieldAccessor;
import org.redisson.api.annotation.RId;
import org.redisson.client.RedisException;
import org.redisson.liveobject.resolver.DefaultNamingScheme;
import org.redisson.liveobject.resolver.LongGenerator;
import org.redisson.liveobject.resolver.UUIDGenerator;
@ -54,6 +54,39 @@ import org.redisson.liveobject.resolver.UUIDGenerator;
*/
public class RedissonLiveObjectServiceTest extends BaseTest {
@REntity
public static class TestEnum implements Serializable {
public enum MyEnum {A, B}
@RId
private String id;
private MyEnum myEnum1;
private MyEnum myEnum2;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public MyEnum getMyEnum1() {
return myEnum1;
}
public void setMyEnum1(MyEnum myEnum1) {
this.myEnum1 = myEnum1;
}
public MyEnum getMyEnum2() {
return myEnum2;
}
public void setMyEnum2(MyEnum myEnum2) {
this.myEnum2 = myEnum2;
}
}
@REntity
public static class TestREntity implements Comparable<TestREntity>, Serializable {
@ -1502,6 +1535,25 @@ public class RedissonLiveObjectServiceTest extends BaseTest {
}
}
@Test
public void testEnum() {
RLiveObjectService liveObjectService = redisson.getLiveObjectService();
liveObjectService.registerClass(TestEnum.class);
String id = "1";
TestEnum entry = new TestEnum();
entry.setId(id);
entry.setMyEnum1(MyEnum.A);
entry = liveObjectService.persist(entry);
TestEnum liveEntry = liveObjectService.get(TestEnum.class, id);
assertThat(liveEntry.getMyEnum1()).isEqualTo(MyEnum.A);
assertThat(liveEntry.getMyEnum2()).isNull();
entry.setMyEnum2(MyEnum.B);
assertThat(liveEntry.getMyEnum2()).isEqualTo(MyEnum.B);
}
@Test
public void testInheritedREntity() {
Dog d = new Dog("Fido");

@ -3,88 +3,27 @@ package org.redisson;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.redisson.api.RMultimapCache;
import org.redisson.api.RSetMultimap;
public class RedissonSetMultimapCacheTest extends BaseTest {
public class RedissonSetMultimapCacheTest extends RedissonBaseMultimapCacheTest {
@Test
public void testContains() {
RMultimapCache<String, String> multimap = redisson.getSetMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
assertThat(multimap.containsKey("1")).isTrue();
assertThat(multimap.containsKey("2")).isFalse();
assertThat(multimap.containsValue("1")).isTrue();
assertThat(multimap.containsValue("3")).isTrue();
assertThat(multimap.containsValue("4")).isFalse();
assertThat(multimap.containsEntry("1", "1")).isTrue();
assertThat(multimap.containsEntry("1", "3")).isTrue();
assertThat(multimap.containsEntry("1", "4")).isFalse();
}
@Test
public void testContainsExpired() throws InterruptedException {
RMultimapCache<String, String> multimap = redisson.getSetMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.expireKey("1", 1, TimeUnit.SECONDS);
Thread.sleep(1000);
assertThat(multimap.containsKey("1")).isFalse();
assertThat(multimap.containsKey("2")).isFalse();
assertThat(multimap.containsValue("1")).isFalse();
assertThat(multimap.containsValue("3")).isFalse();
assertThat(multimap.containsValue("4")).isFalse();
assertThat(multimap.containsEntry("1", "1")).isFalse();
assertThat(multimap.containsEntry("1", "3")).isFalse();
assertThat(multimap.containsEntry("1", "4")).isFalse();
}
@Test
public void testGetAll() throws InterruptedException {
RMultimapCache<String, String> multimap = redisson.getSetMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
assertThat(multimap.getAll("1")).containsOnlyOnce("1", "2", "3");
}
@Test
public void testGetAllExpired() throws InterruptedException {
RMultimapCache<String, String> multimap = redisson.getSetMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.expireKey("1", 1, TimeUnit.SECONDS);
Thread.sleep(1000);
assertThat(multimap.getAll("1")).isEmpty();
@Override
RMultimapCache<String, String> getMultimapCache(String name) {
return redisson.getSetMultimapCache(name);
}
@Test
public void testValues() throws InterruptedException {
RMultimapCache<String, String> multimap = redisson.getSetMultimapCache("test");
RMultimapCache<String, String> multimap = getMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.put("1", "3");
assertThat(multimap.get("1").size()).isEqualTo(3);
assertThat(multimap.get("1")).containsOnlyOnce("1", "2", "3");
assertThat(multimap.get("1")).containsExactlyInAnyOrder("1", "2", "3");
assertThat(multimap.get("1").remove("3")).isTrue();
assertThat(multimap.get("1").contains("3")).isFalse();
assertThat(multimap.get("1").contains("2")).isTrue();
@ -94,97 +33,4 @@ public class RedissonSetMultimapCacheTest extends BaseTest {
assertThat(multimap.get("1").removeAll(Arrays.asList("1"))).isTrue();
}
@Test
public void testValuesExpired() throws InterruptedException {
RMultimapCache<String, String> multimap = redisson.getSetMultimapCache("test");
multimap.put("1", "1");
multimap.put("1", "2");
multimap.put("1", "3");
multimap.expireKey("1", 1, TimeUnit.SECONDS);
Thread.sleep(1500);
assertThat(multimap.get("1").size()).isZero();
assertThat(multimap.get("1").isEmpty()).isTrue();
assertThat(multimap.get("1").remove("3")).isFalse();
assertThat(multimap.get("1").contains("3")).isFalse();
assertThat(multimap.get("1").retainAll(Arrays.asList("1"))).isFalse();
assertThat(multimap.get("1").containsAll(Arrays.asList("1"))).isFalse();
assertThat(multimap.get("1").removeAll(Arrays.asList("1"))).isFalse();
}
@Test
public void testScheduler() throws InterruptedException {
RMultimapCache<String, String> cache = redisson.getSetMultimapCache("simple33");
assertThat(cache.put("1", "1")).isTrue();
assertThat(cache.put("1", "2")).isTrue();
assertThat(cache.put("1", "3")).isTrue();
assertThat(cache.put("2", "1")).isTrue();
assertThat(cache.put("2", "2")).isTrue();
assertThat(cache.put("2", "3")).isTrue();
assertThat(cache.expireKey("1", 2, TimeUnit.SECONDS)).isTrue();
assertThat(cache.expireKey("2", 3, TimeUnit.SECONDS)).isTrue();
assertThat(cache.expireKey("3", 3, TimeUnit.SECONDS)).isFalse();
assertThat(cache.size()).isEqualTo(6);
Thread.sleep(10000);
assertThat(cache.size()).isZero();
}
@Test
public void testExpire() throws InterruptedException {
RSetMultimap<String, String> map = redisson.getSetMultimapCache("simple");
map.put("1", "2");
map.put("2", "3");
map.expire(100, TimeUnit.MILLISECONDS);
Thread.sleep(500);
assertThat(map.size()).isZero();
}
@Test
public void testExpireAt() throws InterruptedException {
RSetMultimap<String, String> map = redisson.getSetMultimapCache("simple");
map.put("1", "2");
map.put("2", "3");
map.expireAt(System.currentTimeMillis() + 100);
Thread.sleep(500);
assertThat(map.size()).isZero();
}
@Test
public void testClearExpire() throws InterruptedException {
RSetMultimap<String, String> map = redisson.getSetMultimapCache("simple");
map.put("1", "2");
map.put("2", "3");
map.expireAt(System.currentTimeMillis() + 100);
map.clearExpire();
Thread.sleep(500);
assertThat(map.size()).isEqualTo(2);
}
@Test
public void testDelete() {
RSetMultimap<String, String> map = redisson.getSetMultimapCache("simple");
map.put("1", "2");
map.put("2", "3");
assertThat(map.delete()).isTrue();
RSetMultimap<String, String> map2 = redisson.getSetMultimapCache("simple1");
assertThat(map2.delete()).isFalse();
}
}

@ -9,7 +9,8 @@ import javax.servlet.ServletException;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.startup.Tomcat;
import org.apache.naming.resources.VirtualDirContext;
import org.apache.catalina.webresources.DirResourceSet;
import org.apache.catalina.webresources.StandardRoot;
public class TomcatServer {
@ -32,8 +33,11 @@ public class TomcatServer {
ctx.setDelegate(true);
File additionWebInfClasses = new File("target/test-classes");
VirtualDirContext resources = new VirtualDirContext();
resources.setExtraResourcePaths("/WEB-INF/classes=" + additionWebInfClasses);
StandardRoot resources = new StandardRoot();
DirResourceSet webResourceSet = new DirResourceSet();
webResourceSet.setBase(additionWebInfClasses.toString());
webResourceSet.setWebAppMount("/WEB-INF/classes");
resources.addPostResources(webResourceSet);
ctx.setResources(resources);
}

Loading…
Cancel
Save