-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
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; | ||
} | ||
} |
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(); | ||
Check failure on line 38 in integration-tests/infinispan-client/src/test/java/io/quarkus/it/infinispan/client/websessions/CounterTest.java GitHub Actions / Build summary for 5b5589715cf00b921aebc6da2b223cf4b3c9d1e2JVM Tests - JDK 11
Raw output
Check failure on line 38 in integration-tests/infinispan-client/src/test/java/io/quarkus/it/infinispan/client/websessions/CounterTest.java GitHub Actions / Build summary for 5b5589715cf00b921aebc6da2b223cf4b3c9d1e2JVM Tests - JDK 17
Raw output
|
||
} | ||
} | ||
|
||
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++; | ||
} | ||
} | ||
} | ||
} |
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; | ||
} | ||
} |
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(); | ||
Check failure on line 38 in integration-tests/redis-client/src/test/java/io/quarkus/redis/it/websessions/CounterTest.java GitHub Actions / Build summary for 5b5589715cf00b921aebc6da2b223cf4b3c9d1e2JVM Tests - JDK 11
Raw output
Check failure on line 38 in integration-tests/redis-client/src/test/java/io/quarkus/redis/it/websessions/CounterTest.java GitHub Actions / Build summary for 5b5589715cf00b921aebc6da2b223cf4b3c9d1e2JVM Tests - JDK 17
Raw output
|
||
} | ||
} | ||
|
||
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++; | ||
} | ||
} | ||
} | ||
} |
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"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
quarkus.http.sessions.mode=in-memory |
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++; | ||
} | ||
} | ||
} | ||
} |