Fixed - Tomcat RedissonSessionManager doesn't remove session on invalidation/expiration. #972

pull/970/head
Nikita 8 years ago
parent cd4a848a42
commit 3c0449eda7

@ -1,6 +1,8 @@
package org.redisson.tomcat;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import org.apache.catalina.LifecycleException;
import org.apache.http.client.ClientProtocolException;
@ -10,6 +12,9 @@ import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
public class RedissonSessionManagerTest {
@ -95,7 +100,12 @@ public class RedissonSessionManagerTest {
@Test
public void testInvalidate() throws LifecycleException, InterruptedException, ClientProtocolException, IOException {
public void testInvalidate() throws Exception {
File f = Paths.get("").toAbsolutePath().resolve("src/test/webapp/WEB-INF/redisson.yaml").toFile();
Config config = Config.fromYAML(f);
RedissonClient r = Redisson.create(config);
r.getKeys().flushall();
// start the server at http://localhost:8080/myapp
TomcatServer server = new TomcatServer("myapp", 8080, "/src/test/");
server.start();
@ -115,9 +125,12 @@ public class RedissonSessionManagerTest {
cookieStore.addCookie(cookie);
executor.use(cookieStore);
read(executor, "test", "null");
invalidate(executor);
Executor.closeIdleConnections();
server.stop();
Assert.assertEquals(0, r.getKeys().count());
}
private void write(Executor executor, String key, String value) throws IOException, ClientProtocolException {

@ -56,6 +56,11 @@ public class RedissonSession extends StandardSession {
map = redissonManager.getMap(id);
}
public void delete() {
map.delete();
map = null;
}
@Override
public void setCreationTime(long time) {
super.setCreationTime(time);

@ -106,10 +106,12 @@ public class RedissonSessionManager extends ManagerBase {
}
@Override
public void remove(Session session) {
super.remove(session);
public void remove(Session session, boolean update) {
super.remove(session, update);
getMap(session.getId()).delete();
if (session.getIdInternal() != null) {
((RedissonSession)session).delete();
}
}
public RedissonClient getRedisson() {

@ -1,6 +1,8 @@
package org.redisson.tomcat;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.fluent.Executor;
@ -9,6 +11,9 @@ import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
public class RedissonSessionManagerTest {
@ -95,6 +100,11 @@ public class RedissonSessionManagerTest {
@Test
public void testInvalidate() throws Exception {
File f = Paths.get("").toAbsolutePath().resolve("src/test/webapp/WEB-INF/redisson.yaml").toFile();
Config config = Config.fromYAML(f);
RedissonClient r = Redisson.create(config);
r.getKeys().flushall();
// start the server at http://localhost:8080/myapp
TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
server.start();
@ -114,9 +124,12 @@ public class RedissonSessionManagerTest {
cookieStore.addCookie(cookie);
executor.use(cookieStore);
read(executor, "test", "null");
invalidate(executor);
Executor.closeIdleConnections();
server.stop();
Assert.assertEquals(0, r.getKeys().count());
}
private void write(Executor executor, String key, String value) throws IOException, ClientProtocolException {

@ -40,7 +40,6 @@ public class RedissonSession extends StandardSession {
public RedissonSession(RedissonSessionManager manager) {
super(manager);
this.redissonManager = manager;
try {
Field attr = StandardSession.class.getDeclaredField("attributes");
attrs = (Map<String, Object>) attr.get(this);
@ -57,6 +56,11 @@ public class RedissonSession extends StandardSession {
map = redissonManager.getMap(id);
}
public void delete() {
map.delete();
map = null;
}
@Override
public void setCreationTime(long time) {
super.setCreationTime(time);

@ -105,10 +105,12 @@ public class RedissonSessionManager extends ManagerBase {
}
@Override
public void remove(Session session) {
super.remove(session);
public void remove(Session session, boolean update) {
super.remove(session, update);
getMap(session.getId()).delete();
if (session.getIdInternal() != null) {
((RedissonSession)session).delete();
}
}
public RedissonClient getRedisson() {

@ -1,6 +1,8 @@
package org.redisson.tomcat;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.fluent.Executor;
@ -9,6 +11,9 @@ import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
public class RedissonSessionManagerTest {
@ -95,6 +100,11 @@ public class RedissonSessionManagerTest {
@Test
public void testInvalidate() throws Exception {
File f = Paths.get("").toAbsolutePath().resolve("src/test/webapp/WEB-INF/redisson.yaml").toFile();
Config config = Config.fromYAML(f);
RedissonClient r = Redisson.create(config);
r.getKeys().flushall();
// start the server at http://localhost:8080/myapp
TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
server.start();
@ -114,9 +124,12 @@ public class RedissonSessionManagerTest {
cookieStore.addCookie(cookie);
executor.use(cookieStore);
read(executor, "test", "null");
invalidate(executor);
Executor.closeIdleConnections();
server.stop();
Assert.assertEquals(0, r.getKeys().count());
}
private void write(Executor executor, String key, String value) throws IOException, ClientProtocolException {

@ -28,7 +28,7 @@ public class TomcatServer {
tomcat.setBaseDir("."); // location where temp dir is created
tomcat.setPort(port);
tomcat.getHost().setAppBase(".");
tomcat.getHost().setAppBase(appBase);
tomcat.addWebapp(contextPath, appBase + "webapp");
}

Loading…
Cancel
Save