From 4ce7820fdc3680bbdd3f89de489a933f0e6307ec Mon Sep 17 00:00:00 2001 From: seakider Date: Sun, 9 Mar 2025 22:02:57 +0800 Subject: [PATCH] Fixed - Inconsistent MaxInactiveInterval Setting in Sessions in multi-node Signed-off-by: seakider --- .../org/redisson/tomcat/RedissonSession.java | 2 +- .../tomcat/RedissonSessionManager.java | 4 +- .../tomcat/RedissonSessionManagerTest.java | 41 ++++++++++++++++++- .../java/org/redisson/tomcat/TestServlet.java | 22 +++++++++- .../org/redisson/tomcat/RedissonSession.java | 2 +- .../tomcat/RedissonSessionManager.java | 4 +- .../tomcat/RedissonSessionManagerTest.java | 39 ++++++++++++++++++ .../java/org/redisson/tomcat/TestServlet.java | 22 +++++++++- .../org/redisson/tomcat/RedissonSession.java | 2 +- .../tomcat/RedissonSessionManager.java | 4 +- .../tomcat/RedissonSessionManagerTest.java | 40 ++++++++++++++++++ .../java/org/redisson/tomcat/TestServlet.java | 22 +++++++++- .../org/redisson/tomcat/RedissonSession.java | 2 +- .../tomcat/RedissonSessionManager.java | 4 +- .../tomcat/RedissonSessionManagerTest.java | 39 ++++++++++++++++++ .../java/org/redisson/tomcat/TestServlet.java | 22 +++++++++- .../org/redisson/tomcat/RedissonSession.java | 2 +- .../tomcat/RedissonSessionManager.java | 4 +- .../tomcat/RedissonSessionManagerTest.java | 41 ++++++++++++++++++- .../java/org/redisson/tomcat/TestServlet.java | 22 +++++++++- 20 files changed, 323 insertions(+), 17 deletions(-) diff --git a/redisson-tomcat/redisson-tomcat-10/src/main/java/org/redisson/tomcat/RedissonSession.java b/redisson-tomcat/redisson-tomcat-10/src/main/java/org/redisson/tomcat/RedissonSession.java index 3c41d2e28..4e90adede 100644 --- a/redisson-tomcat/redisson-tomcat-10/src/main/java/org/redisson/tomcat/RedissonSession.java +++ b/redisson-tomcat/redisson-tomcat-10/src/main/java/org/redisson/tomcat/RedissonSession.java @@ -263,7 +263,7 @@ public class RedissonSession extends StandardSession { return; } m.fastPut(name, value); - if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) { + if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || this.broadcastSessionEvents) { try { Encoder encoder = m.getCodec().getMapValueEncoder(); topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder)); diff --git a/redisson-tomcat/redisson-tomcat-10/src/main/java/org/redisson/tomcat/RedissonSessionManager.java b/redisson-tomcat/redisson-tomcat-10/src/main/java/org/redisson/tomcat/RedissonSessionManager.java index da96f1651..e8797ddb0 100644 --- a/redisson-tomcat/redisson-tomcat-10/src/main/java/org/redisson/tomcat/RedissonSessionManager.java +++ b/redisson-tomcat/redisson-tomcat-10/src/main/java/org/redisson/tomcat/RedissonSessionManager.java @@ -324,7 +324,9 @@ public class RedissonSessionManager extends ManagerBase { if (msg instanceof AttributeUpdateMessage) { AttributeUpdateMessage m = (AttributeUpdateMessage)msg; - session.superSetAttribute(m.getName(), m.getValue(codecToUse.getMapValueDecoder()), true); + Map attrs = new HashMap<>(); + attrs.put(m.getName(), m.getValue(codecToUse.getMapValueDecoder())); + session.load(attrs); } } else { if (msg instanceof SessionCreatedMessage) { diff --git a/redisson-tomcat/redisson-tomcat-10/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java b/redisson-tomcat/redisson-tomcat-10/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java index c900cd9b1..397feabdd 100644 --- a/redisson-tomcat/redisson-tomcat-10/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java +++ b/redisson-tomcat/redisson-tomcat-10/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java @@ -40,7 +40,34 @@ public class RedissonSessionManagerTest { Files.deleteIfExists(Paths.get(basePath + "context.xml")); Files.copy(Paths.get(basePath + contextName), Paths.get(basePath + "context.xml")); } - + + @ParameterizedTest + @MethodSource("data") + public void testUpdateMaxInactiveInterval(String contextName) throws Exception { + prepare(contextName); + TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/"); + TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/"); + try { + server1.start(); + server2.start(); + + Executor executor = Executor.newInstance(); + BasicCookieStore cookieStore = new BasicCookieStore(); + executor.use(cookieStore); + + write(8080, executor, "test", "from_server1"); + write(8081, executor, "test", "from_server2"); + + writeInternal(8080, executor, 3000); + readInternal(8081, executor, 3000); + + } finally { + Executor.closeIdleConnections(); + server1.stop(); + server2.stop(); + } + } + @ParameterizedTest @MethodSource("data") public void testUpdateTwoServers_readValue(String contextName) throws Exception { @@ -376,6 +403,18 @@ public class RedissonSessionManagerTest { Assertions.assertEquals(value, response); } + private void writeInternal(int port, Executor executor, Object value) throws IOException { + String url = "http://localhost:" + port + "/myapp/writeInternal?value=" + value; + String response = executor.execute(Request.Get(url)).returnContent().asString(); + Assertions.assertEquals("OK", response); + } + + private void readInternal(int port, Executor executor, Object value) throws IOException { + String url = "http://localhost:" + port + "/myapp/readInternal"; + String response = executor.execute(Request.Get(url)).returnContent().asString(); + Assertions.assertEquals(value.toString(), response); + } + private void remove(Executor executor, String key, String value) throws IOException { String url = "http://localhost:8080/myapp/remove?key=" + key; String response = executor.execute(Request.Get(url)).returnContent().asString(); diff --git a/redisson-tomcat/redisson-tomcat-10/src/test/java/org/redisson/tomcat/TestServlet.java b/redisson-tomcat/redisson-tomcat-10/src/test/java/org/redisson/tomcat/TestServlet.java index 0d686ca98..78aaf80f4 100644 --- a/redisson-tomcat/redisson-tomcat-10/src/test/java/org/redisson/tomcat/TestServlet.java +++ b/redisson-tomcat/redisson-tomcat-10/src/test/java/org/redisson/tomcat/TestServlet.java @@ -73,7 +73,27 @@ public class TestServlet extends HttpServlet { Object attr = session.getAttribute(key); resp.getWriter().print(attr); - } else if (req.getPathInfo().equals("/remove")) { + } else if (req.getPathInfo().equals("/writeInternal")) { + String[] params = req.getQueryString().split("&"); + String value = null; + for (String param : params) { + String[] paramLine = param.split("="); + String keyParam = paramLine[0]; + String valueParam = paramLine[1]; + if ("value".equals(keyParam)) { + value = valueParam; + } + } + + if (value == null) { + resp.getWriter().print("ERROR"); + } else { + session.setMaxInactiveInterval(Integer.parseInt(value)); + resp.getWriter().print("OK"); + } + } else if (req.getPathInfo().equals("/readInternal")) { + resp.getWriter().print(session.getMaxInactiveInterval()); + } else if (req.getPathInfo().equals("/remove")) { String[] params = req.getQueryString().split("&"); String key = null; for (String param : params) { diff --git a/redisson-tomcat/redisson-tomcat-11/src/main/java/org/redisson/tomcat/RedissonSession.java b/redisson-tomcat/redisson-tomcat-11/src/main/java/org/redisson/tomcat/RedissonSession.java index 3c41d2e28..4e90adede 100644 --- a/redisson-tomcat/redisson-tomcat-11/src/main/java/org/redisson/tomcat/RedissonSession.java +++ b/redisson-tomcat/redisson-tomcat-11/src/main/java/org/redisson/tomcat/RedissonSession.java @@ -263,7 +263,7 @@ public class RedissonSession extends StandardSession { return; } m.fastPut(name, value); - if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) { + if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || this.broadcastSessionEvents) { try { Encoder encoder = m.getCodec().getMapValueEncoder(); topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder)); diff --git a/redisson-tomcat/redisson-tomcat-11/src/main/java/org/redisson/tomcat/RedissonSessionManager.java b/redisson-tomcat/redisson-tomcat-11/src/main/java/org/redisson/tomcat/RedissonSessionManager.java index 71278cc63..af575d85b 100644 --- a/redisson-tomcat/redisson-tomcat-11/src/main/java/org/redisson/tomcat/RedissonSessionManager.java +++ b/redisson-tomcat/redisson-tomcat-11/src/main/java/org/redisson/tomcat/RedissonSessionManager.java @@ -324,7 +324,9 @@ public class RedissonSessionManager extends ManagerBase { if (msg instanceof AttributeUpdateMessage) { AttributeUpdateMessage m = (AttributeUpdateMessage)msg; - session.superSetAttribute(m.getName(), m.getValue(codecToUse.getMapValueDecoder()), true); + Map attrs = new HashMap<>(); + attrs.put(m.getName(), m.getValue(codecToUse.getMapValueDecoder())); + session.load(attrs); } } else { if (msg instanceof SessionCreatedMessage) { diff --git a/redisson-tomcat/redisson-tomcat-11/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java b/redisson-tomcat/redisson-tomcat-11/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java index c900cd9b1..69edf9683 100644 --- a/redisson-tomcat/redisson-tomcat-11/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java +++ b/redisson-tomcat/redisson-tomcat-11/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java @@ -40,6 +40,33 @@ public class RedissonSessionManagerTest { Files.deleteIfExists(Paths.get(basePath + "context.xml")); Files.copy(Paths.get(basePath + contextName), Paths.get(basePath + "context.xml")); } + + @ParameterizedTest + @MethodSource("data") + public void testUpdateMaxInactiveInterval(String contextName) throws Exception { + prepare(contextName); + TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/"); + TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/"); + try { + server1.start(); + server2.start(); + + Executor executor = Executor.newInstance(); + BasicCookieStore cookieStore = new BasicCookieStore(); + executor.use(cookieStore); + + write(8080, executor, "test", "from_server1"); + write(8081, executor, "test", "from_server2"); + + writeInternal(8080, executor, 3000); + readInternal(8081, executor, 3000); + + } finally { + Executor.closeIdleConnections(); + server1.stop(); + server2.stop(); + } + } @ParameterizedTest @MethodSource("data") @@ -376,6 +403,18 @@ public class RedissonSessionManagerTest { Assertions.assertEquals(value, response); } + private void writeInternal(int port, Executor executor, Object value) throws IOException { + String url = "http://localhost:" + port + "/myapp/writeInternal?value=" + value; + String response = executor.execute(Request.Get(url)).returnContent().asString(); + Assertions.assertEquals("OK", response); + } + + private void readInternal(int port, Executor executor, Object value) throws IOException { + String url = "http://localhost:" + port + "/myapp/readInternal"; + String response = executor.execute(Request.Get(url)).returnContent().asString(); + Assertions.assertEquals(value.toString(), response); + } + private void remove(Executor executor, String key, String value) throws IOException { String url = "http://localhost:8080/myapp/remove?key=" + key; String response = executor.execute(Request.Get(url)).returnContent().asString(); diff --git a/redisson-tomcat/redisson-tomcat-11/src/test/java/org/redisson/tomcat/TestServlet.java b/redisson-tomcat/redisson-tomcat-11/src/test/java/org/redisson/tomcat/TestServlet.java index 0d686ca98..78aaf80f4 100644 --- a/redisson-tomcat/redisson-tomcat-11/src/test/java/org/redisson/tomcat/TestServlet.java +++ b/redisson-tomcat/redisson-tomcat-11/src/test/java/org/redisson/tomcat/TestServlet.java @@ -73,7 +73,27 @@ public class TestServlet extends HttpServlet { Object attr = session.getAttribute(key); resp.getWriter().print(attr); - } else if (req.getPathInfo().equals("/remove")) { + } else if (req.getPathInfo().equals("/writeInternal")) { + String[] params = req.getQueryString().split("&"); + String value = null; + for (String param : params) { + String[] paramLine = param.split("="); + String keyParam = paramLine[0]; + String valueParam = paramLine[1]; + if ("value".equals(keyParam)) { + value = valueParam; + } + } + + if (value == null) { + resp.getWriter().print("ERROR"); + } else { + session.setMaxInactiveInterval(Integer.parseInt(value)); + resp.getWriter().print("OK"); + } + } else if (req.getPathInfo().equals("/readInternal")) { + resp.getWriter().print(session.getMaxInactiveInterval()); + } else if (req.getPathInfo().equals("/remove")) { String[] params = req.getQueryString().split("&"); String key = null; for (String param : params) { diff --git a/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSession.java b/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSession.java index 856dc91cc..108b79332 100644 --- a/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSession.java +++ b/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSession.java @@ -258,7 +258,7 @@ public class RedissonSession extends StandardSession { return; } m.fastPut(name, value); - if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) { + if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || this.broadcastSessionEvents) { try { Encoder encoder = m.getCodec().getMapValueEncoder(); topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder)); diff --git a/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSessionManager.java b/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSessionManager.java index 04071a51f..99251a24e 100644 --- a/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSessionManager.java +++ b/redisson-tomcat/redisson-tomcat-7/src/main/java/org/redisson/tomcat/RedissonSessionManager.java @@ -324,7 +324,9 @@ public class RedissonSessionManager extends ManagerBase { if (msg instanceof AttributeUpdateMessage) { AttributeUpdateMessage m = (AttributeUpdateMessage)msg; - session.superSetAttribute(m.getName(), m.getValue(codecToUse.getMapValueDecoder()), true); + Map attrs = new HashMap<>(); + attrs.put(m.getName(), m.getValue(codecToUse.getMapValueDecoder())); + session.load(attrs); } } else { if (msg instanceof SessionCreatedMessage) { diff --git a/redisson-tomcat/redisson-tomcat-7/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java b/redisson-tomcat/redisson-tomcat-7/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java index 5e34d55ee..87cb7499c 100644 --- a/redisson-tomcat/redisson-tomcat-7/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java +++ b/redisson-tomcat/redisson-tomcat-7/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java @@ -34,6 +34,33 @@ public class RedissonSessionManagerTest { Files.deleteIfExists(Paths.get(basePath + "context.xml")); Files.copy(Paths.get(basePath + contextName), Paths.get(basePath + "context.xml")); } + + @ParameterizedTest + @MethodSource("data") + public void testUpdateMaxInactiveInterval(String contextName) throws Exception { + prepare(contextName); + TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/"); + TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/"); + try { + server1.start(); + server2.start(); + + Executor executor = Executor.newInstance(); + BasicCookieStore cookieStore = new BasicCookieStore(); + executor.use(cookieStore); + + write(8080, executor, "test", "from_server1"); + write(8081, executor, "test", "from_server2"); + + writeInternal(8080, executor, 3000); + readInternal(8081, executor, 3000); + + } finally { + Executor.closeIdleConnections(); + server1.stop(); + server2.stop(); + } + } @ParameterizedTest @MethodSource("data") @@ -321,6 +348,19 @@ public class RedissonSessionManagerTest { Assertions.assertEquals(value, response); } + private void writeInternal(int port, Executor executor, Object value) throws IOException { + String url = "http://localhost:" + port + "/myapp/writeInternal?value=" + value; + String response = executor.execute(Request.Get(url)).returnContent().asString(); + Assertions.assertEquals("OK", response); + } + + private void readInternal(int port, Executor executor, Object value) throws IOException { + String url = "http://localhost:" + port + "/myapp/readInternal"; + String response = executor.execute(Request.Get(url)).returnContent().asString(); + Assertions.assertEquals(value.toString(), response); + } + + private void remove(Executor executor, String key, String value) throws IOException { String url = "http://localhost:8080/myapp/remove?key=" + key; String response = executor.execute(Request.Get(url)).returnContent().asString(); diff --git a/redisson-tomcat/redisson-tomcat-7/src/test/java/org/redisson/tomcat/TestServlet.java b/redisson-tomcat/redisson-tomcat-7/src/test/java/org/redisson/tomcat/TestServlet.java index 1c68da965..ddc488a57 100644 --- a/redisson-tomcat/redisson-tomcat-7/src/test/java/org/redisson/tomcat/TestServlet.java +++ b/redisson-tomcat/redisson-tomcat-7/src/test/java/org/redisson/tomcat/TestServlet.java @@ -48,7 +48,27 @@ public class TestServlet extends HttpServlet { Object attr = session.getAttribute(key); resp.getWriter().print(attr); - } else if (req.getPathInfo().equals("/remove")) { + } else if (req.getPathInfo().equals("/writeInternal")) { + String[] params = req.getQueryString().split("&"); + String value = null; + for (String param : params) { + String[] paramLine = param.split("="); + String keyParam = paramLine[0]; + String valueParam = paramLine[1]; + if ("value".equals(keyParam)) { + value = valueParam; + } + } + + if (value == null) { + resp.getWriter().print("ERROR"); + } else { + session.setMaxInactiveInterval(Integer.parseInt(value)); + resp.getWriter().print("OK"); + } + } else if (req.getPathInfo().equals("/readInternal")) { + resp.getWriter().print(session.getMaxInactiveInterval()); + } else if (req.getPathInfo().equals("/remove")) { String[] params = req.getQueryString().split("&"); String key = null; for (String param : params) { diff --git a/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSession.java b/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSession.java index 30f6e8836..afcba2344 100644 --- a/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSession.java +++ b/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSession.java @@ -258,7 +258,7 @@ public class RedissonSession extends StandardSession { return; } m.fastPut(name, value); - if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) { + if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || this.broadcastSessionEvents) { try { Encoder encoder = m.getCodec().getMapValueEncoder(); topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder)); diff --git a/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSessionManager.java b/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSessionManager.java index f15bac7b0..be9da6f1a 100644 --- a/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSessionManager.java +++ b/redisson-tomcat/redisson-tomcat-8/src/main/java/org/redisson/tomcat/RedissonSessionManager.java @@ -324,7 +324,9 @@ public class RedissonSessionManager extends ManagerBase { if (msg instanceof AttributeUpdateMessage) { AttributeUpdateMessage m = (AttributeUpdateMessage)msg; - session.superSetAttribute(m.getName(), m.getValue(codecToUse.getMapValueDecoder()), true); + Map attrs = new HashMap<>(); + attrs.put(m.getName(), m.getValue(codecToUse.getMapValueDecoder())); + session.load(attrs); } } else { if (msg instanceof SessionCreatedMessage) { diff --git a/redisson-tomcat/redisson-tomcat-8/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java b/redisson-tomcat/redisson-tomcat-8/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java index 5e34d55ee..3f621fdf3 100644 --- a/redisson-tomcat/redisson-tomcat-8/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java +++ b/redisson-tomcat/redisson-tomcat-8/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java @@ -34,6 +34,33 @@ public class RedissonSessionManagerTest { Files.deleteIfExists(Paths.get(basePath + "context.xml")); Files.copy(Paths.get(basePath + contextName), Paths.get(basePath + "context.xml")); } + + @ParameterizedTest + @MethodSource("data") + public void testUpdateMaxInactiveInterval(String contextName) throws Exception { + prepare(contextName); + TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/"); + TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/"); + try { + server1.start(); + server2.start(); + + Executor executor = Executor.newInstance(); + BasicCookieStore cookieStore = new BasicCookieStore(); + executor.use(cookieStore); + + write(8080, executor, "test", "from_server1"); + write(8081, executor, "test", "from_server2"); + + writeInternal(8080, executor, 3000); + readInternal(8081, executor, 3000); + + } finally { + Executor.closeIdleConnections(); + server1.stop(); + server2.stop(); + } + } @ParameterizedTest @MethodSource("data") @@ -321,6 +348,18 @@ public class RedissonSessionManagerTest { Assertions.assertEquals(value, response); } + private void writeInternal(int port, Executor executor, Object value) throws IOException { + String url = "http://localhost:" + port + "/myapp/writeInternal?value=" + value; + String response = executor.execute(Request.Get(url)).returnContent().asString(); + Assertions.assertEquals("OK", response); + } + + private void readInternal(int port, Executor executor, Object value) throws IOException { + String url = "http://localhost:" + port + "/myapp/readInternal"; + String response = executor.execute(Request.Get(url)).returnContent().asString(); + Assertions.assertEquals(value.toString(), response); + } + private void remove(Executor executor, String key, String value) throws IOException { String url = "http://localhost:8080/myapp/remove?key=" + key; String response = executor.execute(Request.Get(url)).returnContent().asString(); diff --git a/redisson-tomcat/redisson-tomcat-8/src/test/java/org/redisson/tomcat/TestServlet.java b/redisson-tomcat/redisson-tomcat-8/src/test/java/org/redisson/tomcat/TestServlet.java index 1c68da965..ddc488a57 100644 --- a/redisson-tomcat/redisson-tomcat-8/src/test/java/org/redisson/tomcat/TestServlet.java +++ b/redisson-tomcat/redisson-tomcat-8/src/test/java/org/redisson/tomcat/TestServlet.java @@ -48,7 +48,27 @@ public class TestServlet extends HttpServlet { Object attr = session.getAttribute(key); resp.getWriter().print(attr); - } else if (req.getPathInfo().equals("/remove")) { + } else if (req.getPathInfo().equals("/writeInternal")) { + String[] params = req.getQueryString().split("&"); + String value = null; + for (String param : params) { + String[] paramLine = param.split("="); + String keyParam = paramLine[0]; + String valueParam = paramLine[1]; + if ("value".equals(keyParam)) { + value = valueParam; + } + } + + if (value == null) { + resp.getWriter().print("ERROR"); + } else { + session.setMaxInactiveInterval(Integer.parseInt(value)); + resp.getWriter().print("OK"); + } + } else if (req.getPathInfo().equals("/readInternal")) { + resp.getWriter().print(session.getMaxInactiveInterval()); + } else if (req.getPathInfo().equals("/remove")) { String[] params = req.getQueryString().split("&"); String key = null; for (String param : params) { diff --git a/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSession.java b/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSession.java index 30f6e8836..afcba2344 100644 --- a/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSession.java +++ b/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSession.java @@ -258,7 +258,7 @@ public class RedissonSession extends StandardSession { return; } m.fastPut(name, value); - if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) { + if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || this.broadcastSessionEvents) { try { Encoder encoder = m.getCodec().getMapValueEncoder(); topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder)); diff --git a/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSessionManager.java b/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSessionManager.java index 2b8546949..2c7cf4df4 100644 --- a/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSessionManager.java +++ b/redisson-tomcat/redisson-tomcat-9/src/main/java/org/redisson/tomcat/RedissonSessionManager.java @@ -332,7 +332,9 @@ public class RedissonSessionManager extends ManagerBase { if (msg instanceof AttributeUpdateMessage) { AttributeUpdateMessage m = (AttributeUpdateMessage)msg; - session.superSetAttribute(m.getName(), m.getValue(codecToUse.getMapValueDecoder()), true); + Map attrs = new HashMap<>(); + attrs.put(m.getName(), m.getValue(codecToUse.getMapValueDecoder())); + session.load(attrs); } } else { if (msg instanceof SessionCreatedMessage) { diff --git a/redisson-tomcat/redisson-tomcat-9/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java b/redisson-tomcat/redisson-tomcat-9/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java index f7ed0f421..df8bce8df 100644 --- a/redisson-tomcat/redisson-tomcat-9/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java +++ b/redisson-tomcat/redisson-tomcat-9/src/test/java/org/redisson/tomcat/RedissonSessionManagerTest.java @@ -53,7 +53,34 @@ public class RedissonSessionManagerTest { return redissonSessionManager; } - + + @ParameterizedTest + @MethodSource("data") + public void testUpdateMaxInactiveInterval(String contextName) throws Exception { + prepare(contextName); + TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/"); + TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/"); + try { + server1.start(); + server2.start(); + + Executor executor = Executor.newInstance(); + BasicCookieStore cookieStore = new BasicCookieStore(); + executor.use(cookieStore); + + write(8080, executor, "test", "from_server1"); + write(8081, executor, "test", "from_server2"); + + writeInternal(8080, executor, 3000); + readInternal(8081, executor, 3000); + + } finally { + Executor.closeIdleConnections(); + server1.stop(); + server2.stop(); + } + } + @Test public void testProgrammaticManagerConfigurationUpdateTwoServers_readValue() throws Exception { prepare("context_empty.xml"); @@ -368,6 +395,18 @@ public class RedissonSessionManagerTest { Assertions.assertEquals(value, response); } + private void writeInternal(int port, Executor executor, Object value) throws IOException { + String url = "http://localhost:" + port + "/myapp/writeInternal?value=" + value; + String response = executor.execute(Request.Get(url)).returnContent().asString(); + Assertions.assertEquals("OK", response); + } + + private void readInternal(int port, Executor executor, Object value) throws IOException { + String url = "http://localhost:" + port + "/myapp/readInternal"; + String response = executor.execute(Request.Get(url)).returnContent().asString(); + Assertions.assertEquals(value.toString(), response); + } + private void remove(Executor executor, String key, String value) throws IOException { String url = "http://localhost:8080/myapp/remove?key=" + key; String response = executor.execute(Request.Get(url)).returnContent().asString(); diff --git a/redisson-tomcat/redisson-tomcat-9/src/test/java/org/redisson/tomcat/TestServlet.java b/redisson-tomcat/redisson-tomcat-9/src/test/java/org/redisson/tomcat/TestServlet.java index 1c68da965..ddc488a57 100644 --- a/redisson-tomcat/redisson-tomcat-9/src/test/java/org/redisson/tomcat/TestServlet.java +++ b/redisson-tomcat/redisson-tomcat-9/src/test/java/org/redisson/tomcat/TestServlet.java @@ -48,7 +48,27 @@ public class TestServlet extends HttpServlet { Object attr = session.getAttribute(key); resp.getWriter().print(attr); - } else if (req.getPathInfo().equals("/remove")) { + } else if (req.getPathInfo().equals("/writeInternal")) { + String[] params = req.getQueryString().split("&"); + String value = null; + for (String param : params) { + String[] paramLine = param.split("="); + String keyParam = paramLine[0]; + String valueParam = paramLine[1]; + if ("value".equals(keyParam)) { + value = valueParam; + } + } + + if (value == null) { + resp.getWriter().print("ERROR"); + } else { + session.setMaxInactiveInterval(Integer.parseInt(value)); + resp.getWriter().print("OK"); + } + } else if (req.getPathInfo().equals("/readInternal")) { + resp.getWriter().print(session.getMaxInactiveInterval()); + } else if (req.getPathInfo().equals("/remove")) { String[] params = req.getQueryString().split("&"); String key = null; for (String param : params) {