Make the CheckingSender used in tests less GC aggressive

This commit is contained in:
Julien Viet
2019-04-15 14:22:18 +02:00
parent b26822decf
commit 5c0642a720
2 changed files with 22 additions and 14 deletions

View File

@@ -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();
}

View File

@@ -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());
}
}