提交 b2d40e43 编写于 作者: N Nikita

Fixed - tomcat session renewal. #1311

上级 2e7dc273
......@@ -192,6 +192,10 @@ public class RedissonSession extends StandardSession {
if (lastAccessedTime != null) {
this.lastAccessedTime = lastAccessedTime;
}
Integer maxInactiveInterval = (Integer) attrs.remove("session:maxInactiveInterval");
if (maxInactiveInterval != null) {
this.maxInactiveInterval = maxInactiveInterval;
}
Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime");
if (thisAccessedTime != null) {
this.thisAccessedTime = thisAccessedTime;
......
......@@ -152,6 +152,9 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
session.endAccess();
return session;
}
result.access();
result.endAccess();
return result;
}
......
......@@ -18,6 +18,33 @@ import org.redisson.config.Config;
public class RedissonSessionManagerTest {
@Test
public void testExpiration() throws Exception {
TomcatServer server1 = new TomcatServer("myapp", 8080, "/src/test/");
server1.start();
Executor executor = Executor.newInstance();
BasicCookieStore cookieStore = new BasicCookieStore();
executor.use(cookieStore);
write(executor, "test", "1234");
TomcatServer server2 = new TomcatServer("myapp", 8081, "/src/test/");
server2.start();
Thread.sleep(30000);
read(8081, executor, "test", "1234");
Thread.sleep(40000);
read(executor, "test", "1234");
Executor.closeIdleConnections();
server1.stop();
server2.stop();
}
@Test
public void testSwitchServer() throws LifecycleException, InterruptedException, ClientProtocolException, IOException {
// start the server at http://localhost:8080/myapp
......@@ -144,6 +171,12 @@ public class RedissonSessionManagerTest {
String response = executor.execute(Request.Get(url)).returnContent().asString();
Assert.assertEquals(value, response);
}
private void read(int port, Executor executor, String key, String value) throws IOException, ClientProtocolException {
String url = "http://localhost:" + port + "/myapp/read?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString();
Assert.assertEquals(value, response);
}
private void remove(Executor executor, String key, String value) throws IOException, ClientProtocolException {
String url = "http://localhost:8080/myapp/remove?key=" + key;
......
......@@ -16,7 +16,7 @@
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
<session-timeout>1</session-timeout>
</session-config>
</web-app>
......@@ -197,6 +197,10 @@ public class RedissonSession extends StandardSession {
if (lastAccessedTime != null) {
this.lastAccessedTime = lastAccessedTime;
}
Integer maxInactiveInterval = (Integer) attrs.remove("session:maxInactiveInterval");
if (maxInactiveInterval != null) {
this.maxInactiveInterval = maxInactiveInterval;
}
Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime");
if (thisAccessedTime != null) {
this.thisAccessedTime = thisAccessedTime;
......
......@@ -132,6 +132,9 @@ public class RedissonSessionManager extends ManagerBase {
return session;
}
result.access();
result.endAccess();
return result;
}
......
......@@ -17,6 +17,33 @@ import org.redisson.config.Config;
public class RedissonSessionManagerTest {
@Test
public void testExpiration() throws Exception {
TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
server1.start();
Executor executor = Executor.newInstance();
BasicCookieStore cookieStore = new BasicCookieStore();
executor.use(cookieStore);
write(executor, "test", "1234");
TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
server2.start();
Thread.sleep(30000);
read(8081, executor, "test", "1234");
Thread.sleep(40000);
read(executor, "test", "1234");
Executor.closeIdleConnections();
server1.stop();
server2.stop();
}
@Test
public void testSwitchServer() throws Exception {
// start the server at http://localhost:8080/myapp
......@@ -138,6 +165,12 @@ public class RedissonSessionManagerTest {
Assert.assertEquals("OK", response);
}
private void read(int port, Executor executor, String key, String value) throws IOException, ClientProtocolException {
String url = "http://localhost:" + port + "/myapp/read?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString();
Assert.assertEquals(value, response);
}
private void read(Executor executor, String key, String value) throws IOException, ClientProtocolException {
String url = "http://localhost:8080/myapp/read?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString();
......
......@@ -16,7 +16,7 @@
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
<session-timeout>1</session-timeout>
</session-config>
</web-app>
......@@ -197,6 +197,10 @@ public class RedissonSession extends StandardSession {
if (lastAccessedTime != null) {
this.lastAccessedTime = lastAccessedTime;
}
Integer maxInactiveInterval = (Integer) attrs.remove("session:maxInactiveInterval");
if (maxInactiveInterval != null) {
this.maxInactiveInterval = maxInactiveInterval;
}
Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime");
if (thisAccessedTime != null) {
this.thisAccessedTime = thisAccessedTime;
......
......@@ -131,6 +131,9 @@ public class RedissonSessionManager extends ManagerBase {
session.endAccess();
return session;
}
result.access();
result.endAccess();
return result;
}
......
......@@ -17,6 +17,34 @@ import org.redisson.config.Config;
public class RedissonSessionManagerTest {
@Test
public void testExpiration() throws Exception {
TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
server1.start();
Executor executor = Executor.newInstance();
BasicCookieStore cookieStore = new BasicCookieStore();
executor.use(cookieStore);
write(executor, "test", "1234");
TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
server2.start();
Thread.sleep(30000);
read(8081, executor, "test", "1234");
Thread.sleep(40000);
executor.use(cookieStore);
read(executor, "test", "1234");
Executor.closeIdleConnections();
server1.stop();
server2.stop();
}
@Test
public void testSwitchServer() throws Exception {
// start the server at http://localhost:8080/myapp
......@@ -138,6 +166,12 @@ public class RedissonSessionManagerTest {
Assert.assertEquals("OK", response);
}
private void read(int port, Executor executor, String key, String value) throws IOException, ClientProtocolException {
String url = "http://localhost:" + port + "/myapp/read?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString();
Assert.assertEquals(value, response);
}
private void read(Executor executor, String key, String value) throws IOException, ClientProtocolException {
String url = "http://localhost:8080/myapp/read?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString();
......
......@@ -16,7 +16,7 @@
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
<session-timeout>1</session-timeout>
</session-config>
</web-app>
......@@ -197,6 +197,10 @@ public class RedissonSession extends StandardSession {
if (lastAccessedTime != null) {
this.lastAccessedTime = lastAccessedTime;
}
Integer maxInactiveInterval = (Integer) attrs.remove("session:maxInactiveInterval");
if (maxInactiveInterval != null) {
this.maxInactiveInterval = maxInactiveInterval;
}
Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime");
if (thisAccessedTime != null) {
this.thisAccessedTime = thisAccessedTime;
......
......@@ -132,6 +132,9 @@ public class RedissonSessionManager extends ManagerBase {
return session;
}
result.access();
result.endAccess();
return result;
}
......
......@@ -17,10 +17,38 @@ import org.redisson.config.Config;
public class RedissonSessionManagerTest {
@Test
public void testExpiration() throws Exception {
TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
server1.start();
Executor executor = Executor.newInstance();
BasicCookieStore cookieStore = new BasicCookieStore();
executor.use(cookieStore);
write(executor, "test", "1234");
TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
server2.start();
Thread.sleep(30000);
read(8081, executor, "test", "1234");
Thread.sleep(40000);
executor.use(cookieStore);
read(executor, "test", "1234");
Executor.closeIdleConnections();
server1.stop();
server2.stop();
}
@Test
public void testSwitchServer() throws Exception {
// start the server at http://localhost:8080/myapp
TomcatServer server = new TomcatServer("/myapp", 8080, "src/test/");
TomcatServer server = new TomcatServer("myapp", 8080, "src/test/");
server.start();
Executor executor = Executor.newInstance();
......@@ -138,6 +166,12 @@ public class RedissonSessionManagerTest {
Assert.assertEquals("OK", response);
}
private void read(int port, Executor executor, String key, String value) throws IOException, ClientProtocolException {
String url = "http://localhost:" + port + "/myapp/read?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString();
Assert.assertEquals(value, response);
}
private void read(Executor executor, String key, String value) throws IOException, ClientProtocolException {
String url = "http://localhost:8080/myapp/read?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册