Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test of the vertx context reference factory pr #1160

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
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
@@ -0,0 +1,20 @@
package org.acme.hibernate;

import javax.annotation.PreDestroy;
import javax.enterprise.context.RequestScoped;

@RequestScoped
public class MyBean {

int count = 0;

public int incrAndGet() {
return count++;
}

@PreDestroy
public void destroy() {
System.out.println("Oh no! I'm going to be destroyed");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import javax.ws.rs.core.Response;

import io.smallrye.mutiny.Uni;

import org.acme.hibernate.MyBean;
import org.hibernate.reactive.mutiny.Mutiny.SessionFactory;

@Path("fruits")
Expand All @@ -30,11 +32,15 @@ public class FruitMutinyResource {
@Inject
SessionFactory sf;

@Inject MyBean bean;

@GET
public Uni<List<Fruit>> get() {
System.out.println(">> " + bean.incrAndGet());
return sf.withTransaction((s,t) -> s
.createNamedQuery("Fruits.findAll", Fruit.class)
.getResultList()
.invoke(() -> System.out.println(">> " + bean.incrAndGet()))
);
}

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

import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;
import io.vertx.mutiny.core.Vertx;

import org.eclipse.microprofile.rest.client.inject.RestClient;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import java.util.Set;
Expand All @@ -15,23 +18,31 @@ public class ExtensionsResource {
@RestClient
ExtensionsService extensionsService;

@Inject MyBean bean;

@GET
@Path("/id/{id}")
@Blocking
public Set<Extension> id(String id) {
bean.log();
return extensionsService.getById(id);
}

@GET
@Path("/id-async/{id}")
public CompletionStage<Set<Extension>> idAsync(String id) {
return extensionsService.getByIdAsync(id);
bean.log();
return extensionsService.getByIdAsync(id)
.whenComplete((r, f) -> bean.log());
}

@GET
@Path("/id-uni/{id}")
public Uni<Set<Extension>> idUni(String id) {
return extensionsService.getByIdAsUni(id);
bean.log();
System.out.println("DC is " + Vertx.currentContext());
return extensionsService.getByIdAsUni(id)
.invoke(() -> bean.log()); // PB HERE - request scope suspended and not resumed, so no access.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.acme.rest.client;

import javax.annotation.PreDestroy;
import javax.enterprise.context.RequestScoped;

@RequestScoped
public class MyBean {

int count = 0;

public int incrAndGet() {
return count++;
}

@PreDestroy
public void destroy() {
System.out.println(this + " - Oh no! I'm going to be destroyed");
}

public void log() {
System.out.println(this + " >> " + incrAndGet());
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.acme.rest.client;

import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext;
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestFilter;

import io.quarkus.arc.Arc;
import io.vertx.core.Vertx;

import javax.annotation.Priority;
import javax.enterprise.context.control.ActivateRequestContext;
import javax.inject.Inject;
import javax.ws.rs.ext.Provider;

@Provider
@Priority(1)
public class MyRequestFilter implements ResteasyReactiveClientRequestFilter {

@Inject
MyBean myRequestScopedBean;

@Override
@ActivateRequestContext
public void filter(ResteasyReactiveClientRequestContext requestContext) {
System.out.println("MyRequestFilter " + Arc.container().requestContext());
System.out.println("Is active? " + Arc.container().requestContext().isActive());
System.out.println("in req filter DC is " + Vertx.currentContext());
myRequestScopedBean.log();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.acme.rest.client;

import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext;
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientResponseFilter;

import io.quarkus.arc.Arc;
import io.vertx.core.Vertx;

import javax.enterprise.context.control.ActivateRequestContext;
import javax.inject.Inject;
import javax.ws.rs.client.ClientResponseContext;
import javax.ws.rs.ext.Provider;

@Provider
public class MyResponseFilter implements ResteasyReactiveClientResponseFilter{
@Inject
MyBean myRequestScopedBean;

@Override
@ActivateRequestContext
public void filter(ResteasyReactiveClientRequestContext requestContext, ClientResponseContext responseContext) {
System.out.println("Response filter called on " + Thread.currentThread().getName());
System.out.println("MyResponseFilter " + Arc.container().requestContext() + " / " + Arc.container().requestContext().isActive());
System.out.println("in resp filter DC is " + Vertx.currentContext());
myRequestScopedBean.log();
}
}