Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
101 changes: 101 additions & 0 deletions src/test/java/aeminium/runtime/tests/TestAtomicTaskDeadLock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Copyright (c) 2010-11 The AEminium Project (see AUTHORS file)
*
* This file is part of Plaid Programming Language.
*
* Plaid Programming Language is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plaid Programming Language is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Plaid Programming Language. If not, see <http://www.gnu.org/licenses/>.
*/

package aeminium.runtime.tests;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;

import org.junit.Assert;
import org.junit.Test;

import aeminium.runtime.DataGroup;
import aeminium.runtime.ErrorHandler;
import aeminium.runtime.Runtime;
import aeminium.runtime.Task;
import aeminium.runtime.implementations.Factory;

public class TestAtomicTaskDeadLock extends BaseTest {

@Test(timeout=2000)
public void createAtomicTaskDeadLock() {
final AtomicBoolean deadlock = new AtomicBoolean(false);
Runtime rt = Factory.getRuntime();
rt.init();

rt.addErrorHandler(new ErrorHandler() {

@Override
public void handleTaskException(Task task, Throwable t) {
}

@Override
public void handleTaskDuplicatedSchedule(Task task) {
}

@Override
public void handleLockingDeadlock() {
deadlock.set(true);
}

@Override
public void handleInternalError(Error err) {
}

@Override
public void handleDependencyCycle(Task task) {
}
});

DataGroup dg1 = rt.createDataGroup();
DataGroup dg2 = rt.createDataGroup();

Task t1 = createAtomicTask(rt, dg1, dg2);
rt.schedule(t1, Runtime.NO_PARENT, Runtime.NO_DEPS);
Task t2 = createAtomicTask(rt, dg2, dg1);
rt.schedule(t2, Runtime.NO_PARENT, Runtime.NO_DEPS);

try {
Thread.sleep(1500);
} catch (InterruptedException e1) {}

if ( deadlock.get() ) {
Assert.fail("Could not find deadlock");
rt.shutdown();
}
}

private Task createAtomicTask(final Runtime rt, final DataGroup dg1, final DataGroup dg2) {
return rt.createAtomicTask((Runtime rt1, Task current) -> {
getLogger().log(Level.INFO, "Atomic Task for data group : {0}", dg1);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
rt1.schedule(createAtomicTask(rt1, dg2), current, Runtime.NO_DEPS);
}, dg1, Runtime.NO_HINTS);
}

private Task createAtomicTask(final Runtime rt, final DataGroup dg) {
return rt.createAtomicTask((Runtime rt1, Task current) -> {
getLogger().log(Level.INFO, "Atomic Sub-Task for data group : {0}", dg);
}, dg, Runtime.NO_HINTS);

}
}
94 changes: 94 additions & 0 deletions src/test/java/aeminium/runtime/tests/TestAtomicTaskWaiting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Copyright (c) 2010-11 The AEminium Project (see AUTHORS file)
*
* This file is part of Plaid Programming Language.
*
* Plaid Programming Language is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plaid Programming Language is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Plaid Programming Language. If not, see <http://www.gnu.org/licenses/>.
*/

package aeminium.runtime.tests;

import java.util.Arrays;

import org.junit.Test;

import aeminium.runtime.Body;
import aeminium.runtime.DataGroup;
import aeminium.runtime.Runtime;
import aeminium.runtime.Task;
import aeminium.runtime.implementations.Factory;

public class TestAtomicTaskWaiting extends BaseTest {

@Test
public void runAtomicTaskWaitingTest() {
Runtime rt = Factory.getRuntime();
rt.init();

DataGroup dg = rt.createDataGroup();
Task t1 = createAtomicTask(rt, dg, 10);
rt.schedule(t1, Runtime.NO_PARENT, Runtime.NO_DEPS);
Task t2 = createAtomicTask(rt, dg, 20);
rt.schedule(t2, Runtime.NO_PARENT, Runtime.NO_DEPS);
Task t3 = createAtomicTask(rt, dg, 30);
rt.schedule(t3, Runtime.NO_PARENT, Runtime.NO_DEPS);
Task t4 = createAtomicTask(rt, dg, 40);
rt.schedule(t4, Runtime.NO_PARENT, Runtime.NO_DEPS);
Task t5 = createAtomicTask(rt, dg, 50);
rt.schedule(t5, Runtime.NO_PARENT, Runtime.NO_DEPS);

rt.shutdown();
}

public Task createAtomicTask(final Runtime rt, DataGroup group, final int delay) {
return rt.createAtomicTask(new Body() {
@Override
public void execute(Runtime rt, Task current) {
// let's create some sub tasks
Task t1 = rt.createNonBlockingTask(new Body() {
@Override
public void execute(Runtime rt, Task current) {
getLogger().info("Sub Task waiting for "+ (delay+1) + " ms");
}
@Override
public String toString() {
return ""+(delay+1);
}
}, Runtime.NO_HINTS);
rt.schedule(t1, current, Runtime.NO_DEPS);

Task t2 = rt.createNonBlockingTask(new Body() {
@Override
public void execute(Runtime rt, Task current) {
getLogger().info("Sub Task waiting for "+ (delay+2) + " ms");
}
@Override
public String toString() {
return ""+(delay+2);
}

}, Runtime.NO_HINTS);
rt.schedule(t2, current, Arrays.asList(t1));

getLogger().info("Task waiting for "+delay + " ms");

}

@Override
public String toString() {
return ""+delay;
}
} , group, Runtime.NO_HINTS);
}
}
48 changes: 48 additions & 0 deletions src/test/java/aeminium/runtime/tests/TestChildTasks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) 2010-11 The AEminium Project (see AUTHORS file)
*
* This file is part of Plaid Programming Language.
*
* Plaid Programming Language is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plaid Programming Language is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Plaid Programming Language. If not, see <http://www.gnu.org/licenses/>.
*/

package aeminium.runtime.tests;

import org.junit.Test;

import aeminium.runtime.Body;
import aeminium.runtime.Runtime;
import aeminium.runtime.Task;
import aeminium.runtime.implementations.Factory;

public class TestChildTasks extends BaseTest {
@Test
public void childTasks() {
Runtime rt = Factory.getRuntime();
rt.init();

Task t1 = createTask(rt, 2);
rt.schedule(t1, Runtime.NO_PARENT, Runtime.NO_DEPS);

rt.shutdown();
}

public Task createTask(final Runtime rt, final int level ) {
return rt.createNonBlockingTask((Runtime rt1, Task current) -> {
if (level > 0) {
rt1.schedule(createTask(rt1, level-1), current, Runtime.NO_DEPS);
}
}, Runtime.NO_HINTS);
}
}
104 changes: 104 additions & 0 deletions src/test/java/aeminium/runtime/tests/TestCycle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* Copyright (c) 2010-11 The AEminium Project (see AUTHORS file)
*
* This file is part of Plaid Programming Language.
*
* Plaid Programming Language is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plaid Programming Language is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Plaid Programming Language. If not, see <http://www.gnu.org/licenses/>.
*/

package aeminium.runtime.tests;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;

import org.junit.Assert;
import org.junit.Test;

import aeminium.runtime.Body;
import aeminium.runtime.ErrorHandler;
import aeminium.runtime.Runtime;
import aeminium.runtime.Task;
import aeminium.runtime.implementations.Factory;

public class TestCycle extends BaseTest {

@Test(timeout=2000)
public void testRoundDeadlock() {
final AtomicBoolean cycle = new AtomicBoolean();
Runtime rt = Factory.getRuntime();
rt.init();

rt.addErrorHandler(new ErrorHandler() {

@Override
public void handleTaskException(Task task, Throwable t) {


}

@Override
public void handleTaskDuplicatedSchedule(Task task) {


}

@Override
public void handleLockingDeadlock() {


}

@Override
public void handleInternalError(Error err) {


}

@Override
public void handleDependencyCycle(Task task) {
cycle.set(true);

}
});

Task t1 = rt.createNonBlockingTask(createBody(1), Runtime.NO_HINTS);
Task t2 = rt.createNonBlockingTask(createBody(2), Runtime.NO_HINTS);
Task t3 = rt.createNonBlockingTask(createBody(3), Runtime.NO_HINTS);
Task t4 = rt.createNonBlockingTask(createBody(4), Runtime.NO_HINTS);

rt.schedule(t1, Runtime.NO_PARENT, Arrays.asList(t4));
rt.schedule(t2, Runtime.NO_PARENT, Arrays.asList(t1));
rt.schedule(t3, Runtime.NO_PARENT, Arrays.asList(t2));
rt.schedule(t4, Runtime.NO_PARENT, Arrays.asList(t3));

if ( !cycle.get() ) {
Assert.fail("Did not detect self cylcle.");
rt.shutdown();
}
}

public Body createBody(final int i) {
return new Body() {
@Override
public void execute(Runtime rt, Task parent) {
System.out.println("Task " + i);
}

public String toString() {
return "" + i;
}
};
}

}
Loading