Search in sources :

Example 1 with BuildStepMonitor

use of hudson.tasks.BuildStepMonitor in project jenkins by jenkinsci.

the class AbstractBuildTest method workspaceLock.

@Test
@Issue("JENKINS-10615")
public void workspaceLock() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    p.setConcurrentBuild(true);
    OneShotEvent e1 = new OneShotEvent();
    OneShotEvent e2 = new OneShotEvent();
    OneShotEvent done = new OneShotEvent();
    p.getPublishersList().add(new Recorder() {

        @Override
        public BuildStepMonitor getRequiredMonitorService() {
            return BuildStepMonitor.NONE;
        }

        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException {
            if (build.number == 1) {
                // signal that build #1 is in publisher
                e1.signal();
            } else if (build.number == 2) {
                // signal that build #2 is in publisher
                e2.signal();
            } else {
                throw new IllegalArgumentException("unexpected build number: " + build.number);
            }
            done.block();
            return true;
        }

        private Object writeReplace() {
            return new Object();
        }
    });
    QueueTaskFuture<FreeStyleBuild> b1 = p.scheduleBuild2(0);
    e1.block();
    QueueTaskFuture<FreeStyleBuild> b2 = p.scheduleBuild2(0);
    e2.block();
    // at this point both builds are in the publisher, so we verify that
    // the workspace are differently allocated
    assertNotEquals(b1.getStartCondition().get().getWorkspace(), b2.getStartCondition().get().getWorkspace());
    done.signal();
}
Also used : Recorder(hudson.tasks.Recorder) Launcher(hudson.Launcher) JSONObject(net.sf.json.JSONObject) OneShotEvent(hudson.util.OneShotEvent) BuildStepMonitor(hudson.tasks.BuildStepMonitor) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) LogRotatorTest(hudson.tasks.LogRotatorTest)

Aggregations

Launcher (hudson.Launcher)1 BuildStepMonitor (hudson.tasks.BuildStepMonitor)1 LogRotatorTest (hudson.tasks.LogRotatorTest)1 Recorder (hudson.tasks.Recorder)1 OneShotEvent (hudson.util.OneShotEvent)1 JSONObject (net.sf.json.JSONObject)1 Test (org.junit.Test)1 Issue (org.jvnet.hudson.test.Issue)1