Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Gracefully handle out-of-sync lifecycle events
  • Loading branch information
emsa23 committed May 11, 2015
1 parent b6bf3e4 commit cbf6804
Showing 1 changed file with 14 additions and 6 deletions.
Expand Up @@ -23,6 +23,8 @@
*/
package jenkins.advancedqueue.sorter;

import java.util.logging.Logger;

import hudson.Extension;
import hudson.model.Queue.BlockedItem;
import hudson.model.Queue.BuildableItem;
Expand All @@ -37,6 +39,8 @@
@Extension
public class AdvancedQueueSorterQueueListener extends QueueListener {

private final static Logger LOGGER = Logger.getLogger(AdvancedQueueSorterQueueListener.class.getName());

@Override
public void onEnterWaiting(WaitingItem wi) {
AdvancedQueueSorter.get().onNewItem(wi);
Expand All @@ -50,19 +54,23 @@ public void onLeft(LeftItem li) {
@Override
public void onEnterBuildable(BuildableItem bi) {
ItemInfo item = QueueItemCache.get().getItem(bi.id);
// Null at startup
if (item != null) {
QueueItemCache.get().getItem(bi.id).setBuildable();
// Null at startup - onEnterWaiting not called during startup (?)
if (item == null) {
LOGGER.warning("onEnterBuilding() called without prior call to onEnterWaiting() for '" + bi.task.getDisplayName() + "'");
AdvancedQueueSorter.get().onNewItem(bi);
}
QueueItemCache.get().getItem(bi.id).setBuildable();
}

@Override
public void onEnterBlocked(BlockedItem bi) {
ItemInfo item = QueueItemCache.get().getItem(bi.id);
// Null at startup
if (item != null) {
item.setBlocked();
// Null at startup - onEnterWaiting not called during startup (?)
if (item == null) {
LOGGER.warning("onEnterBlocked() called without prior call to onEnterWaiting() for '" + bi.task.getDisplayName() + "'");
AdvancedQueueSorter.get().onNewItem(bi);
}
QueueItemCache.get().getItem(bi.id).setBlocked();
}

}

4 comments on commit cbf6804

@olivergondza
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes test failures.

org.jvnet.hudson.reactor.ReactorException: java.lang.Error: java.lang.reflect.InvocationTargetException
    at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:269)
    at jenkins.InitReactorRunner.run(InitReactorRunner.java:44)
    at jenkins.model.Jenkins.executeReactor(Jenkins.java:896)
    at jenkins.model.Jenkins.<init>(Jenkins.java:795)
    at hudson.model.Hudson.<init>(Hudson.java:82)
    at org.jvnet.hudson.test.JenkinsRule.newHudson(JenkinsRule.java:535)
    at org.jvnet.hudson.test.JenkinsRule.before(JenkinsRule.java:331)
    at org.jvnet.hudson.test.JenkinsRule$2.evaluate(JenkinsRule.java:480)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.lang.Error: java.lang.reflect.InvocationTargetException
    at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:109)
    at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:169)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:282)
    at jenkins.model.Jenkins$7.runTask(Jenkins.java:885)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:210)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:105)
    at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:169)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:282)
    at jenkins.model.Jenkins$7.runTask(Jenkins.java:885)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:210)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: null
    at jenkins.advancedqueue.PrioritySorterConfiguration.init(PrioritySorterConfiguration.java:82)
    at jenkins.advancedqueue.PrioritySorterPlugin.init1(PrioritySorterPlugin.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:105)
    at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:169)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:282)
    at jenkins.model.Jenkins$7.runTask(Jenkins.java:885)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:210)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)


@emsa23
Copy link
Contributor Author

@emsa23 emsa23 commented on cbf6804 May 12, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I noticed that, unfortunately it is almost impossible to write stable tests for this.

@olivergondza
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reasons I not quite understand #26 seems to fix that.

@emsa23
Copy link
Contributor Author

@emsa23 emsa23 commented on cbf6804 May 12, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great ;-) I've tried combinations from h*** and back and was just about to deep dive into core ...

Please sign in to comment.