[ 
https://issues.apache.org/jira/browse/DELTASPIKE-1198?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15434950#comment-15434950
 ] 

Sean Flanigan commented on DELTASPIKE-1198:
-------------------------------------------

[~johndament] The validators themselves aren't terribly complex - at worst, 
they might just use a DAO to check for a duplicate email address.  But I do 
have a mix of very simple validators which don't even need mocks to test, and 
other validators like the duplicate email validator which need injection of 
things like DAOs. Switching them all to CDI tests would get around the problem, 
but that's quite a bit of work, especially for any tests which already needed a 
custom JUnit Runner. 

I don't know how to tell Hibernate to use a non-CDI ConstraintValidatorFactory 
for simple unit tests, and use CdiAwareConstraintValidatorFactory or 
InjectingConstraintValidatorFactory for the others, so the next best thing 
would be a ConstraintValidatorFactory which chooses between them, depending on 
the state of CDI. BeanManagerProvider is generally a really handy class for 
low-level CDI stuff like getting a BeanManager, so it's a shame {{isActive()}} 
can't be used for this.

I'm not using Test-Control, but I am using CDI-Unit, together with Weld SE, 
which does a lot of the same things. From what I can tell, it is shutting down 
the Weld deployment between tests, at least enough to blow up when 
BeanManagerProvider tries to use it. 

The weird thing is that the class BeanManagerProvider is retaining a static 
reference to a object which were created by the first Weld container (including 
an instance of BeanManagerProvider itself, which holds a BeanManager), even 
after that container has stopped. That doesn't cause a problem most of the time 
(except a minor memory leak on shutdown perhaps), but it does cause 
{{isActive()}} to violate its own javadoc IMHO. 

Have you got any idea why the BeanManagerProvider needs to retain state after 
container shutdown?

> BeanManagerProvider.isActive() returns true after container shutdown
> --------------------------------------------------------------------
>
>                 Key: DELTASPIKE-1198
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-1198
>             Project: DeltaSpike
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.7.0, 1.7.2
>            Reporter: Sean Flanigan
>
> While trying to implement DELTASPIKE-1197 I found that 
> {{BeanManagerProvider.isActive()}} returns true after container shutdown.
> The javadocs for {{isActive()}} say "@return true if the BeanManagerProvider 
> is ready to be used", but when it is in this state, the BeanManagerProvider 
> can't actually be used because the CDI container is not active. 
> In the case of Weld, when {{BeanProvider.getContextualReference()}} was 
> called I got errors like "java.lang.IllegalStateException: Singleton not set 
> for STATIC_INSTANCE => []". There was no stack trace, but that message comes 
> from Weld's RegistrySingletonProvider.java.
> It would seem reasonable to reset bmpSingleton to null during 
> cleanupStoredBeanManagerOnShutdown, but for some reason this breaks a lot of 
> tests.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to