Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ public BlockingWriterData blockingWriterOnIoThread() {
@GET
@Path("async-writer-on-io-thread")
public AsyncWriterData asyncWriterOnIoThread() {
return new AsyncWriterData(true, false);
return new AsyncWriterData(false, "async-io");
}

@GET
@Path("slow-async-writer-on-io-thread")
public AsyncWriterData slowAsyncWriterOnIoThread() {
return new AsyncWriterData(true, true);
return new AsyncWriterData(true, "slow-async-io");
}

@GET
Expand All @@ -167,13 +167,13 @@ public CompletionStage<BlockingWriterData> blockingWriterOnWorkerThread() {
@GET
@Path("async-writer-on-worker-thread")
public CompletionStage<AsyncWriterData> asyncWriterOnWorkerThread() {
return CompletableFuture.supplyAsync(() -> new AsyncWriterData(false, true));
return CompletableFuture.supplyAsync(() -> new AsyncWriterData(false, "async-worker"));
}

@GET
@Path("slow-async-writer-on-worker-thread")
public CompletionStage<AsyncWriterData> slowAsyncWriterOnWorkerThread() {
return CompletableFuture.supplyAsync(() -> new AsyncWriterData(false, true));
return CompletableFuture.supplyAsync(() -> new AsyncWriterData(true, "slow-async-worker"));
}

private <T> CompletionStage<T> async(T value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

@Disabled("See issue 24")
public class AsyncIOTest {

static Client client;
Expand Down Expand Up @@ -79,23 +77,23 @@ public void testAsyncIo() throws Exception {

target = client.target(generateURL("/async-io/async-writer-on-io-thread"));
val = target.request().get(String.class);
Assertions.assertEquals("OK", val);
Assertions.assertEquals("async-io", val);

target = client.target(generateURL("/async-io/slow-async-writer-on-io-thread"));
val = target.request().get(String.class);
Assertions.assertEquals("OK", val);
Assertions.assertEquals("slow-async-io", val);

target = client.target(generateURL("/async-io/blocking-writer-on-worker-thread"));
val = target.request().get(String.class);
Assertions.assertEquals("OK", val);

target = client.target(generateURL("/async-io/async-writer-on-worker-thread"));
val = target.request().get(String.class);
Assertions.assertEquals("OK", val);
Assertions.assertEquals("async-worker", val);

target = client.target(generateURL("/async-io/slow-async-writer-on-worker-thread"));
val = target.request().get(String.class);
Assertions.assertEquals("OK", val);
Assertions.assertEquals("slow-async-worker", val);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

Expand All @@ -16,8 +17,6 @@
import org.jboss.resteasy.spi.AsyncMessageBodyWriter;
import org.jboss.resteasy.spi.AsyncOutputStream;

import io.vertx.core.Context;

@Provider
public class AsyncWriter implements AsyncMessageBodyWriter<AsyncWriterData> {

Expand All @@ -38,7 +37,6 @@ public void writeTo(AsyncWriterData t, Class<?> type, Type genericType, Annotati
public CompletionStage<Void> asyncWriteTo(AsyncWriterData t, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
AsyncOutputStream entityStream) {
String resp = t.expectOnIoThread == Context.isOnEventLoopThread() ? "OK" : "KO";
CompletionStage<Void> start = t.simulateSlowIo
? CompletableFuture.runAsync(() -> {
try {
Expand All @@ -48,7 +46,7 @@ public CompletionStage<Void> asyncWriteTo(AsyncWriterData t, Class<?> type, Type
}
})
: CompletableFuture.completedFuture(null);
return start.thenCompose(v -> entityStream.asyncWrite(resp.getBytes(Charset.forName("UTF-8"))))
return start.thenCompose(v -> entityStream.asyncWrite(t.expectedValue.getBytes(StandardCharsets.UTF_8)))
.thenCompose(v -> entityStream.asyncFlush());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public class AsyncWriterData {

public final boolean expectOnIoThread;
public final boolean simulateSlowIo;
public final String expectedValue;

public AsyncWriterData(final boolean expectOnIoThread, final boolean simulateSlowIo) {
this.expectOnIoThread = expectOnIoThread;
public AsyncWriterData(final boolean simulateSlowIo, final String expectedValue) {
this.simulateSlowIo = simulateSlowIo;
this.expectedValue = expectedValue;
}

}