Skip to content

Commit

Permalink
Virtual threads
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Deandrea <[email protected]>
  • Loading branch information
edeandrea committed Jan 5, 2024
1 parent 9b9d64d commit 073fd35
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions grpc-locations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<argLine>-Djdk.tracePinnedThreads</argLine>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@ package io.quarkus.sample.superheroes.location.grpc

import io.grpc.Status
import io.grpc.stub.StreamObserver
import io.smallrye.common.annotation.Blocking
import io.quarkus.grpc.GrpcService
import io.quarkus.logging.Log
import io.quarkus.sample.superheroes.location.grpc.LocationsGrpc.LocationsImplBase
import io.quarkus.sample.superheroes.location.mapping.LocationMapper
import io.quarkus.sample.superheroes.location.service.LocationService
import io.smallrye.common.annotation.Blocking
import io.smallrye.common.annotation.RunOnVirtualThread

@GrpcService
class LocationGrpcService(private val locationService: LocationService) : LocationsImplBase() {
@Blocking
@RunOnVirtualThread
override fun getRandomLocation(request: RandomLocationRequest?, responseObserver: StreamObserver<Location>?) {
Log.debug("Requesting a random location")
returnLocationOrError(this.locationService.getRandomLocation(), responseObserver)
responseObserver?.onCompleted()
}

@Blocking
@RunOnVirtualThread
override fun getLocationByName(request: GetLocationRequest?, responseObserver: StreamObserver<Location>?) {
if (request != null) {
Log.debug("Getting location ${request.name}")
Expand All @@ -29,6 +32,7 @@ class LocationGrpcService(private val locationService: LocationService) : Locati
}

@Blocking
@RunOnVirtualThread
override fun replaceAllLocations(request: LocationsList?, responseObserver: StreamObserver<ReplaceAllLocationsResponse>?) {
if (request != null) {
Log.debug("Replacing all locations")
Expand All @@ -43,6 +47,7 @@ class LocationGrpcService(private val locationService: LocationService) : Locati
}

@Blocking
@RunOnVirtualThread
override fun getAllLocations(request: AllLocationsRequest?, responseObserver: StreamObserver<LocationsList>?) {
val allLocations = this.locationService.getAllLocations()
Log.debug("Got all locations: $allLocations")
Expand All @@ -55,6 +60,7 @@ class LocationGrpcService(private val locationService: LocationService) : Locati
}

@Blocking
@RunOnVirtualThread
override fun deleteAllLocations(request: DeleteAllLocationsRequest?, responseObserver: StreamObserver<DeleteAllLocationsResponse>?) {
Log.debug("Deleting all locations")

Expand Down
1 change: 0 additions & 1 deletion rest-villains/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@
<goal>verify</goal>
</goals>
<configuration>
<argLine>-Djdk.tracePinnedThreads</argLine>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.quarkus.sample.superheroes.villain.service.VillainService;

import io.smallrye.common.annotation.Blocking;
import io.smallrye.common.annotation.RunOnVirtualThread;

@Path("/")
public class UIResource {
Expand All @@ -30,6 +31,7 @@ static class Templates {
@GET
@Produces(MediaType.TEXT_HTML)
@Blocking
@RunOnVirtualThread
public TemplateInstance get(@QueryParam("name_filter") Optional<String> nameFilter) {
var villains = nameFilter
.map(this.service::findAllVillainsHavingName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import io.quarkus.sample.superheroes.villain.Villain;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit5.virtual.ShouldNotPin;
import io.quarkus.test.junit5.virtual.VirtualThreadUnit;

import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.Locator;
Expand All @@ -23,6 +25,8 @@

@QuarkusTest
@WithPlaywright
@VirtualThreadUnit
@ShouldNotPin
class UIResourceTests {
private static final int NB_VILLAINS = 100;
private static final Villain DARTH_VADER = getDarthVader();
Expand Down

0 comments on commit 073fd35

Please sign in to comment.