Fixed - Inconsistent MaxInactiveInterval Setting in Sessions in multi-node

Signed-off-by: seakider <seakider@gmail.com>
pull/6478/head
seakider 4 days ago
parent 7d6d8fcab3
commit 4ce7820fdc

@ -263,7 +263,7 @@ public class RedissonSession extends StandardSession {
return; return;
} }
m.fastPut(name, value); m.fastPut(name, value);
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) { if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || this.broadcastSessionEvents) {
try { try {
Encoder encoder = m.getCodec().getMapValueEncoder(); Encoder encoder = m.getCodec().getMapValueEncoder();
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder)); topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder));

@ -324,7 +324,9 @@ public class RedissonSessionManager extends ManagerBase {
if (msg instanceof AttributeUpdateMessage) { if (msg instanceof AttributeUpdateMessage) {
AttributeUpdateMessage m = (AttributeUpdateMessage)msg; AttributeUpdateMessage m = (AttributeUpdateMessage)msg;
session.superSetAttribute(m.getName(), m.getValue(codecToUse.getMapValueDecoder()), true); Map<String, Object> attrs = new HashMap<>();
attrs.put(m.getName(), m.getValue(codecToUse.getMapValueDecoder()));
session.load(attrs);
} }
} else { } else {
if (msg instanceof SessionCreatedMessage) { if (msg instanceof SessionCreatedMessage) {

@ -40,7 +40,34 @@ public class RedissonSessionManagerTest {
Files.deleteIfExists(Paths.get(basePath + "context.xml")); Files.deleteIfExists(Paths.get(basePath + "context.xml"));
Files.copy(Paths.get(basePath + contextName), 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 @ParameterizedTest
@MethodSource("data") @MethodSource("data")
public void testUpdateTwoServers_readValue(String contextName) throws Exception { public void testUpdateTwoServers_readValue(String contextName) throws Exception {
@ -376,6 +403,18 @@ public class RedissonSessionManagerTest {
Assertions.assertEquals(value, response); 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 { private void remove(Executor executor, String key, String value) throws IOException {
String url = "http://localhost:8080/myapp/remove?key=" + key; String url = "http://localhost:8080/myapp/remove?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString(); String response = executor.execute(Request.Get(url)).returnContent().asString();

@ -73,7 +73,27 @@ public class TestServlet extends HttpServlet {
Object attr = session.getAttribute(key); Object attr = session.getAttribute(key);
resp.getWriter().print(attr); 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[] params = req.getQueryString().split("&");
String key = null; String key = null;
for (String param : params) { for (String param : params) {

@ -263,7 +263,7 @@ public class RedissonSession extends StandardSession {
return; return;
} }
m.fastPut(name, value); m.fastPut(name, value);
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) { if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || this.broadcastSessionEvents) {
try { try {
Encoder encoder = m.getCodec().getMapValueEncoder(); Encoder encoder = m.getCodec().getMapValueEncoder();
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder)); topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder));

@ -324,7 +324,9 @@ public class RedissonSessionManager extends ManagerBase {
if (msg instanceof AttributeUpdateMessage) { if (msg instanceof AttributeUpdateMessage) {
AttributeUpdateMessage m = (AttributeUpdateMessage)msg; AttributeUpdateMessage m = (AttributeUpdateMessage)msg;
session.superSetAttribute(m.getName(), m.getValue(codecToUse.getMapValueDecoder()), true); Map<String, Object> attrs = new HashMap<>();
attrs.put(m.getName(), m.getValue(codecToUse.getMapValueDecoder()));
session.load(attrs);
} }
} else { } else {
if (msg instanceof SessionCreatedMessage) { if (msg instanceof SessionCreatedMessage) {

@ -40,6 +40,33 @@ public class RedissonSessionManagerTest {
Files.deleteIfExists(Paths.get(basePath + "context.xml")); Files.deleteIfExists(Paths.get(basePath + "context.xml"));
Files.copy(Paths.get(basePath + contextName), 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 @ParameterizedTest
@MethodSource("data") @MethodSource("data")
@ -376,6 +403,18 @@ public class RedissonSessionManagerTest {
Assertions.assertEquals(value, response); 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 { private void remove(Executor executor, String key, String value) throws IOException {
String url = "http://localhost:8080/myapp/remove?key=" + key; String url = "http://localhost:8080/myapp/remove?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString(); String response = executor.execute(Request.Get(url)).returnContent().asString();

@ -73,7 +73,27 @@ public class TestServlet extends HttpServlet {
Object attr = session.getAttribute(key); Object attr = session.getAttribute(key);
resp.getWriter().print(attr); 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[] params = req.getQueryString().split("&");
String key = null; String key = null;
for (String param : params) { for (String param : params) {

@ -258,7 +258,7 @@ public class RedissonSession extends StandardSession {
return; return;
} }
m.fastPut(name, value); m.fastPut(name, value);
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) { if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || this.broadcastSessionEvents) {
try { try {
Encoder encoder = m.getCodec().getMapValueEncoder(); Encoder encoder = m.getCodec().getMapValueEncoder();
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder)); topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder));

@ -324,7 +324,9 @@ public class RedissonSessionManager extends ManagerBase {
if (msg instanceof AttributeUpdateMessage) { if (msg instanceof AttributeUpdateMessage) {
AttributeUpdateMessage m = (AttributeUpdateMessage)msg; AttributeUpdateMessage m = (AttributeUpdateMessage)msg;
session.superSetAttribute(m.getName(), m.getValue(codecToUse.getMapValueDecoder()), true); Map<String, Object> attrs = new HashMap<>();
attrs.put(m.getName(), m.getValue(codecToUse.getMapValueDecoder()));
session.load(attrs);
} }
} else { } else {
if (msg instanceof SessionCreatedMessage) { if (msg instanceof SessionCreatedMessage) {

@ -34,6 +34,33 @@ public class RedissonSessionManagerTest {
Files.deleteIfExists(Paths.get(basePath + "context.xml")); Files.deleteIfExists(Paths.get(basePath + "context.xml"));
Files.copy(Paths.get(basePath + contextName), 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 @ParameterizedTest
@MethodSource("data") @MethodSource("data")
@ -321,6 +348,19 @@ public class RedissonSessionManagerTest {
Assertions.assertEquals(value, response); 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 { private void remove(Executor executor, String key, String value) throws IOException {
String url = "http://localhost:8080/myapp/remove?key=" + key; String url = "http://localhost:8080/myapp/remove?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString(); String response = executor.execute(Request.Get(url)).returnContent().asString();

@ -48,7 +48,27 @@ public class TestServlet extends HttpServlet {
Object attr = session.getAttribute(key); Object attr = session.getAttribute(key);
resp.getWriter().print(attr); 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[] params = req.getQueryString().split("&");
String key = null; String key = null;
for (String param : params) { for (String param : params) {

@ -258,7 +258,7 @@ public class RedissonSession extends StandardSession {
return; return;
} }
m.fastPut(name, value); m.fastPut(name, value);
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) { if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || this.broadcastSessionEvents) {
try { try {
Encoder encoder = m.getCodec().getMapValueEncoder(); Encoder encoder = m.getCodec().getMapValueEncoder();
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder)); topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder));

@ -324,7 +324,9 @@ public class RedissonSessionManager extends ManagerBase {
if (msg instanceof AttributeUpdateMessage) { if (msg instanceof AttributeUpdateMessage) {
AttributeUpdateMessage m = (AttributeUpdateMessage)msg; AttributeUpdateMessage m = (AttributeUpdateMessage)msg;
session.superSetAttribute(m.getName(), m.getValue(codecToUse.getMapValueDecoder()), true); Map<String, Object> attrs = new HashMap<>();
attrs.put(m.getName(), m.getValue(codecToUse.getMapValueDecoder()));
session.load(attrs);
} }
} else { } else {
if (msg instanceof SessionCreatedMessage) { if (msg instanceof SessionCreatedMessage) {

@ -34,6 +34,33 @@ public class RedissonSessionManagerTest {
Files.deleteIfExists(Paths.get(basePath + "context.xml")); Files.deleteIfExists(Paths.get(basePath + "context.xml"));
Files.copy(Paths.get(basePath + contextName), 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 @ParameterizedTest
@MethodSource("data") @MethodSource("data")
@ -321,6 +348,18 @@ public class RedissonSessionManagerTest {
Assertions.assertEquals(value, response); 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 { private void remove(Executor executor, String key, String value) throws IOException {
String url = "http://localhost:8080/myapp/remove?key=" + key; String url = "http://localhost:8080/myapp/remove?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString(); String response = executor.execute(Request.Get(url)).returnContent().asString();

@ -48,7 +48,27 @@ public class TestServlet extends HttpServlet {
Object attr = session.getAttribute(key); Object attr = session.getAttribute(key);
resp.getWriter().print(attr); 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[] params = req.getQueryString().split("&");
String key = null; String key = null;
for (String param : params) { for (String param : params) {

@ -258,7 +258,7 @@ public class RedissonSession extends StandardSession {
return; return;
} }
m.fastPut(name, value); m.fastPut(name, value);
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) { if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || this.broadcastSessionEvents) {
try { try {
Encoder encoder = m.getCodec().getMapValueEncoder(); Encoder encoder = m.getCodec().getMapValueEncoder();
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder)); topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, encoder));

@ -332,7 +332,9 @@ public class RedissonSessionManager extends ManagerBase {
if (msg instanceof AttributeUpdateMessage) { if (msg instanceof AttributeUpdateMessage) {
AttributeUpdateMessage m = (AttributeUpdateMessage)msg; AttributeUpdateMessage m = (AttributeUpdateMessage)msg;
session.superSetAttribute(m.getName(), m.getValue(codecToUse.getMapValueDecoder()), true); Map<String, Object> attrs = new HashMap<>();
attrs.put(m.getName(), m.getValue(codecToUse.getMapValueDecoder()));
session.load(attrs);
} }
} else { } else {
if (msg instanceof SessionCreatedMessage) { if (msg instanceof SessionCreatedMessage) {

@ -53,7 +53,34 @@ public class RedissonSessionManagerTest {
return redissonSessionManager; 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 @Test
public void testProgrammaticManagerConfigurationUpdateTwoServers_readValue() throws Exception { public void testProgrammaticManagerConfigurationUpdateTwoServers_readValue() throws Exception {
prepare("context_empty.xml"); prepare("context_empty.xml");
@ -368,6 +395,18 @@ public class RedissonSessionManagerTest {
Assertions.assertEquals(value, response); 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 { private void remove(Executor executor, String key, String value) throws IOException {
String url = "http://localhost:8080/myapp/remove?key=" + key; String url = "http://localhost:8080/myapp/remove?key=" + key;
String response = executor.execute(Request.Get(url)).returnContent().asString(); String response = executor.execute(Request.Get(url)).returnContent().asString();

@ -48,7 +48,27 @@ public class TestServlet extends HttpServlet {
Object attr = session.getAttribute(key); Object attr = session.getAttribute(key);
resp.getWriter().print(attr); 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[] params = req.getQueryString().split("&");
String key = null; String key = null;
for (String param : params) { for (String param : params) {

Loading…
Cancel
Save