Quartz Plugin

bootstrap fails in integration tests since APPLICATION_CONTEXT attribute is not available

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 0.4.2
  • Component/s: None
  • Labels:
    None
  • Environment:
    Grails 1.1.1, Quartz 0.4.1-SNAPSHOT

Description

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

Activity

Hide
Bradley Booth added a comment -

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.

Show
Bradley Booth added a comment - 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.
Hide
Björn Wilmsmann added a comment -

Workaround, change QuartzConfig.groovy as follows:

import grails.util.Environment

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

Show
Björn Wilmsmann added a comment - Workaround, change QuartzConfig.groovy as follows: import grails.util.Environment quartz { if (Environment.current != Environment.TEST) { autoStartup = true } else { autoStartup = false } jdbcStore = false }
Hide
Helmut Denk added a comment -

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)
Show
Helmut Denk added a comment - 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)
Hide
Sergey Nebolsin added a comment - - edited

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

Show
Sergey Nebolsin added a comment - - edited Helmut, that is another issue GRAILSPLUGINS-742 and it is already fixed in the 0.4.1-SNAPSHOT.
Hide
Cyril Picat added a comment -

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?

Show
Cyril Picat added a comment - 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?
Hide
Björn Wilmsmann added a comment -

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.

Show
Björn Wilmsmann added a comment - 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.
Hide
Sergey Nebolsin added a comment -

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

Show
Sergey Nebolsin added a comment - Changed the DefaultQuartzConfig.groovy file to have 'autoStartup = false' for test environment.
Hide
Cyril Picat added a comment -

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?

Show
Cyril Picat added a comment - 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?
Hide
Sergey Nebolsin added a comment -

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

Show
Sergey Nebolsin added a comment - You could turn quartzScheduler on for this specific test by injecting Quartz sheduler ('def quartzSheduler') and using quartzScheduler.start().
Hide
Sergey Nebolsin added a comment -

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.

Show
Sergey Nebolsin added a comment - 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.
Hide
Cyril Picat added a comment -

Thanks Sergey, your solution worked fine for my problem.

Show
Cyril Picat added a comment - Thanks Sergey, your solution worked fine for my problem.
Hide
Burt Beckwith added a comment -

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 = {}
}
Show
Burt Beckwith added a comment - 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 = {}
}
Hide
Sergey Nebolsin added a comment -

Thanks, Burt! I commited your change to the plugin.

Show
Sergey Nebolsin added a comment - Thanks, Burt! I commited your change to the plugin.

People

Vote (8)
Watch (12)

Dates

  • Created:
    Updated:
    Resolved: