-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
332 additions
and
1 deletion.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...pan-client/src/main/java/io/quarkus/it/infinispan/client/websessions/CounterResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkus.it.infinispan.client.websessions; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import io.vertx.ext.web.Session; | ||
|
||
@Path("/counter") | ||
public class CounterResource { | ||
@Inject | ||
Session session; | ||
|
||
@GET | ||
public String counter() { | ||
Integer counter = session.get("counter"); | ||
counter = counter == null ? 1 : counter + 1; | ||
session.put("counter", counter); | ||
return session.id() + "|" + counter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...inispan-client/src/test/java/io/quarkus/it/infinispan/client/websessions/CounterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package io.quarkus.it.infinispan.client.websessions; | ||
|
||
import static io.restassured.RestAssured.with; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Queue; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.filter.session.SessionFilter; | ||
import io.restassured.response.Response; | ||
|
||
@QuarkusTest | ||
public class CounterTest { | ||
@Test | ||
public void test() throws InterruptedException { | ||
List<User> users = new ArrayList<>(); | ||
for (int i = 0; i < 50; i++) { | ||
users.add(new User(100)); | ||
} | ||
|
||
for (User user : users) { | ||
user.start(); | ||
} | ||
for (User user : users) { | ||
user.join(); | ||
} | ||
for (User user : users) { | ||
user.verify(); | ||
} | ||
} | ||
|
||
static class User extends Thread { | ||
private static final AtomicInteger counter = new AtomicInteger(); | ||
|
||
private final Set<String> sessionIds = Collections.newSetFromMap(new ConcurrentHashMap<>()); | ||
private final Queue<String> responses = new ConcurrentLinkedQueue<>(); | ||
|
||
private final int requests; | ||
|
||
User(int requests) { | ||
super("User" + counter.incrementAndGet()); | ||
this.requests = requests; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
SessionFilter sessions = new SessionFilter(); | ||
for (int i = 0; i < requests; i++) { | ||
Response response = with().filter(sessions).get("/counter"); | ||
if (response.sessionId() != null) { | ||
sessionIds.add(response.sessionId()); | ||
} | ||
responses.add(response.body().asString()); | ||
|
||
try { | ||
Thread.sleep(ThreadLocalRandom.current().nextInt(50)); | ||
} catch (InterruptedException e) { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
public void verify() { | ||
assertEquals(1, sessionIds.size()); | ||
String id = sessionIds.iterator().next(); | ||
|
||
assertEquals(requests, responses.size()); | ||
int i = 1; | ||
for (String response : responses) { | ||
assertEquals(id + "|" + i, response); | ||
i++; | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ion-tests/redis-client/src/main/java/io/quarkus/redis/it/websessions/CounterResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkus.redis.it.websessions; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import io.vertx.ext.web.Session; | ||
|
||
@Path("/counter") | ||
public class CounterResource { | ||
@Inject | ||
Session session; | ||
|
||
@GET | ||
public String counter() { | ||
Integer counter = session.get("counter"); | ||
counter = counter == null ? 1 : counter + 1; | ||
session.put("counter", counter); | ||
return session.id() + "|" + counter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...gration-tests/redis-client/src/test/java/io/quarkus/redis/it/websessions/CounterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package io.quarkus.redis.it.websessions; | ||
|
||
import static io.restassured.RestAssured.with; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Queue; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.filter.session.SessionFilter; | ||
import io.restassured.response.Response; | ||
|
||
@QuarkusTest | ||
public class CounterTest { | ||
@Test | ||
public void test() throws InterruptedException { | ||
List<User> users = new ArrayList<>(); | ||
for (int i = 0; i < 50; i++) { | ||
users.add(new User(100)); | ||
} | ||
|
||
for (User user : users) { | ||
user.start(); | ||
} | ||
for (User user : users) { | ||
user.join(); | ||
} | ||
for (User user : users) { | ||
user.verify(); | ||
} | ||
} | ||
|
||
static class User extends Thread { | ||
private static final AtomicInteger counter = new AtomicInteger(); | ||
|
||
private final Set<String> sessionIds = Collections.newSetFromMap(new ConcurrentHashMap<>()); | ||
private final Queue<String> responses = new ConcurrentLinkedQueue<>(); | ||
|
||
private final int requests; | ||
|
||
User(int requests) { | ||
super("User" + counter.incrementAndGet()); | ||
this.requests = requests; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
SessionFilter sessions = new SessionFilter(); | ||
for (int i = 0; i < requests; i++) { | ||
Response response = with().filter(sessions).get("/counter"); | ||
if (response.sessionId() != null) { | ||
sessionIds.add(response.sessionId()); | ||
} | ||
responses.add(response.body().asString()); | ||
|
||
try { | ||
Thread.sleep(ThreadLocalRandom.current().nextInt(50)); | ||
} catch (InterruptedException e) { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
public void verify() { | ||
assertEquals(1, sessionIds.size()); | ||
String id = sessionIds.iterator().next(); | ||
|
||
assertEquals(requests, responses.size()); | ||
int i = 1; | ||
for (String response : responses) { | ||
assertEquals(id + "|" + i, response); | ||
i++; | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ration-tests/vertx-web/src/main/java/io/quarkus/it/vertx/websessions/CounterEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.it.vertx.websessions; | ||
|
||
import io.quarkus.vertx.web.Route; | ||
import io.vertx.ext.web.RoutingContext; | ||
import io.vertx.ext.web.Session; | ||
|
||
public class CounterEndpoint { | ||
@Route(path = "/counter", methods = Route.HttpMethod.GET) | ||
String counter(RoutingContext ctx) { | ||
Session session = ctx.session(); | ||
Integer counter = session.get("counter"); | ||
counter = counter == null ? 1 : counter + 1; | ||
session.put("counter", counter); | ||
return session.id() + "|" + counter; | ||
} | ||
|
||
@Route(path = "/check-sessions", methods = Route.HttpMethod.GET) | ||
void checkSessions(RoutingContext ctx) { | ||
Session session = ctx.session(); | ||
ctx.end(session != null ? "OK" : "KO"); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
integration-tests/vertx-web/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
quarkus.http.sessions.mode=in-memory |
89 changes: 89 additions & 0 deletions
89
integration-tests/vertx-web/src/test/java/io/quarkus/it/vertx/websessions/CounterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package io.quarkus.it.vertx.websessions; | ||
|
||
import static io.restassured.RestAssured.when; | ||
import static io.restassured.RestAssured.with; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Queue; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.filter.session.SessionFilter; | ||
import io.restassured.response.Response; | ||
|
||
@QuarkusTest | ||
public class CounterTest { | ||
@Test | ||
public void test() throws InterruptedException { | ||
when().get("/check-sessions").then().statusCode(200).body(Matchers.is("OK")); | ||
|
||
List<User> users = new ArrayList<>(); | ||
for (int i = 0; i < 50; i++) { | ||
users.add(new User(100)); | ||
} | ||
|
||
for (User user : users) { | ||
user.start(); | ||
} | ||
for (User user : users) { | ||
user.join(); | ||
} | ||
for (User user : users) { | ||
user.verify(); | ||
} | ||
} | ||
|
||
static class User extends Thread { | ||
private static final AtomicInteger counter = new AtomicInteger(); | ||
|
||
private final Set<String> sessionIds = Collections.newSetFromMap(new ConcurrentHashMap<>()); | ||
private final Queue<String> responses = new ConcurrentLinkedQueue<>(); | ||
|
||
private final int requests; | ||
|
||
User(int requests) { | ||
super("User" + counter.incrementAndGet()); | ||
this.requests = requests; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
SessionFilter sessions = new SessionFilter(); | ||
for (int i = 0; i < requests; i++) { | ||
Response response = with().filter(sessions).get("/counter"); | ||
if (response.sessionId() != null) { | ||
sessionIds.add(response.sessionId()); | ||
} | ||
responses.add(response.body().asString()); | ||
|
||
try { | ||
Thread.sleep(ThreadLocalRandom.current().nextInt(50)); | ||
} catch (InterruptedException e) { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
public void verify() { | ||
assertEquals(1, sessionIds.size()); | ||
String id = sessionIds.iterator().next(); | ||
|
||
assertEquals(requests, responses.size()); | ||
int i = 1; | ||
for (String response : responses) { | ||
assertEquals(id + "|" + i, response); | ||
i++; | ||
} | ||
} | ||
} | ||
} |