-
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.
Merge pull request #41212 from gsmet/3.12.0-backports-1
[3.12] 3.12.0 backports 1
- Loading branch information
Showing
30 changed files
with
788 additions
and
60 deletions.
There are no files selected for viewing
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
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
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
63 changes: 63 additions & 0 deletions
63
...st/java/io/quarkus/resteasy/reactive/server/test/preconditions/DatePreconditionTests.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,63 @@ | ||
package io.quarkus.resteasy.reactive.server.test.preconditions; | ||
|
||
import static io.restassured.RestAssured.get; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Request; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.core.Response.ResponseBuilder; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class DatePreconditionTests { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Resource.class)); | ||
|
||
// Make sure we test a subtype of Date, since that is what Hibernate ORM gives us most of the time (hah) | ||
// Also make sure we have non-zero milliseconds, since that will be the case for most date values representing | ||
// "now", and we want to make sure pre-conditions work (second-resolution) | ||
static final Date date = new Date(Date.from(Instant.parse("2007-12-03T10:15:30.24Z")).getTime()) { | ||
}; | ||
|
||
public static class Something { | ||
} | ||
|
||
@Test | ||
public void test() { | ||
get("/preconditions") | ||
.then() | ||
.statusCode(200) | ||
.header("Last-Modified", "Mon, 03 Dec 2007 10:15:30 GMT") | ||
.body(Matchers.equalTo("foo")); | ||
RestAssured | ||
.with() | ||
.header("If-Modified-Since", "Mon, 03 Dec 2007 10:15:30 GMT") | ||
.get("/preconditions") | ||
.then() | ||
.statusCode(304); | ||
} | ||
|
||
@Path("/preconditions") | ||
public static class Resource { | ||
@GET | ||
public Response get(Request request) { | ||
ResponseBuilder resp = request.evaluatePreconditions(date); | ||
if (resp != null) { | ||
return resp.build(); | ||
} | ||
return Response.ok("foo").lastModified(date).build(); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...rc/test/java/io/quarkus/websockets/next/test/traffic/BasicConnectorTrafficLoggerTest.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,57 @@ | ||
package io.quarkus.websockets.next.test.traffic; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.websockets.next.BasicWebSocketConnector; | ||
import io.quarkus.websockets.next.WebSocketClientConnection; | ||
import io.vertx.core.Context; | ||
|
||
public class BasicConnectorTrafficLoggerTest extends TrafficLoggerTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(Endpoint.class); | ||
TrafficLoggerTest.addApplicationProperties(root, false); | ||
}) | ||
.setLogRecordPredicate(TrafficLoggerTest::isTrafficLogRecord) | ||
.assertLogRecords(logRecordsConsumer(true)); | ||
|
||
@Inject | ||
BasicWebSocketConnector connector; | ||
|
||
@Test | ||
public void testTrafficLogger() throws InterruptedException { | ||
List<String> messages = new CopyOnWriteArrayList<>(); | ||
CountDownLatch closedLatch = new CountDownLatch(1); | ||
CountDownLatch messageLatch = new CountDownLatch(1); | ||
WebSocketClientConnection conn = connector | ||
.baseUri(endUri) | ||
.path("end") | ||
.onTextMessage((c, m) -> { | ||
assertTrue(Context.isOnWorkerThread()); | ||
messages.add(m); | ||
messageLatch.countDown(); | ||
}) | ||
.onClose((c, s) -> closedLatch.countDown()) | ||
.connectAndAwait(); | ||
conn.sendTextAndAwait("dummy"); | ||
assertTrue(messageLatch.await(5, TimeUnit.SECONDS)); | ||
assertEquals("ok", messages.get(0)); | ||
conn.closeAndAwait(); | ||
assertTrue(closedLatch.await(5, TimeUnit.SECONDS)); | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
...rc/test/java/io/quarkus/websockets/next/test/traffic/ClientEndpointTrafficLoggerTest.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,72 @@ | ||
package io.quarkus.websockets.next.test.traffic; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.websockets.next.OnClose; | ||
import io.quarkus.websockets.next.OnTextMessage; | ||
import io.quarkus.websockets.next.WebSocketClient; | ||
import io.quarkus.websockets.next.WebSocketClientConnection; | ||
import io.quarkus.websockets.next.WebSocketConnector; | ||
|
||
public class ClientEndpointTrafficLoggerTest extends TrafficLoggerTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(Endpoint.class, Client.class); | ||
TrafficLoggerTest.addApplicationProperties(root, false); | ||
}) | ||
.setLogRecordPredicate( | ||
TrafficLoggerTest::isTrafficLogRecord) | ||
.assertLogRecords(logRecordsConsumer(true)); | ||
|
||
@Inject | ||
WebSocketConnector<Client> connector; | ||
|
||
@Test | ||
public void testTrafficLogger() throws InterruptedException { | ||
WebSocketClientConnection conn = connector | ||
.baseUri(endUri) | ||
.connectAndAwait(); | ||
assertTrue(Client.MESSAGE_LATCH.await(5, TimeUnit.SECONDS)); | ||
assertEquals("ok", Client.MESSAGES.get(0)); | ||
conn.closeAndAwait(); | ||
assertTrue(Client.CLOSED_LATCH.await(5, TimeUnit.SECONDS)); | ||
assertTrue(Endpoint.CLOSED_LATCH.await(5, TimeUnit.SECONDS)); | ||
} | ||
|
||
@WebSocketClient(path = "/end") | ||
public static class Client { | ||
|
||
static final List<String> MESSAGES = new CopyOnWriteArrayList<>(); | ||
|
||
static final CountDownLatch MESSAGE_LATCH = new CountDownLatch(1); | ||
|
||
static final CountDownLatch CLOSED_LATCH = new CountDownLatch(1); | ||
|
||
@OnTextMessage | ||
void onMessage(String message) { | ||
MESSAGES.add(message); | ||
MESSAGE_LATCH.countDown(); | ||
} | ||
|
||
@OnClose | ||
void onClose() { | ||
CLOSED_LATCH.countDown(); | ||
} | ||
|
||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...oyment/src/test/java/io/quarkus/websockets/next/test/traffic/ServerTrafficLoggerTest.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,42 @@ | ||
package io.quarkus.websockets.next.test.traffic; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
|
||
public class ServerTrafficLoggerTest extends TrafficLoggerTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(Endpoint.class, WSClient.class); | ||
TrafficLoggerTest.addApplicationProperties(root, true); | ||
}) | ||
.setLogRecordPredicate(TrafficLoggerTest::isTrafficLogRecord) | ||
.assertLogRecords(logRecordsConsumer(false)); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@Test | ||
public void testTrafficLogger() throws InterruptedException, ExecutionException { | ||
try (WSClient client = new WSClient(vertx)) { | ||
client.connect(WSClient.toWS(endUri, "end")); | ||
client.waitForMessages(1); | ||
assertEquals("ok", client.getMessages().get(0).toString()); | ||
} | ||
assertTrue(Endpoint.CLOSED_LATCH.await(5, TimeUnit.SECONDS)); | ||
} | ||
|
||
} |
Oops, something went wrong.