Comments (2)
Any possible fix will be greatly accelerated by a test case that exhibits the problem (and would theoretically pass if the issue were fixed).
from guice.
Hello - Here is some sample code with a test that fails when intercepting suspending functions in Kotlin
package interceptors
import com.google.inject.Guice
import com.google.inject.Injector
import com.google.inject.matcher.Matchers
import java.io.InterruptedIOException
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import misk.inject.KAbstractModule
import misk.inject.getInstance
import org.aopalliance.intercept.MethodInterceptor
import org.aopalliance.intercept.MethodInvocation
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
var successfulInterceptedCallCount: Int = 0
var failedInterceptedCallCount: Int = 0
class ClientMetricsInterceptorTest {
private lateinit var dinosaur: Dinosaur
private lateinit var clientMetricsInterceptor: ClientMetricsInterceptor
private lateinit var injector: Injector
@BeforeEach
fun before() {
injector = Guice.createInjector(
object : KAbstractModule() {
override fun configure() {
bindInterceptor(
Matchers.any(),
Matchers.annotatedWith(WithMetrics::class.java),
ClientMetricsInterceptor(),
)
// This makes the Dinosaur class a managed bean
// so that it can support method interception.
requestStaticInjection(Dinosaur::class.java)
}
}
)
dinosaur = injector.getInstance()
clientMetricsInterceptor = injector.getInstance()
}
@Test
fun `failure metrics published on interrupt`() {
runBlocking {
(1..100).map {
async {
try {
dinosaur.interceptedMethod(true)
} catch (e: InterruptedIOException) {
// exception caught!
}
}
}
}
assertThat(successfulInterceptedCallCount).isEqualTo(0)
assertThat(failedInterceptedCallCount).isEqualTo(100)
}
}
interface Animal {
suspend fun interceptedMethod(interrupt: Boolean)
}
open class Dinosaur @Inject constructor() : Animal {
@WithMetrics("dinosaur")
override suspend fun interceptedMethod(
interrupt: Boolean,
) {
delay(10)
if (interrupt) {
throw InterruptedIOException()
}
}
}
@Singleton class ClientMetricsInterceptor @Inject constructor() : MethodInterceptor {
override fun invoke(invocation: MethodInvocation?) = invocation?.let {
try {
it.proceed().also { successfulInterceptedCallCount++ }
} catch (e: InterruptedIOException) {
failedInterceptedCallCount++
throw e
}
}
}
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
annotation class WithMetrics(
val clientName: String,
)
from guice.
Related Issues (20)
- Annotations @Provides and @Singleton do not work together HOT 2
- HiddenClassDefiner incorrectly assumes Unsafe.staticFieldBase(Field) returns a real Object HOT 8
- Bob Lee,God bless You
- Feature Request: MicroProfile-config integration: Allow injecting annotations with jakarta.inject.Qualifier HOT 12
- where are the installation instructions? HOT 4
- java.lang.ClassCastException: class com.google.inject.servlet.GuiceFilter cannot be cast to class jakarta.servlet.Filter (com.google.inject.servlet.GuiceFilter is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @e383572; jakarta.servlet.Filter is in unnamed module of loader java.net.URLClassLoader @2ef1e4fa) HOT 1
- Changed behaviour in Guice 7 HOT 3
- Struts 6.x.x not working with Guice HOT 9
- Possible leak using Guice HOT 5
- Performance Issue in getJustInTimeBinding Method HOT 1
- Misleading exception message for nested Guice injector failure
- 8 Flaky tests in the module extensions/throwingproviders
- Request/Question: Provide non-jarjar'd builds
- Enable to define a custom "@Inject" marker (ie add some extension point for reflection doing getAnnotation/isAnnotationPresent on this marker)
- Implement a functionality similar to Spring Boot’s fully automatic configuration dependency injection
- Replace Guava with standard Java (where possible) HOT 3
- Vulnerabilities referenced in version 7
- GCP OAuth2 auth method failed through Java SDK when trying to build a Docker image in local
- High memory consumption to obtain a Singleton instance via Injector or Provider HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guice.