Exemplo n.º 1
0
  /** Can {@link Queue} successfully recover removal? */
  public void testPersistence2() throws Exception {
    Queue q = hudson.getQueue();

    // prevent execution to push stuff into the queue
    hudson.setNumExecutors(0);
    hudson.setNodes(hudson.getNodes());

    FreeStyleProject testProject = createFreeStyleProject("test");
    testProject.scheduleBuild(new UserCause());
    q.save();

    System.out.println(FileUtils.readFileToString(new File(hudson.getRootDir(), "queue.xml")));

    assertEquals(1, q.getItems().length);
    q.clear();
    assertEquals(0, q.getItems().length);

    // delete the project before loading the queue back
    testProject.delete();
    q.load();
    assertEquals(0, q.getItems().length);
  }
Exemplo n.º 2
0
  /** Checks the persistence of queue. */
  public void testPersistence() throws Exception {
    Queue q = hudson.getQueue();

    // prevent execution to push stuff into the queue
    hudson.setNumExecutors(0);
    hudson.setNodes(hudson.getNodes());

    FreeStyleProject testProject = createFreeStyleProject("test");
    testProject.scheduleBuild(new UserCause());
    q.save();

    System.out.println(FileUtils.readFileToString(new File(hudson.getRootDir(), "queue.xml")));

    assertEquals(1, q.getItems().length);
    q.clear();
    assertEquals(0, q.getItems().length);

    // load the contents back
    q.load();
    assertEquals(1, q.getItems().length);

    // did it bind back to the same object?
    assertSame(q.getItems()[0].task, testProject);
  }
Exemplo n.º 3
0
  public void testFoldableCauseAction() throws Exception {
    final OneShotEvent buildStarted = new OneShotEvent();
    final OneShotEvent buildShouldComplete = new OneShotEvent();

    hudson.quietPeriod = 0;
    FreeStyleProject project = createFreeStyleProject();
    // Make build sleep a while so it blocks new builds
    project
        .getBuildersList()
        .add(
            new TestBuilder() {
              public boolean perform(
                  AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
                  throws InterruptedException, IOException {
                buildStarted.signal();
                buildShouldComplete.block();
                return true;
              }
            });

    // Start one build to block others
    assertTrue(project.scheduleBuild(new UserCause()));
    buildStarted.block(); // wait for the build to really start

    // Schedule a new build, and trigger it many ways while it sits in queue
    Future<FreeStyleBuild> fb = project.scheduleBuild2(0, new UserCause());
    assertNotNull(fb);
    assertFalse(project.scheduleBuild(new SCMTriggerCause()));
    assertFalse(project.scheduleBuild(new UserCause()));
    assertFalse(project.scheduleBuild(new TimerTriggerCause()));
    assertFalse(project.scheduleBuild(new RemoteCause("1.2.3.4", "test")));
    assertFalse(project.scheduleBuild(new RemoteCause("4.3.2.1", "test")));
    assertFalse(project.scheduleBuild(new SCMTriggerCause()));
    assertFalse(project.scheduleBuild(new RemoteCause("1.2.3.4", "test")));
    assertFalse(project.scheduleBuild(new RemoteCause("1.2.3.4", "foo")));
    assertFalse(project.scheduleBuild(new SCMTriggerCause()));
    assertFalse(project.scheduleBuild(new TimerTriggerCause()));

    // Wait for 2nd build to finish
    buildShouldComplete.signal();
    FreeStyleBuild build = fb.get();

    // Make sure proper folding happened.
    CauseAction ca = build.getAction(CauseAction.class);
    assertNotNull(ca);
    StringBuilder causes = new StringBuilder();
    for (Cause c : ca.getCauses()) causes.append(c.getShortDescription() + "\n");
    assertEquals(
        "Build causes should have all items, even duplicates",
        "Started by user anonymous\nStarted by an SCM change\n"
            + "Started by user anonymous\nStarted by timer\n"
            + "Started by remote host 1.2.3.4 with note: test\n"
            + "Started by remote host 4.3.2.1 with note: test\n"
            + "Started by an SCM change\n"
            + "Started by remote host 1.2.3.4 with note: test\n"
            + "Started by remote host 1.2.3.4 with note: foo\n"
            + "Started by an SCM change\nStarted by timer\n",
        causes.toString());

    // View for build should group duplicates
    WebClient wc = new WebClient();
    String buildPage = wc.getPage(build, "").asText().replace('\n', ' ');
    assertTrue(
        "Build page should combine duplicates and show counts: " + buildPage,
        buildPage.contains(
            "Started by user anonymous (2 times) "
                + "Started by an SCM change (3 times) "
                + "Started by timer (2 times) "
                + "Started by remote host 1.2.3.4 with note: test (2 times) "
                + "Started by remote host 4.3.2.1 with note: test "
                + "Started by remote host 1.2.3.4 with note: foo"));
  }