Skip to content

Commit

Permalink
Virtual threads: integration tests refactoring
Browse files Browse the repository at this point in the history
- move the logic from AssertHelpers to a shared component - VirtualThreadsAssertions located in quarkus-test-vertx
  • Loading branch information
mkouba committed Oct 13, 2023
1 parent 14dd05e commit 8638dcb
Show file tree
Hide file tree
Showing 47 changed files with 160 additions and 929 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<!-- Use the "compile" scope because we need to include the VirtualThreadsAssertions in the app -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-vertx</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package io.quarkus.it.vthreads.amqp;

import static io.quarkus.it.vthreads.amqp.AssertHelper.assertThatItRunsOnADuplicatedContext;
import static io.quarkus.it.vthreads.amqp.AssertHelper.assertThatItRunsOnVirtualThread;

import java.util.Random;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -14,6 +11,7 @@
import org.eclipse.microprofile.reactive.messaging.Outgoing;
import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.quarkus.test.vertx.VirtualThreadsAssertions;
import io.smallrye.common.annotation.RunOnVirtualThread;

@ApplicationScoped
Expand All @@ -25,12 +23,12 @@ public class PriceConsumer {
@Incoming("prices")
@RunOnVirtualThread
public CompletionStage<Void> consume(Message<Double> msg) {
assertThatItRunsOnVirtualThread();
assertThatItRunsOnADuplicatedContext();
VirtualThreadsAssertions.assertThatItRunsOnVirtualThread();
VirtualThreadsAssertions.assertThatItRunsOnADuplicatedContext();
double price = msg.getPayload();
alertService.alertMessage(price);
return msg.ack().thenAccept(x -> {
assertThatItRunsOnADuplicatedContext();
VirtualThreadsAssertions.assertThatItRunsOnADuplicatedContext();
// While the ack always runs on event loop thread
// the post-ack may run on the processing virtual-thread which executed the method.
});
Expand All @@ -39,8 +37,8 @@ public CompletionStage<Void> consume(Message<Double> msg) {
@Incoming("prices")
@RunOnVirtualThread
public void consume(double price) {
assertThatItRunsOnVirtualThread();
assertThatItRunsOnADuplicatedContext();
VirtualThreadsAssertions.assertThatItRunsOnVirtualThread();
VirtualThreadsAssertions.assertThatItRunsOnADuplicatedContext();
alertService.alert(price);
}

Expand All @@ -50,7 +48,7 @@ public void consume(double price) {
@Outgoing("prices-out")
@RunOnVirtualThread
public Message<Double> randomPriceGenerator() {
assertThatItRunsOnVirtualThread();
VirtualThreadsAssertions.assertThatItRunsOnVirtualThread();
return Message.of(r.nextDouble() * 10 * i.incrementAndGet());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc</artifactId>
</dependency>

<!-- Use the "compile" scope because we need to include the VirtualThreadsAssertions in the app -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-vertx</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.quarkus.grpc.example.streaming;

import static io.quarkus.grpc.example.streaming.AssertHelper.assertEverything;

import com.google.protobuf.ByteString;
import com.google.protobuf.EmptyProtos;

import io.grpc.testing.integration.Messages;
import io.grpc.testing.integration.TestService;
import io.quarkus.grpc.GrpcService;
import io.quarkus.test.vertx.VirtualThreadsAssertions;
import io.smallrye.common.annotation.RunOnVirtualThread;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
Expand All @@ -18,39 +17,39 @@ public class TestServiceImpl implements TestService {
@RunOnVirtualThread
@Override
public Uni<EmptyProtos.Empty> emptyCall(EmptyProtos.Empty request) {
assertEverything();
VirtualThreadsAssertions.assertEverything();
return Uni.createFrom().item(EmptyProtos.Empty.newBuilder().build())
.invoke(AssertHelper::assertEverything);
.invoke(VirtualThreadsAssertions::assertEverything);
}

@RunOnVirtualThread
@Override
public Uni<Messages.SimpleResponse> unaryCall(Messages.SimpleRequest request) {
assertEverything();
VirtualThreadsAssertions.assertEverything();
var value = request.getPayload().getBody().toStringUtf8();
var resp = Messages.SimpleResponse.newBuilder()
.setPayload(Messages.Payload.newBuilder().setBody(ByteString.copyFromUtf8(value.toUpperCase())).build())
.build();
return Uni.createFrom().item(resp)
.invoke(AssertHelper::assertEverything);
.invoke(VirtualThreadsAssertions::assertEverything);
}

@Override
@RunOnVirtualThread
public Multi<Messages.StreamingOutputCallResponse> streamingOutputCall(Messages.StreamingOutputCallRequest request) {
var value = request.getPayload().getBody().toStringUtf8();
assertEverything();
VirtualThreadsAssertions.assertEverything();
return Multi.createFrom().<String> emitter(emitter -> {
assertEverything();
VirtualThreadsAssertions.assertEverything();
emitter.emit(value.toUpperCase());
emitter.emit(value.toUpperCase());
emitter.emit(value.toUpperCase());
emitter.complete();
}).map(v -> Messages.StreamingOutputCallResponse.newBuilder()
.setPayload(Messages.Payload.newBuilder().setBody(ByteString.copyFromUtf8(v)).build())
.build())
.invoke(AssertHelper::assertEverything)
.onTermination().invoke(AssertHelper::assertEverything);
.invoke(VirtualThreadsAssertions::assertEverything)
.onTermination().invoke(VirtualThreadsAssertions::assertEverything);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<!-- Use the "compile" scope because we need to include the VirtualThreadsAssertions in the app -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-vertx</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.it.vthreads.jms;

import static io.quarkus.it.vthreads.jms.AssertHelper.assertThatItRunsOnVirtualThread;

import java.util.Random;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -13,6 +11,7 @@
import org.eclipse.microprofile.reactive.messaging.Outgoing;
import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.quarkus.test.vertx.VirtualThreadsAssertions;
import io.smallrye.common.annotation.RunOnVirtualThread;

@ApplicationScoped
Expand All @@ -24,7 +23,7 @@ public class PriceConsumer {
@Incoming("prices")
@RunOnVirtualThread
public CompletionStage<Void> consume(Message<Double> msg) {
assertThatItRunsOnVirtualThread();
VirtualThreadsAssertions.assertThatItRunsOnVirtualThread();
double price = msg.getPayload();
alertService.alertMessage(price);
return msg.ack();
Expand All @@ -33,7 +32,7 @@ public CompletionStage<Void> consume(Message<Double> msg) {
@Incoming("prices")
@RunOnVirtualThread
public void consume(double price) {
assertThatItRunsOnVirtualThread();
VirtualThreadsAssertions.assertThatItRunsOnVirtualThread();
alertService.alert(price);
}

Expand All @@ -43,7 +42,7 @@ public void consume(double price) {
@Outgoing("prices-out")
@RunOnVirtualThread
public Message<Double> randomPriceGenerator() {
assertThatItRunsOnVirtualThread();
VirtualThreadsAssertions.assertThatItRunsOnVirtualThread();
return Message.of(r.nextDouble() * 10 * i.incrementAndGet());
}

Expand Down
Loading

0 comments on commit 8638dcb

Please sign in to comment.