use of org.dkpro.lab.engine.TaskContext in project dkpro-lab by dkpro.
the class BatchTaskTest method importTest.
@Test(expected = RuntimeException.class)
public void importTest() throws Exception {
Task producer = new ExecutableTaskBase() {
@Override
public void execute(TaskContext aContext) throws Exception {
System.out.println("Running producer");
Properties data = new Properties();
data.setProperty("key", "value");
aContext.storeBinary("DATA", new PropertiesAdapter(data));
}
};
Task consumer = new ExecutableTaskBase() {
@Override
public void execute(TaskContext aContext) throws Exception {
System.out.println("Running consumer");
Properties data = new Properties();
aContext.retrieveBinary("DATA", new PropertiesAdapter(data));
Assert.assertEquals(data.getProperty("key"), "value");
}
};
consumer.addImport(producer, "DATA1", "DATA");
DefaultBatchTask batch = new DefaultBatchTask();
batch.addTask(producer);
batch.addTask(consumer);
Lab.getInstance().run(batch);
}
use of org.dkpro.lab.engine.TaskContext in project dkpro-lab by dkpro.
the class BatchTaskTest method testUnresolvable.
@Test(expected = RuntimeException.class)
public void testUnresolvable() throws Exception {
Dimension<String> dim = Dimension.create("param", "1", "2", "3");
ParameterSpace pSpace = new ParameterSpace(dim);
Task task1 = new ExecutableTaskBase() {
@Discriminator
private String param;
@Override
public void execute(TaskContext aContext) throws Exception {
// Nothing to do
}
};
Task task2 = new ExecutableTaskBase() {
@Discriminator
private String param;
@Override
public void execute(TaskContext aContext) throws Exception {
// Nothing to do
}
};
task2.addImport(task1, "DUMMY");
task1.addImport(task2, "DUMMY");
DefaultBatchTask batchTask = new DefaultBatchTask();
batchTask.setParameterSpace(pSpace);
batchTask.addTask(task1);
batchTask.addTask(task2);
Lab.getInstance().run(batchTask);
}
use of org.dkpro.lab.engine.TaskContext in project dkpro-lab by dkpro.
the class TaskBaseTest method settingDiscriminatorsNotAllowedAfterTaskRan.
@Test(expected = IllegalStateException.class)
public void settingDiscriminatorsNotAllowedAfterTaskRan() throws Exception {
Task consumer = new ExecutableTaskBase() {
@Override
public void execute(TaskContext aContext) throws Exception {
// do nothing
}
};
// this should still work
consumer.setDescriminator("DUMMY_KEY", "123");
DefaultBatchTask batch = new DefaultBatchTask();
batch.addTask(consumer);
Lab.getInstance().run(batch);
// Task did run - no modification allowed
consumer.setDescriminator("DUMMY_KEY_2", "1234");
}
use of org.dkpro.lab.engine.TaskContext in project dkpro-lab by dkpro.
the class TaskBaseTest method settingAttributesNotAllowedAfterTaskRan.
@Test(expected = IllegalStateException.class)
public void settingAttributesNotAllowedAfterTaskRan() throws Exception {
Task consumer = new ExecutableTaskBase() {
@Override
public void execute(TaskContext aContext) throws Exception {
// do nothing
}
};
// this should still work
consumer.setAttribute("DUMMY_KEY", "123");
DefaultBatchTask batch = new DefaultBatchTask();
batch.addTask(consumer);
Lab.getInstance().run(batch);
// Task did run - no modification allowed
consumer.setAttribute("DUMMY_KEY_2", "1234");
}
use of org.dkpro.lab.engine.TaskContext in project dkpro-lab by dkpro.
the class MultiThreadBatchTaskTest method importTest.
@Test(expected = UnresolvedImportException.class)
public void importTest() throws Exception {
Task producer = new ExecutableTaskBase() {
@Override
public void execute(TaskContext aContext) throws Exception {
System.out.println("Running producer");
Properties data = new Properties();
data.setProperty("key", "value");
aContext.storeBinary("DATA", new PropertiesAdapter(data));
}
};
Task consumer = new ExecutableTaskBase() {
@Override
public void execute(TaskContext aContext) throws Exception {
System.out.println("Running consumer");
Properties data = new Properties();
aContext.retrieveBinary("DATA", new PropertiesAdapter(data));
Assert.assertEquals(data.getProperty("key"), "value");
}
};
consumer.addImport(producer, "DATA1", "DATA");
DefaultBatchTask batch = new DefaultBatchTask();
// BatchTask batch = new BatchTask();
batch.addTask(producer);
batch.addTask(consumer);
Lab.getInstance().run(batch);
}
Aggregations