-
Notifications
You must be signed in to change notification settings - Fork 374
cdi-inject-weld: make SupplierContractsTest deterministic #6022
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
base: 2.x
Are you sure you want to change the base?
cdi-inject-weld: make SupplierContractsTest deterministic #6022
Conversation
|
It is difficult to check this because text has been reformatted. Could you restore the previous format, please?. |
|
Sure! My pleasure! |
6769255 to
54d8485
Compare
| // ---------- ClassBinding ---------- | ||
| if (ClassBinding.class.isAssignableFrom(binding.getClass())) { | ||
| final ClassBinding<?> cb = (ClassBinding<?>) binding; | ||
|
|
||
| // Keep existing "update" path for CLIENT | ||
| if (RuntimeType.CLIENT == runtimeType) { | ||
| for (Type contract : ((ClassBinding<?>) binding).getContracts()) { | ||
| final List<BindingBeanPair> preregistered = classBindings.get(contract); | ||
| if (preregistered != null && preregistered.size() == 1) { | ||
| BeanHelper.updateBean( | ||
| (ClassBinding<?>) binding, preregistered.get(0), injectionResolvers, beanManager); | ||
| for (Type contract : cb.getContracts()) { | ||
| final java.util.List<BindingBeanPair> pre = classBindings.get(contract); | ||
| if (pre != null && pre.size() == 1) { | ||
| BeanHelper.updateBean(cb, pre.get(0), injectionResolvers, beanManager); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section of here is is just renaming, right?. It does not modify any functionality.
I suggest to not do this refactoring because of two reasons:
- It is more difficult to focus in the real change of the PR.
- It adds noise when you want track changes of a file.
|
|
||
| // ---------- SupplierClassBinding ---------- | ||
| } else if (SupplierClassBinding.class.isAssignableFrom(binding.getClass())) { | ||
| final SupplierClassBinding<?> scb = (SupplierClassBinding<?>) binding; | ||
|
|
||
| // Keep existing "update" path for CLIENT | ||
| if (RuntimeType.CLIENT == runtimeType) { | ||
| for (Type contract : ((SupplierClassBinding<?>) binding).getContracts()) { | ||
| final List<BindingBeanPair> preregistered = supplierClassBindings.get(contract); | ||
| if (preregistered != null && preregistered.size() == 1) { | ||
| for (Type contract : scb.getContracts()) { | ||
| final java.util.List<BindingBeanPair> pre = supplierClassBindings.get(contract); | ||
| if (pre != null && pre.size() == 1) { | ||
| BeanHelper.updateSupplierBean( | ||
| (SupplierClassBinding<?>) binding, preregistered.get(0), injectionResolvers, beanManager); | ||
| scb, pre.get(0), injectionResolvers, beanManager); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also refactoring, that we can avoid in this PR.
| // ---------- Instance bindings (unchanged) ---------- | ||
| } else if (InitializableInstanceBinding.class.isAssignableFrom(binding.getClass())) { | ||
| if (RuntimeType.SERVER == runtimeType | ||
| || !matchInitializableInstanceBinding((InitializableInstanceBinding<?>) binding)) { | ||
| initializableInstanceBindings.add((InitializableInstanceBinding<?>) binding); | ||
| BeanHelper.registerBean( | ||
| runtimeType, (InitializableInstanceBinding<?>) binding, abd, injectionResolvers, beanManager); | ||
| runtimeType, (InitializableInstanceBinding<?>) binding, | ||
| abd, injectionResolvers, beanManager); | ||
| } | ||
| } else if (InitializableSupplierInstanceBinding.class.isInstance(binding)) { | ||
| if (RuntimeType.SERVER == runtimeType | ||
| || !matchInitializableSupplierInstanceBinding((InitializableSupplierInstanceBinding) binding)) { | ||
| initializableSupplierInstanceBindings.add((InitializableSupplierInstanceBinding) binding); | ||
| BeanHelper.registerSupplier(runtimeType, (InitializableSupplierInstanceBinding<?>) binding, abd, beanManager); | ||
| || !matchInitializableSupplierInstanceBinding( | ||
| (InitializableSupplierInstanceBinding) binding)) { | ||
| initializableSupplierInstanceBindings.add( | ||
| (InitializableSupplierInstanceBinding) binding); | ||
| BeanHelper.registerSupplier( | ||
| runtimeType, (InitializableSupplierInstanceBinding<?>) binding, | ||
| abd, beanManager); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is refactoring too
|
@minizhiren I am not quite sure what the purpose of this PR is. Do you use the module with 2.x Jersey? Or is the purpose to just to fix the test? I am just curious about the usage of this module by the community. This module is meant to be used mainly in EE 12, and there was a significant development in the latest (4.0/4.0.JPMS) branch. |
Root cause: binder registration order and reuse were nondeterministic, causing SupplierContractsTest to be flaky.
Fix: register bindings deterministically and reuse them safely (IdentityHashMap for insertion-order semantics; cleanup of binder cache).
Test: SupplierContractsTest now passes reliably across runs/seeds.