@Override public Void call() throws Exception { maintain(); return null; }
protected void doRun() { Queue q = queue.get(); if (q != null) q.maintain(); else cancel(); } }
@Override public Void call() throws Exception { maintain(); return null; }
protected void doRun() { Queue q = queue.get(); if (q != null) q.maintain(); else cancel(); } }
@Override protected void doRun() { Queue q = queue.get(); if (q != null) { q.maintain(); } else { cancel(); } } }
protected void doRun() { Queue q = queue.get(); if (q != null) q.maintain(); else cancel(); } }
protected void doRun() { Queue q = queue.get(); if (q != null) q.maintain(); else cancel(); } }
protected void doRun() { Queue q = queue.get(); if (q != null) q.maintain(); else cancel(); } }
/** * Process RefReplicated events. * @param refReplicated the event */ public void gerritEvent(RefReplicated refReplicated) { replicationCache.put(refReplicated); boolean queueMaintenanceRequired = false; for (BlockedItem blockedItem : blockedItems.values()) { if (!blockedItem.canRun) { blockedItem.processRefReplicatedEvent(refReplicated); if (blockedItem.canRun) { queueMaintenanceRequired = true; } } } if (queueMaintenanceRequired) { // force a maintenance of the queue to unblock builds Queue.getInstance().maintain(); } }
/** * Test that it should not block item when the elapsed time between the event reception time stamp and the * dispatcher get called is greater than the cache expiration time. * * Lets say that the cache expires after 6 hours, a build enter the queue and gets blocked by another * QueueTaskDispatcher for 7 hours and this dispatcher gets called after, we assume that we received the * replication event. We cannot cache the events forever otherwise will end up with serious memory issue. */ @Test public void shouldNotBlockItemWhenElapsedTimeIsGreaterThenCacheExpirationTime() { PatchsetCreated patchsetCreated = Setup.createPatchsetCreated("someGerritServer", "someProject", "refs/heads/master"); patchsetCreated.setReceivedOn(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(ReplicationCache.DEFAULT_EXPIRATION_IN_MINUTES)); Item item = createItem(patchsetCreated, new String[] {"slaveA", "slaveB"}); assertNull("Item should not be blocked", dispatcher.canRun(item)); verify(queueMock, times(0)).maintain(); }
assertNotNull("Item should be tagged with replicationFailedAction", replicationFailedAction); assertTrue(replicationFailedAction.getReason().contains("slave2")); verify(queueMock, times(0)).maintain();
/** * Test that it should not block item when replication is completed before the queue task dispatcher * is called to evaluate that queued item. * * This scenario is very likely if another QueueTaskDispatcher is registered, gets called before our and block the * build for sometime(e.g. ThrottleConcurrentBuild plugin). */ @Test public void shouldNotBlockItemWhenReplicationIsCompletedBeforeDispatcherIsCalled() { PatchsetCreated patchsetCreated = Setup.createPatchsetCreated("someGerritServer", "someProject", "refs/changes/1/1/1"); Item item = createItem(patchsetCreated, new String[] {"slaveA", "slaveB"}); //send replication event for slaveB dispatcher.gerritEvent(Setup.createRefReplicatedEvent("someProject", "refs/changes/1/1/1", "someGerritServer", "slaveB", RefReplicated.SUCCEEDED_STATUS)); //send replication event for slaveA dispatcher.gerritEvent(Setup.createRefReplicatedEvent("someProject", "refs/changes/1/1/1", "someGerritServer", "slaveA", RefReplicated.SUCCEEDED_STATUS)); assertNull("Item should not be blocked", dispatcher.canRun(item)); verify(queueMock, times(0)).maintain(); }
private static void assertNoTasksRunning(Jenkins j) { j.getQueue().maintain(); assert j.getQueue().isEmpty(); Computer[] computerList = j.getComputers(); for (Computer c : computerList) { List<Executor> executors = c.getExecutors(); for (Executor ex : executors) { if (ex.isBusy()) { Assert.fail("Computer "+c+" has an Executor "+ex+" still running a task: "+ex.getCurrentWorkUnit()); } } } }
/** * Helper method for ChangeBasedEvent replication * @param cbe Change Based event */ private void patchSetIsReplicatedToOneSlaveAfterChangeBasedEvent(ChangeBasedEvent cbe) { Item item = createItem(cbe, new String[] {"slaveA"}); //item is blocked CauseOfBlockage cause = dispatcher.canRun(item); assertNotNull("The item should be blocked", cause); assertTrue("Should have returned a WaitingForReplication as CauseOfBlockage", cause instanceof WaitingForReplication); assertTrue(cause.getShortDescription().contains("slaveA")); //send an unrelated event (not RefReplicated) dispatcher.gerritEvent(new ChangeAbandoned()); assertNotNull("the item should be blocked", dispatcher.canRun(item)); //send the proper replication event dispatcher.gerritEvent(Setup.createRefReplicatedEvent("someProject", "refs/changes/1/1/1", "someGerritServer", "slaveA", RefReplicated.SUCCEEDED_STATUS)); assertNull("Item should not be blocked", dispatcher.canRun(item)); assertNull("Item should not be tagged with replicationFailedAction", item.getAction(ReplicationFailedAction.class)); verify(queueMock, times(1)).maintain(); }
@Issue("JENKINS-50561") @Test public void rateLimitBuilds() throws Exception { WorkflowRun b = expect("rateLimitBuilds") .go(); WorkflowJob p = b.getParent(); RateLimitBranchProperty.JobPropertyImpl prop = p.getProperty(RateLimitBranchProperty.JobPropertyImpl.class); assertNotNull(prop); assertEquals(1, prop.getCount()); assertEquals("day", prop.getDurationName()); assertFalse(prop.isUserBoost()); QueueTaskFuture<WorkflowRun> inQueue = p.scheduleBuild2(0); while (!Queue.getInstance().contains(p)) { Thread.yield(); } Queue.getInstance().maintain(); Queue.Item queued = Queue.getInstance().getItem(p); assertThat(queued.isBlocked(), is(true)); assertThat(queued.getCauseOfBlockage().getShortDescription().toLowerCase(), containsString("throttle")); inQueue.cancel(true); }
verify(queueMock, times(1)).maintain();
assertNull("Item should not be tagged with replicationFailedAction", item.getAction(ReplicationFailedAction.class)); verify(queueMock, times(1)).maintain();
assertNull("Item should not be blocked", cause); verify(queueMock, times(1)).maintain();
assertNull("Item should not be tagged with replicationFailedAction", item2.getAction(ReplicationFailedAction.class)); verify(queueMock, times(1)).maintain();
assertNull("Item should not be tagged with replicationFailedAction", item.getAction(ReplicationFailedAction.class)); verify(queueMock, times(1)).maintain();