Issue Details (XML | Word | Printable)

Key: GRAILSPLUGINS-1159
Type: Bug Bug
Status: Reopened Reopened
Priority: Major Major
Assignee: Sergey Nebolsin
Reporter: Marcus Better
Votes: 8
Watchers: 12
Operations

If you were logged in you would be able to see more operations.
Grails Plugins

bootstrap fails in integration tests since APPLICATION_CONTEXT attribute is not available

Created: 14/May/09 10:59 AM   Updated: 10/Jul/09 10:45 PM
Return to search
Component/s: Grails-Quartz
Affects Version/s: None
Fix Version/s: Grails-Quartz 0.4.1

Time Tracking:
Not Specified

Environment: Grails 1.1.1, Quartz 0.4.1-SNAPSHOT


 Description  « Hide

Grails 1.1.1 runs bootstrap classes in integration tests. This seems to break the Quartz plugin:

gant.TargetExecutionException: java.lang.NullPointerException: Cannot get property 'quartzScheduler' on null object
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:331)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:344)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:334)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:495)
at gant.Gant.processTargets(Gant.groovy:480)
Caused by: java.lang.NullPointerException: Cannot get property 'quartzScheduler' on null object
at QuartzBootStrap$_closure1.doCall(QuartzBootStrap.groovy:30)
at _GrailsTest_groovy$_run_closure7.doCall(_GrailsTest_groovy:261)
at _GrailsTest_groovy$_run_closure7.doCall(_GrailsTest_groovy)
at _GrailsTest_groovy$_run_closure1_closure19.doCall(_GrailsTest_groovy:110)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:96)
at TestApp$_run_closure1.doCall(TestApp.groovy:66)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
... 10 more



Bradley Booth added a comment - 15/May/09 01:35 PM

I created a new 1.1.1 app and only installed the quartz plugin in order to duplicate the issue. Ran grails test-app and received same stack trace. Hope that helps.


Björn Wilmsmann added a comment - 16/May/09 01:18 PM

Workaround, change QuartzConfig.groovy as follows:

import grails.util.Environment

quartz {
if (Environment.current != Environment.TEST) { autoStartup = true } else { autoStartup = false }
jdbcStore = false
}


Helmut Denk added a comment - 18/May/09 03:57 AM

btw. an error occurs when i am running the command

grails install-quartz-config

 
Running script C:\Dokumente und Einstellungen\zadkh\.grails\1.1.1\projects\grails111-test\plugins\quartz-0.3.3\scripts\InstallQuartzConfig.groovy
Error executing script InstallQuartzConfig: null\scripts\Init.groovy (Das System kann den angegebenen Pfad nicht finden)
java.io.FileNotFoundException: null\scripts\Init.groovy (Das System kann den angegebenen Pfad nicht finden)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(FileInputStream.java:106)
	at gant.Gant$_closure1.doCall(Gant.groovy:120)
	at gant.Gant$_closure1.call(Gant.groovy)
	at InstallQuartzConfig.run(InstallQuartzConfig:26)
	at InstallQuartzConfig$run.call(Unknown Source)
	at gant.Gant.processTargets(Gant.groovy:494)
	at gant.Gant.processTargets(Gant.groovy:480)

Sergey Nebolsin added a comment - 18/May/09 04:24 AM - edited

Helmut, that is another issue GRAILSPLUGINS-742 and it is already fixed in the 0.4.1-SNAPSHOT.


Cyril Picat added a comment - 26/May/09 10:05 AM

The workaround seems to fix the problem for me too.

But I have a problem with this workaround: I now have an integration test that ends up in an infinite loop.

This test triggers a Quartz job (with quartzScheduler.triggerJob()) and waits until it finishes to check that the job has been doing what it is supposed to do (send an email).
Any idea on how to solve this? I guess this is related to setting autoStartup to false in TEST?


Björn Wilmsmann added a comment - 26/May/09 11:20 AM

As the configuration option simply tells Quartz to automatically start job scheduling on app startup starting job scheduling in that specific integration test should solve this problem. At the moment, I don't know exactly how to do this. However, QuartzBootStrap.groovy should serve pretty well as a guideline.


Sergey Nebolsin made changes - 22/Jun/09 08:16 AM
Field Original Value New Value
Status Open [ 1 ] In Progress [ 3 ]
Sergey Nebolsin added a comment - 22/Jun/09 08:53 AM

Changed the DefaultQuartzConfig.groovy file to have 'autoStartup = false' for test environment.


Sergey Nebolsin made changes - 22/Jun/09 08:53 AM
Resolution Fixed [ 1 ]
Fix Version/s Grails-Quartz 0.4.1 [ 14309 ]
Status In Progress [ 3 ] Resolved [ 5 ]
Cyril Picat added a comment - 23/Jun/09 07:31 AM

Am I right in saying that this fix does not solve my problem, ie testing Quartz jobs in integration tests?
Should this bug be considered as fixed, thus?


Sergey Nebolsin added a comment - 23/Jun/09 08:13 AM

You could turn quartzScheduler on for this specific test by injecting Quartz sheduler ('def quartzSheduler') and using quartzScheduler.start().


Sergey Nebolsin added a comment - 23/Jun/09 08:48 AM

Ok, I found GRAILS-4609 which is related to this issue. I'll reopen this issue for now and wait for corresponding Grails issue to be fixed.


Sergey Nebolsin made changes - 23/Jun/09 08:48 AM
Status Resolved [ 5 ] Reopened [ 4 ]
Resolution Fixed [ 1 ]
Cyril Picat added a comment - 25/Jun/09 03:12 AM

Thanks Sergey, your solution worked fine for my problem.


Burt Beckwith added a comment - 10/Jul/09 10:45 PM

I had the same issue but fixed it differently. The problem seemed to be with getting the ApplicationContext, so I used dependency injection instead for the 'quartzScheduler' bean:

class QuartzBootStrap {

    def quartzScheduler

    def init = {servletContext ->
        if (ConfigurationHolder.config?.quartz?.autoStartup) quartzScheduler.start()
    }
    def destroy = {}
}