-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Scenario: RequestScope custom context was removed after `javax.en…
…terprise` event propagation When firing an async CDI Event, the requestScope context from the emitter briefly exists for the observer and is then terminated. This commit is a reproducer of this scenario that happens on Quarkus 2.13.0.Final
- Loading branch information
pablo gonzalez granados
committed
Jan 16, 2023
1 parent
2350b46
commit 9f4d78b
Showing
3 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/HelloResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,66 @@ | ||
package io.quarkus.ts.http.advanced; | ||
|
||
import java.time.Duration; | ||
import java.util.Objects; | ||
|
||
import javax.enterprise.event.Event; | ||
import javax.enterprise.event.ObservesAsync; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.DefaultValue; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.NotFoundException; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Path("/hello") | ||
public class HelloResource { | ||
private static final String TEMPLATE = "Hello, %s!"; | ||
private static final int TIMEOUT_MS = 250; | ||
private String contextValueAfterEventPropagation; | ||
|
||
@Inject | ||
Event<String> event; | ||
|
||
@Inject | ||
LocalCustomContext localCustomContext; | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Hello get(@QueryParam("name") @DefaultValue("World") String name) { | ||
return new Hello(String.format(TEMPLATE, name)); | ||
} | ||
|
||
@PUT() | ||
@Path("/local-context/{value}") | ||
public void updateContext(@PathParam("value") String value) { | ||
event.fireAsync(value); | ||
} | ||
|
||
@GET() | ||
@Path("/local-context/{value}") | ||
public String retrieveContextValue(@PathParam("value") String value) { | ||
if (Objects.isNull(contextValueAfterEventPropagation)) { | ||
throw new NotFoundException(String.format("Resource %s not found!", value)); | ||
} | ||
|
||
return contextValueAfterEventPropagation; | ||
} | ||
|
||
void dequeueProcessingRequests(@ObservesAsync String value) { | ||
localCustomContext.set(value); | ||
// 'wait' is required in order to reproduce the issue https://github.com/quarkusio/quarkus/issues/29017 | ||
wait(Duration.ofMillis(TIMEOUT_MS)); | ||
contextValueAfterEventPropagation = localCustomContext.get(); | ||
} | ||
|
||
private void wait(Duration timeout) { | ||
try { | ||
Thread.sleep(timeout.toMillis()); | ||
} catch (Exception e) { | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/LocalCustomContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quarkus.ts.http.advanced; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
|
||
@RequestScoped | ||
public class LocalCustomContext { | ||
|
||
String value; | ||
|
||
public void set(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String get() { | ||
return value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters