Class RestartableJenkinsRule
- java.lang.Object
-
- org.jvnet.hudson.test.RestartableJenkinsRule
-
- All Implemented Interfaces:
org.junit.rules.MethodRule
public class RestartableJenkinsRule extends Object implements org.junit.rules.MethodRule
Provides a pattern for executing a sequence of steps. In between steps, Jenkins gets restarted.To use this, add this rule instead of
JenkinsRule
to the test, then from your test method, callthen(org.jvnet.hudson.test.RestartableJenkinsRule.Step)
repeatedly. You may test scenarios related to abrupt shutdowns or failures to start usingthenWithHardShutdown(org.jvnet.hudson.test.RestartableJenkinsRule.Step)
andthenDoesNotStart()
.The rule will evaluate your test method to collect all steps, then execute them in turn and restart Jenkins in between each step. Consider using
JenkinsSessionRule
if you want each step to be executed immediately whenthen(org.jvnet.hudson.test.RestartableJenkinsRule.Step)
is called.If your test requires disabling of a plugin then the default
PluginManager
(TestPluginManager
) used for tests will need to be changed toUnitTestSupportingPluginManager
. This can be accomplished by annotating the test with@WithPluginManager(UnitTestSupportingPluginManager.class)
.- Since:
- 1.567
- Author:
- Kohsuke Kawaguchi
- See Also:
JenkinsRule
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RestartableJenkinsRule.Builder
static interface
RestartableJenkinsRule.Step
One step to run, intended to be a SAM for lambdas withthen(org.jvnet.hudson.test.RestartableJenkinsRule.Step)
.
-
Field Summary
Fields Modifier and Type Field Description File
home
JENKINS_HOMEJenkinsRule
j
-
Constructor Summary
Constructors Constructor Description RestartableJenkinsRule()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addStep(org.junit.runners.model.Statement step)
Deprecated.void
addStep(org.junit.runners.model.Statement step, boolean expectedToStartCorrectly)
Deprecated.void
addStepWithDirtyShutdown(org.junit.runners.model.Statement step)
Deprecated.org.junit.runners.model.Statement
apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target)
protected JenkinsRule
createJenkinsRule(org.junit.runner.Description description)
void
step(groovy.lang.Closure<?> c)
Deprecated.void
then(RestartableJenkinsRule.Step s)
Run one Jenkins session and shut down.void
thenDoesNotStart()
void
thenWithHardShutdown(RestartableJenkinsRule.Step s)
Run one Jenkins session and then simulate the Jenkins process ending without a clean shutdown.
-
-
-
Field Detail
-
j
public JenkinsRule j
-
home
public File home
JENKINS_HOME
-
-
Method Detail
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target)
- Specified by:
apply
in interfaceorg.junit.rules.MethodRule
-
step
@Deprecated public void step(groovy.lang.Closure<?> c)
Deprecated.
-
then
public void then(RestartableJenkinsRule.Step s)
Run one Jenkins session and shut down.- Since:
- 2.24
-
thenWithHardShutdown
public void thenWithHardShutdown(RestartableJenkinsRule.Step s)
Run one Jenkins session and then simulate the Jenkins process ending without a clean shutdown. This can be used to test that data is appropriately persisted without relying on shutdown processes.Implementation note: we're actually just copying the JENKINS_HOME, which takes some time - so the shutdown isn't truly instant (additional data may be written while this happens).
-
thenDoesNotStart
public void thenDoesNotStart()
-
addStep
@Deprecated public void addStep(org.junit.runners.model.Statement step)
Deprecated.
-
addStep
@Deprecated public void addStep(org.junit.runners.model.Statement step, boolean expectedToStartCorrectly)
Deprecated.
-
addStepWithDirtyShutdown
@Deprecated public void addStepWithDirtyShutdown(org.junit.runners.model.Statement step)
Deprecated.
-
createJenkinsRule
protected JenkinsRule createJenkinsRule(org.junit.runner.Description description)
-
-