Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 28967 Details for
Bug 114269
[jobs] Customizable job scheduling priorities
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
JUnit Plugin test that shows effects of priority on job scheduling
JobSchedulingTest.java (text/plain), 2.91 KB, created by
Ian Graham
on 2005-10-28 19:07:08 EDT
(
hide
)
Description:
JUnit Plugin test that shows effects of priority on job scheduling
Filename:
MIME Type:
Creator:
Ian Graham
Created:
2005-10-28 19:07:08 EDT
Size:
2.91 KB
patch
obsolete
>import java.util.ArrayList; >import java.util.List; >import java.util.Random; > >import junit.framework.TestCase; > >import org.eclipse.core.runtime.IProgressMonitor; >import org.eclipse.core.runtime.IStatus; >import org.eclipse.core.runtime.Status; >import org.eclipse.core.runtime.jobs.ISchedulingRule; >import org.eclipse.core.runtime.jobs.Job; > >public class JobSchedulingTest extends TestCase { > > static class MutexRule implements ISchedulingRule { > public boolean contains(ISchedulingRule rule) { > return rule == this; > } > public boolean isConflicting(ISchedulingRule rule) { > return rule == this; > } > } > > /** > * TestJob returns OK iff priority is not lower than any previously run job. > */ > static class TestJob extends Job { > > static int lastPriority; > > private String name; > > public static void resetLastPriority() { > lastPriority = 0; > } > > TestJob(String name, int priority) { > super("TestJob"); > this.name = name; > setRule(mutex); > setPriority(priority); > } > > @Override > protected IStatus run(IProgressMonitor aMonitor) { > System.out.print(name + ", Priority " + getPriority() + " "); > try { > Thread.sleep(50); > } catch (InterruptedException e) { > fail("Job was interrupted"); > } > if (getPriority() >= lastPriority) { > System.out.println("OK"); > lastPriority = getPriority(); > return Status.OK_STATUS; > } > System.out.println("OUT OF SEQUENCE"); > return Status.CANCEL_STATUS; > } > } > > static ISchedulingRule mutex = new MutexRule(); > static Random random = new Random(); > > @Override > protected void setUp() throws Exception { > super.setUp(); > TestJob.resetLastPriority(); > } > > public void testPrioritizedJobScheduling() throws InterruptedException { > Job job = new TestJob("First Job", Job.INTERACTIVE); > job.schedule(); > List<Job> jobs = scheduleJobsOfRandomPriority(25); > Job lastJob = new TestJob("Last Job", Job.DECORATE); > jobs.add(lastJob); > lastJob.schedule(); > lastJob.join(); // bit of an assumption here, that it should really be last run > for (Job completedJob : jobs) { > assertEquals(Status.OK_STATUS, completedJob.getResult()); > } > } > > private List<Job> scheduleJobsOfRandomPriority(int numberOfJobs) { > List<Job> jobs = new ArrayList<Job>(); > for (int i = 0; i < numberOfJobs; i++) { > int priority = (random.nextInt(5) + 1) * 10; > Job job = new TestJob("Job " + i, priority); > jobs.add(job); > job.schedule(); > } > return jobs; > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 114269
: 28967