|
|
|
@ -1,12 +1,10 @@
|
|
|
|
|
package org.redisson.tomcat;
|
|
|
|
|
|
|
|
|
|
import org.apache.http.client.ClientProtocolException;
|
|
|
|
|
import org.apache.http.client.fluent.Executor;
|
|
|
|
|
import org.apache.http.client.fluent.Request;
|
|
|
|
|
import org.apache.http.cookie.Cookie;
|
|
|
|
|
import org.apache.http.impl.client.BasicCookieStore;
|
|
|
|
|
import org.junit.Assert;
|
|
|
|
|
import org.junit.Assume;
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
@ -20,6 +18,7 @@ import java.io.IOException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
@RunWith(Parameterized.class)
|
|
|
|
|
public class RedissonSessionManagerTest {
|
|
|
|
@ -44,6 +43,31 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
Files.copy(Paths.get(basePath + contextName), Paths.get(basePath + "context.xml"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testUpdateTwoServers_readValue() throws Exception {
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
read(8080, executor, "test", "from_server2");
|
|
|
|
|
read(8080, executor, "test", "from_server2");
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
Executor.closeIdleConnections();
|
|
|
|
|
server1.stop();
|
|
|
|
|
server2.stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testHttpSessionListener() throws Exception {
|
|
|
|
|
TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
|
|
|
|
@ -59,7 +83,7 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
TestHttpSessionListener.CREATED_INVOCATION_COUNTER = 0;
|
|
|
|
|
TestHttpSessionListener.DESTROYED_INVOCATION_COUNTER = 0;
|
|
|
|
|
|
|
|
|
|
write(executor, "test", "1234");
|
|
|
|
|
write(8080, executor, "test", "1234");
|
|
|
|
|
|
|
|
|
|
TomcatServer server3 = new TomcatServer("myapp", 8082, "src/test/");
|
|
|
|
|
server3.start();
|
|
|
|
@ -77,23 +101,50 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
server3.stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testUpdateTwoServers_twoValues() throws Exception {
|
|
|
|
|
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, "key1", "value1");
|
|
|
|
|
write(8080, executor, "key2", "value1");
|
|
|
|
|
|
|
|
|
|
write(8081, executor, "key1", "value2");
|
|
|
|
|
write(8081, executor, "key2", "value2");
|
|
|
|
|
|
|
|
|
|
read(8080, executor, "key1", "value2");
|
|
|
|
|
read(8080, executor, "key2", "value2");
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
Executor.closeIdleConnections();
|
|
|
|
|
server1.stop();
|
|
|
|
|
server2.stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testUpdateTwoServers() throws Exception {
|
|
|
|
|
TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
|
|
|
|
|
server1.start();
|
|
|
|
|
TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
|
|
|
|
|
server2.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();
|
|
|
|
|
write(8080, executor, "test", "1234");
|
|
|
|
|
|
|
|
|
|
read(8081, executor, "test", "1234");
|
|
|
|
|
read(executor, "test", "1234");
|
|
|
|
|
write(executor, "test", "324");
|
|
|
|
|
read(8080, executor, "test", "1234");
|
|
|
|
|
write(8080, executor, "test", "324");
|
|
|
|
|
read(8081, executor, "test", "324");
|
|
|
|
|
|
|
|
|
|
Executor.closeIdleConnections();
|
|
|
|
@ -102,7 +153,7 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
|
@Test
|
|
|
|
|
public void testExpiration() throws Exception {
|
|
|
|
|
TomcatServer server1 = new TomcatServer("myapp", 8080, "src/test/");
|
|
|
|
|
server1.start();
|
|
|
|
@ -111,7 +162,7 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
BasicCookieStore cookieStore = new BasicCookieStore();
|
|
|
|
|
executor.use(cookieStore);
|
|
|
|
|
|
|
|
|
|
write(executor, "test", "1234");
|
|
|
|
|
write(8080, executor, "test", "1234");
|
|
|
|
|
|
|
|
|
|
TomcatServer server2 = new TomcatServer("myapp", 8081, "src/test/");
|
|
|
|
|
server2.start();
|
|
|
|
@ -123,7 +174,7 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
Thread.sleep(40000);
|
|
|
|
|
|
|
|
|
|
executor.use(cookieStore);
|
|
|
|
|
read(executor, "test", "1234");
|
|
|
|
|
read(8080, executor, "test", "1234");
|
|
|
|
|
|
|
|
|
|
Executor.closeIdleConnections();
|
|
|
|
|
server1.stop();
|
|
|
|
@ -140,7 +191,8 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
BasicCookieStore cookieStore = new BasicCookieStore();
|
|
|
|
|
executor.use(cookieStore);
|
|
|
|
|
|
|
|
|
|
write(executor, "test", "1234");
|
|
|
|
|
write(8080, executor, "test", "1234");
|
|
|
|
|
System.out.println("done1");
|
|
|
|
|
Cookie cookie = cookieStore.getCookies().get(0);
|
|
|
|
|
|
|
|
|
|
Executor.closeIdleConnections();
|
|
|
|
@ -153,7 +205,7 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
cookieStore = new BasicCookieStore();
|
|
|
|
|
cookieStore.addCookie(cookie);
|
|
|
|
|
executor.use(cookieStore);
|
|
|
|
|
read(executor, "test", "1234");
|
|
|
|
|
read(8080, executor, "test", "1234");
|
|
|
|
|
remove(executor, "test", "null");
|
|
|
|
|
|
|
|
|
|
Executor.closeIdleConnections();
|
|
|
|
@ -169,8 +221,8 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
|
|
|
|
|
Executor executor = Executor.newInstance();
|
|
|
|
|
|
|
|
|
|
write(executor, "test", "1234");
|
|
|
|
|
read(executor, "test", "1234");
|
|
|
|
|
write(8080, executor, "test", "1234");
|
|
|
|
|
read(8080, executor, "test", "1234");
|
|
|
|
|
remove(executor, "test", "null");
|
|
|
|
|
|
|
|
|
|
Executor.closeIdleConnections();
|
|
|
|
@ -185,9 +237,9 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
|
|
|
|
|
Executor executor = Executor.newInstance();
|
|
|
|
|
|
|
|
|
|
write(executor, "test", "1");
|
|
|
|
|
write(8080, executor, "test", "1");
|
|
|
|
|
recreate(executor, "test", "2");
|
|
|
|
|
read(executor, "test", "2");
|
|
|
|
|
read(8080, executor, "test", "2");
|
|
|
|
|
|
|
|
|
|
Executor.closeIdleConnections();
|
|
|
|
|
server.stop();
|
|
|
|
@ -201,10 +253,10 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
|
|
|
|
|
Executor executor = Executor.newInstance();
|
|
|
|
|
|
|
|
|
|
write(executor, "test", "1");
|
|
|
|
|
read(executor, "test", "1");
|
|
|
|
|
write(executor, "test", "2");
|
|
|
|
|
read(executor, "test", "2");
|
|
|
|
|
write(8080, executor, "test", "1");
|
|
|
|
|
read(8080, executor, "test", "1");
|
|
|
|
|
write(8080, executor, "test", "2");
|
|
|
|
|
read(8080, executor, "test", "2");
|
|
|
|
|
|
|
|
|
|
Executor.closeIdleConnections();
|
|
|
|
|
server.stop();
|
|
|
|
@ -226,7 +278,7 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
BasicCookieStore cookieStore = new BasicCookieStore();
|
|
|
|
|
executor.use(cookieStore);
|
|
|
|
|
|
|
|
|
|
write(executor, "test", "1234");
|
|
|
|
|
write(8080, executor, "test", "1234");
|
|
|
|
|
Cookie cookie = cookieStore.getCookies().get(0);
|
|
|
|
|
invalidate(executor);
|
|
|
|
|
|
|
|
|
@ -236,49 +288,46 @@ public class RedissonSessionManagerTest {
|
|
|
|
|
cookieStore = new BasicCookieStore();
|
|
|
|
|
cookieStore.addCookie(cookie);
|
|
|
|
|
executor.use(cookieStore);
|
|
|
|
|
read(executor, "test", "null");
|
|
|
|
|
read(8080, executor, "test", "null");
|
|
|
|
|
invalidate(executor);
|
|
|
|
|
|
|
|
|
|
Executor.closeIdleConnections();
|
|
|
|
|
server.stop();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TimeUnit.SECONDS.sleep(60);
|
|
|
|
|
Assert.assertEquals(0, r.getKeys().count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void write(Executor executor, String key, String value) throws IOException, ClientProtocolException {
|
|
|
|
|
String url = "http://localhost:8080/myapp/write?key=" + key + "&value=" + value;
|
|
|
|
|
private void write(int port, Executor executor, String key, String value) throws IOException {
|
|
|
|
|
String url = "http://localhost:" + port + "/myapp/write?key=" + key + "&value=" + value;
|
|
|
|
|
String response = executor.execute(Request.Get(url)).returnContent().asString();
|
|
|
|
|
Assert.assertEquals("OK", response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void read(int port, Executor executor, String key, String value) throws IOException, ClientProtocolException {
|
|
|
|
|
|
|
|
|
|
private void read(int port, Executor executor, String key, String value) throws IOException {
|
|
|
|
|
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();
|
|
|
|
|
Assert.assertEquals(value, response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void remove(Executor executor, String key, String value) throws IOException, ClientProtocolException {
|
|
|
|
|
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();
|
|
|
|
|
Assert.assertEquals(value, response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void invalidate(Executor executor) throws IOException, ClientProtocolException {
|
|
|
|
|
private void invalidate(Executor executor) throws IOException {
|
|
|
|
|
String url = "http://localhost:8080/myapp/invalidate";
|
|
|
|
|
String response = executor.execute(Request.Get(url)).returnContent().asString();
|
|
|
|
|
Assert.assertEquals("OK", response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void recreate(Executor executor, String key, String value) throws IOException, ClientProtocolException {
|
|
|
|
|
private void recreate(Executor executor, String key, String value) throws IOException {
|
|
|
|
|
String url = "http://localhost:8080/myapp/recreate?key=" + key + "&value=" + value;
|
|
|
|
|
String response = executor.execute(Request.Get(url)).returnContent().asString();
|
|
|
|
|
Assert.assertEquals("OK", response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|