mirror of
https://github.com/jlengrand/vert.x.git
synced 2026-03-10 08:51:19 +00:00
Make the CheckingSender used in tests less GC aggressive
This commit is contained in:
@@ -22,6 +22,7 @@ import io.vertx.core.impl.VertxInternal;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.net.*;
|
||||
import io.vertx.core.net.impl.ConnectionBase;
|
||||
import io.vertx.core.parsetools.RecordParser;
|
||||
import io.vertx.test.core.Repeat;
|
||||
import io.vertx.test.core.CheckingSender;
|
||||
@@ -4540,7 +4541,7 @@ public class Http1xTest extends HttpTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHttpServerRequestShouldExceptionHandlerWhenTheClosedHandlerIsCalled() {
|
||||
public void testHttpServerRequestShouldCallExceptionHandlerWhenTheClosedHandlerIsCalled() {
|
||||
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).requestHandler(req -> {
|
||||
HttpServerResponse resp = req.response();
|
||||
resp.setChunked(true);
|
||||
@@ -4566,7 +4567,7 @@ public class Http1xTest extends HttpTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHttpClientRequestShouldExceptionHandlerWhenTheClosedHandlerIsCalled() throws Exception {
|
||||
public void testHttpClientRequestShouldCallExceptionHandlerWhenTheClosedHandlerIsCalled() throws Exception {
|
||||
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).requestHandler(req -> {
|
||||
vertx.setTimer(1000, id -> {
|
||||
req.response().close();
|
||||
@@ -4575,19 +4576,21 @@ public class Http1xTest extends HttpTest {
|
||||
startServer();
|
||||
HttpClientRequest req = client.put(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/someuri", resp -> {
|
||||
}).setChunked(true);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
req.sendHead(version -> latch.countDown());
|
||||
awaitLatch(latch);
|
||||
CheckingSender sender = new CheckingSender(vertx.getOrCreateContext(), req);
|
||||
AtomicBoolean connected = new AtomicBoolean();
|
||||
req.exceptionHandler(err -> {
|
||||
assertTrue(connected.get());
|
||||
Throwable failure = sender.close();
|
||||
if (failure != null) {
|
||||
fail(failure);
|
||||
} else {
|
||||
} else if (err == ConnectionBase.CLOSED_EXCEPTION) {
|
||||
testComplete();
|
||||
}
|
||||
});
|
||||
sender.send();
|
||||
req.sendHead(v -> {
|
||||
connected.set(true);
|
||||
sender.send();
|
||||
});
|
||||
await();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.vertx.test.core;
|
||||
|
||||
import io.vertx.core.Context;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.streams.WriteStream;
|
||||
|
||||
@@ -30,15 +31,19 @@ public class CheckingSender {
|
||||
}
|
||||
|
||||
public void send() {
|
||||
if (countDown > 0) {
|
||||
try {
|
||||
stream.write(data);
|
||||
} catch (Exception e) {
|
||||
if (error == null) {
|
||||
error = e;
|
||||
return;
|
||||
if (Vertx.currentContext() == context) {
|
||||
if (countDown > 0) {
|
||||
try {
|
||||
stream.write(data);
|
||||
} catch (Exception e) {
|
||||
if (error == null) {
|
||||
error = e;
|
||||
return;
|
||||
}
|
||||
}
|
||||
context.owner().setTimer(1, id -> send());
|
||||
}
|
||||
} else {
|
||||
context.runOnContext(v -> send());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user