-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
An application scoped bean instantiated twice #8960
Comments
@geoand is right. For a normal scoped bean a client proxy is always created when obtaining an injectable reference. This behavior is defined by the CDI spec. AFAIK in Do you control the |
I agree. This is standard behavior and Weld w/o relaxed construction should give you the same result. Some of the above suggestions should do the trick. |
You can probably just use @singleton instead of @ApplicationScoped. |
@stuartwdouglas The problem is that @miron4dev would like to use |
And there's absolutely no chance we could implement mocking for singletons? |
Not with the current test app lifecycle (one app for all tests). |
You could do it via a bytecode transformer, basically just add that same client proxy mocking code into all @singleton beans. |
Like modifying all the methods of a bean class? And if a mock exists then delegate to this mock instead of executing the method body? That could work. On the other hand, such a change looks quite "invasive". |
It's only for tests
…On Mon, 4 May 2020, 7:29 pm Martin Kouba, ***@***.***> wrote:
You could do it via a bytecode transformer, basically just add that same
client proxy mocking code into all @singleton
<https://github.com/singleton> beans.
Like modifying all the methods of a bean class? And if a mock exists then
delegate to this mock instead of executing the method body? That could
work. On the other hand, such a change looks quite "invasive".
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8960 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQG6YLGP7MIGKHBATDQ43RP2DHZANCNFSM4MTZD5EA>
.
|
That should work. I am +1. If we are worried it's to invasive, perhaps we would have a flag that the user needs to switch? There is only a one case I can think of were mockito would still complain: |
Yes, I know. My point is that the bigger the difference between the test and the prod environment is the bigger chance for unpredictable bugs. But that's a general problem with mocking ;-)
Ehm, what is it? |
Describe the bug
I want to create a bean only once during the application lifetime.
I have the next configuration
and inject
JedisPool
somewhere else.Expected behavior
JedisPool
constructor is called only once. So, I can guarantee that nobody instantiates this class except this call. Weld (at leastweld-se
) provides exactly the same behavior.Actual behavior
JedisPool
constructor is called twice. The first call with default no-args constructor, and the second one initiated by the method above.Environment (please complete the following information):
uname -a
orver
: Darwin localhost 19.0.0 Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64 x86_64java -version
: java version "1.8.0_231"mvnw --version
orgradlew --version
): Apache Maven 3.6.2Additional context
Why it is important: in this particular case I call
poolConfig.setJmxEnabled(false);
to make it work in the native mode because GraalVM is having some troubles with JMX. By default, JMX flag is enabled and the application is failing.@Singleton
annotation solves this issue, but in this case, I can't mock this bean usingQuarkusMock
The text was updated successfully, but these errors were encountered: