Test for plugin task loading
This commit is contained in:
parent
f1692297b8
commit
2a395f8064
@ -116,11 +116,11 @@ open class Context(final override val name: String, val parent: Context? = Globa
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.content(target: String): Map<Name, Any> = content<Any>(target)
|
||||
|
||||
/**
|
||||
* A sequences of all objects provided by plugins with given target and type
|
||||
*/
|
||||
fun Context.content(target: String): Map<Name, Any> = content<Any>(target)
|
||||
|
||||
@JvmName("typedContent")
|
||||
inline fun <reified T : Any> Context.content(target: String): Map<Name, T> =
|
||||
plugins.flatMap { plugin ->
|
||||
|
@ -85,11 +85,12 @@ inline fun <reified T : Any> Provider.provide(target: String, name: Name): T? {
|
||||
inline fun <reified T : Any> Provider.provide(target: String, name: String): T? =
|
||||
provide(target, name.toName())
|
||||
|
||||
|
||||
fun Provider.top(target: String): Map<Name, Any> = top<Any>(target)
|
||||
|
||||
/**
|
||||
* A top level content with names
|
||||
*/
|
||||
fun Provider.top(target: String): Map<Name, Any> = top<Any>(target)
|
||||
|
||||
@JvmName("typedTop")
|
||||
inline fun <reified T : Any> Provider.top(target: String): Map<Name, T> {
|
||||
return listNames(target).associate {
|
||||
|
@ -104,7 +104,7 @@ class NodeDescriptor(override val config: Config) : Specific {
|
||||
*/
|
||||
val nodes: Map<String, NodeDescriptor>
|
||||
get() = config.getAll("node".toName()).entries.associate { (name, node) ->
|
||||
name to NodeDescriptor.wrap(node.node ?: error("Node descriptor must be a node"))
|
||||
name to wrap(node.node ?: error("Node descriptor must be a node"))
|
||||
}
|
||||
|
||||
|
||||
@ -114,7 +114,7 @@ class NodeDescriptor(override val config: Config) : Specific {
|
||||
}
|
||||
|
||||
fun node(name: String, block: NodeDescriptor.() -> Unit) {
|
||||
node(name, NodeDescriptor.build { this.name = name }.apply(block))
|
||||
node(name, build { this.name = name }.apply(block))
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@ package hep.dataforge.workspace
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.context.content
|
||||
import hep.dataforge.data.DataNode
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.names.Name
|
||||
@ -18,8 +19,9 @@ class SimpleWorkspace(
|
||||
override val targets: Map<String, Meta>,
|
||||
tasks: Collection<Task<Any>>
|
||||
) : Workspace {
|
||||
|
||||
override val tasks: Map<Name, Task<*>> by lazy {
|
||||
context.top<Task<*>>(Task.TYPE) + tasks.associate { it.name.toName() to it }
|
||||
context.content<Task<*>>(Task.TYPE) + tasks.associate { it.name.toName() to it }
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -26,7 +26,7 @@ interface WorkspaceBuilder {
|
||||
/**
|
||||
* Set the context for future workspcace
|
||||
*/
|
||||
fun WorkspaceBuilder.context(name: String, block: ContextBuilder.() -> Unit = {}) {
|
||||
fun WorkspaceBuilder.context(name: String = "WORKSPACE", block: ContextBuilder.() -> Unit = {}) {
|
||||
context = ContextBuilder(name, parentContext).apply(block).build()
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ class TaskBuilder(val name: String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun task(name: String, builder: TaskBuilder.() -> Unit): GenericTask<Any> {
|
||||
fun Workspace.Companion.task(name: String, builder: TaskBuilder.() -> Unit): GenericTask<Any> {
|
||||
return TaskBuilder(name).apply(builder).build()
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,52 @@
|
||||
package hep.dataforge.workspace
|
||||
|
||||
import hep.dataforge.context.AbstractPlugin
|
||||
import hep.dataforge.context.PluginTag
|
||||
import hep.dataforge.data.first
|
||||
import hep.dataforge.data.get
|
||||
import hep.dataforge.meta.boolean
|
||||
import hep.dataforge.meta.get
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.toName
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
|
||||
class SimpleWorkspaceTest {
|
||||
val testPlugin = object : AbstractPlugin() {
|
||||
override val tag: PluginTag = PluginTag("test")
|
||||
|
||||
val contextTask = Workspace.task("test") {
|
||||
pipe<Any, Unit> {
|
||||
context.logger.info { "Test: $it" }
|
||||
}
|
||||
}
|
||||
|
||||
override fun provideTop(target: String, name: Name): Any? {
|
||||
return if (target == Task.TYPE && name == "test".toName()) {
|
||||
contextTask
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun listNames(target: String): Sequence<Name> {
|
||||
return if(target== Task.TYPE){
|
||||
sequenceOf(contextTask.name.toName())
|
||||
} else{
|
||||
emptySequence()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val workspace = SimpleWorkspace.build {
|
||||
|
||||
context{
|
||||
plugin(testPlugin)
|
||||
}
|
||||
|
||||
repeat(100) {
|
||||
static("myData[$it]", it)
|
||||
}
|
||||
@ -67,6 +103,8 @@ class SimpleWorkspaceTest {
|
||||
data["even"]!! - data["odd"]!!
|
||||
}
|
||||
}
|
||||
|
||||
target("empty") {}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -78,7 +116,14 @@ class SimpleWorkspaceTest {
|
||||
|
||||
@Test
|
||||
fun testMetaPropagation() {
|
||||
val node = workspace.run("sum"){"testFlag" to true}
|
||||
val node = workspace.run("sum") { "testFlag" to true }
|
||||
val res = node.first().get()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPluginTask() {
|
||||
val tasks = workspace.tasks
|
||||
assertTrue { tasks["test.test"] != null }
|
||||
//val node = workspace.run("test.test", "empty")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user