Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deliverable of code associated with assignment 2 of Software Reengineering (dlim1 and sbijl) #12

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
no message
DustinLim committed Jan 15, 2015
commit eefc6ee8c433820e2dd8e52ba944bf62d277c444
17 changes: 14 additions & 3 deletions alitheia/core/src/main/java/eu/sqooss/service/scheduler/Job.java
Original file line number Diff line number Diff line change
@@ -101,6 +101,8 @@ public enum State {

private ResumePoint resumePoint;

private DBService dbs;

public void setWorkerThread(WorkerThread worker) {
m_worker = worker;
}
@@ -215,7 +217,6 @@ private final synchronized void removeDependee(Job other) {
* @throws Exception
*/
final public long execute() throws Exception {
DBService dbs = AlitheiaCore.getInstance().getDBService();
long timer = System.currentTimeMillis();
try {
setState(State.Running);
@@ -374,10 +375,21 @@ public int compareTo(Job other)
/**
* Protected default constructor.
*/
protected Job() {
protected Job() {
this(AlitheiaCore.getInstance().getDBService());
}

/**
* Alternative constructor, allows injecting your
* own DBService
*/
protected Job(DBService dbs)
{
m_scheduler = null;
m_errorException = null;
setState( State.Created );

this.dbs = dbs;
}

/**
@@ -493,7 +505,6 @@ public void yield(ResumePoint p) throws SchedulerException {

public long resume() throws Exception {
long ts = System.currentTimeMillis();
DBService dbs = AlitheiaCore.getInstance().getDBService();

if (state() != State.Yielded)
throw new SchedulerException("Cannot resume a non-yielded job");
Original file line number Diff line number Diff line change
@@ -4,7 +4,9 @@
import org.junit.BeforeClass;
import org.junit.Test;

import eu.sqooss.impl.service.db.DBServiceImpl;
import eu.sqooss.impl.service.scheduler.SchedulerServiceImpl;
import eu.sqooss.service.db.DBService;
import eu.sqooss.service.scheduler.SchedulerException;

public class SchedulerTests {
@@ -13,22 +15,24 @@ public class SchedulerTests {

@BeforeClass
public static void setUp() {
sched = new SchedulerServiceImpl();
sched = new SchedulerServiceImpl();
sched.startExecute(2);
}

@Test
public void testJobYield() throws SchedulerException {

DBService dbs = DBServiceImpl.getInstance();

TestJob j1 = new TestJob(20, "Test");
TestJob j1 = new TestJob(1, "Job 1", dbs);
sched.enqueue(j1);
TestJob j2 = new TestJob(20, "Test");
TestJob j2 = new TestJob(2, "Job 2", dbs);
sched.enqueue(j2);
TestJob j3 = new TestJob(20, "Test");
TestJob j3 = new TestJob(3, "Job 3", dbs);
sched.enqueue(j3);
TestJob j4 = new TestJob(20, "Test");
TestJob j4 = new TestJob(4, "Job 4", dbs);
sched.enqueue(j4);
}
}

@AfterClass
public static void tearDown() {
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@

package eu.sqooss.test.service.scheduler;

import eu.sqooss.service.db.DBService;
import eu.sqooss.service.scheduler.Job;

/**
@@ -50,7 +51,8 @@ class TestJob extends Job
/**
* Contructor creating a job printing string \a s \a n times.
*/
public TestJob(int n, String s) {
public TestJob(int n, String s, DBService dbs) {
super(dbs);
this.n = n;
this.s = s;
}
@@ -62,7 +64,6 @@ public long priority() {
protected void run() throws Exception {
System.out.println("Testjob running!");
for (int i = 0; i < n; ++i) {
Thread.sleep(500);
System.out.println(s);
}
System.out.println("Testjob finished!");