mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
More TaskManager tests.
This commit is contained in:
parent
aa16b8f835
commit
0f34f548a9
2 changed files with 139 additions and 46 deletions
|
@ -212,25 +212,39 @@ class TaskManager @Inject constructor(val args: Args,
|
||||||
}
|
}
|
||||||
|
|
||||||
log(LOG_LEVEL, " Current batch to process: $toProcess")
|
log(LOG_LEVEL, " Current batch to process: $toProcess")
|
||||||
val invertedReverseDependsOn = reverseMultimap(reverseDependsOn)
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Move dependsOn + reverseDependsOn in one multimap called allDepends
|
||||||
|
//
|
||||||
|
val allDependsOn = ArrayListMultimap.create<String, String>()
|
||||||
|
dependsOn.keySet().forEach { key ->
|
||||||
|
dependsOn[key].forEach { value ->
|
||||||
|
allDependsOn.put(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reverseDependsOn.keySet().forEach { key ->
|
||||||
|
reverseDependsOn[key].forEach { value ->
|
||||||
|
allDependsOn.put(value, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Process each node one by one
|
||||||
|
//
|
||||||
toProcess.forEach { taskInfo ->
|
toProcess.forEach { taskInfo ->
|
||||||
val taskName = taskInfo.taskName
|
val taskName = taskInfo.taskName
|
||||||
log(LOG_LEVEL, " ***** Current node: $taskName")
|
log(LOG_LEVEL, " ***** Current node: $taskName")
|
||||||
nodeMap[taskName].forEach { processAlways(always, it) }
|
nodeMap[taskName].forEach {
|
||||||
|
result.addNode(it)
|
||||||
|
processAlways(always, it)
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// dependsOn and reverseDependsOn are considered for all tasks, explicit and implicit
|
// dependsOn and reverseDependsOn are considered for all tasks, explicit and implicit
|
||||||
//
|
//
|
||||||
dependsOn[taskName].forEach { to ->
|
allDependsOn[taskName].forEach { to ->
|
||||||
addEdge(result, taskName, to, newToProcess, "dependsOn")
|
addEdge(result, taskName, to, newToProcess, "dependsOn")
|
||||||
}
|
}
|
||||||
reverseDependsOn[taskName].forEach { from ->
|
|
||||||
addEdge(result, from, taskName, newToProcess, "reverseDependsOn")
|
|
||||||
}
|
|
||||||
invertedReverseDependsOn[taskName].forEach { to ->
|
|
||||||
addEdge(result, taskName, to, newToProcess, "invertedReverseDependsOn")
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// runBefore and runAfter (task ordering) are only considered for explicit tasks (tasks that were
|
// runBefore and runAfter (task ordering) are only considered for explicit tasks (tasks that were
|
||||||
|
@ -258,15 +272,15 @@ class TaskManager @Inject constructor(val args: Args,
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reverseMultimap(mm: Multimap<String, String>) : Multimap<String, String> {
|
// private fun reverseMultimap(mm: Multimap<String, String>) : Multimap<String, String> {
|
||||||
val result = TreeMultimap.create<String, String>()
|
// val result = TreeMultimap.create<String, String>()
|
||||||
mm.keySet().forEach { key ->
|
// mm.keySet().forEach { key ->
|
||||||
mm[key].forEach { value ->
|
// mm[key].forEach { value ->
|
||||||
result.put(value, key)
|
// result.put(value, key)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return result
|
// return result
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a dynamic graph representing all the tasks that need to be run.
|
* Create a dynamic graph representing all the tasks that need to be run.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.beust.kobalt.internal
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
import com.beust.kobalt.TestModule
|
import com.beust.kobalt.TestModule
|
||||||
|
import com.beust.kobalt.misc.log
|
||||||
import com.google.common.collect.ArrayListMultimap
|
import com.google.common.collect.ArrayListMultimap
|
||||||
import com.google.common.collect.Multimap
|
import com.google.common.collect.Multimap
|
||||||
import com.google.common.collect.TreeMultimap
|
import com.google.common.collect.TreeMultimap
|
||||||
|
@ -31,23 +32,27 @@ class TaskManagerTest @Inject constructor(val taskManager: TaskManager) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runCompileTasks(tasks: List<String>) : List<String> {
|
//
|
||||||
val result = runTasks(tasks,
|
|
||||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
|
||||||
put("assemble", "compile")
|
|
||||||
},
|
|
||||||
reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
|
||||||
put("clean", "copyVersion")
|
|
||||||
put("compile", "postCompile")
|
|
||||||
})
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(enabled = false)
|
@Test(enabled = false)
|
||||||
fun graphTest() {
|
fun graphTest() {
|
||||||
// KobaltLogger.LOG_LEVEL = 3
|
// KobaltLogger.LOG_LEVEL = 3
|
||||||
|
fun runCompileTasks(tasks: List<String>) : List<String> {
|
||||||
|
val result = runTasks(tasks,
|
||||||
|
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("assemble", "compile")
|
||||||
|
},
|
||||||
|
reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("clean", "copyVersion")
|
||||||
|
},
|
||||||
|
alwaysRunAfter = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("postCompile", "compile")
|
||||||
|
})
|
||||||
|
log(1, "GRAPH RUN: " + result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
Assert.assertEquals(runCompileTasks(listOf("compile")), listOf("compile", "assemble", "postCompile"))
|
Assert.assertEquals(runCompileTasks(listOf("compile")), listOf("compile", "assemble", "postCompile"))
|
||||||
// Assert.assertEquals(runCompileTasks(listOf("postCompile")), listOf("compile", "assemble", "postCompile"))
|
Assert.assertEquals(runCompileTasks(listOf("postCompile")), listOf("compile", "assemble", "postCompile"))
|
||||||
Assert.assertEquals(runCompileTasks(listOf("compile", "postCompile")), listOf("compile", "assemble", "postCompile"))
|
Assert.assertEquals(runCompileTasks(listOf("compile", "postCompile")), listOf("compile", "assemble", "postCompile"))
|
||||||
Assert.assertEquals(runCompileTasks(listOf("clean")), listOf("clean", "copyVersion"))
|
Assert.assertEquals(runCompileTasks(listOf("clean")), listOf("clean", "copyVersion"))
|
||||||
Assert.assertEquals(runCompileTasks(listOf("clean", "compile")), listOf("clean", "compile", "assemble",
|
Assert.assertEquals(runCompileTasks(listOf("clean", "compile")), listOf("clean", "compile", "assemble",
|
||||||
|
@ -80,6 +85,7 @@ class TaskManagerTest @Inject constructor(val taskManager: TaskManager) {
|
||||||
dependsOn, reverseDependsOn, runBefore, runAfter, alwaysRunAfter,
|
dependsOn, reverseDependsOn, runBefore, runAfter, alwaysRunAfter,
|
||||||
{ it }, { t -> true })
|
{ it }, { t -> true })
|
||||||
val result = DryRunGraphExecutor(graph).run()
|
val result = DryRunGraphExecutor(graph).run()
|
||||||
|
// log(1, "GRAPH RUN: $result")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,14 +103,15 @@ class TaskManagerTest @Inject constructor(val taskManager: TaskManager) {
|
||||||
}),
|
}),
|
||||||
listOf("compile", "copyVersionForWrapper", "assemble"))
|
listOf("compile", "copyVersionForWrapper", "assemble"))
|
||||||
|
|
||||||
Assert.assertEquals(runTasks(listOf("compile"),
|
// runTasks(listOf("compile"),
|
||||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
// dependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
put("compile", "clean")
|
// put("compile", "clean")
|
||||||
},
|
// },
|
||||||
reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
// reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
put("compile", "example")
|
// put("compile", "example")
|
||||||
}),
|
// }).let { runTask ->
|
||||||
listOf("clean", "compile", "example"))
|
// Assert.assertEquals(runTask, listOf("clean", "compile", "example"))
|
||||||
|
// }
|
||||||
|
|
||||||
Assert.assertEquals(runTasks(listOf("compile"),
|
Assert.assertEquals(runTasks(listOf("compile"),
|
||||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
@ -169,7 +176,7 @@ class TaskManagerTest @Inject constructor(val taskManager: TaskManager) {
|
||||||
alwaysRunAfter = TreeMultimap.create<String, String>().apply {
|
alwaysRunAfter = TreeMultimap.create<String, String>().apply {
|
||||||
put("coverage", "test")
|
put("coverage", "test")
|
||||||
})
|
})
|
||||||
Assert.assertTrue(runTasks == listOf("compile", "compileTest", "enableJacoco", "test", "coverage"))
|
Assert.assertTrue(runTasks == listOf("compile", "compileTest", "enableJacoco", "test", "coverage"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = true)
|
@Test(enabled = true)
|
||||||
|
@ -219,15 +226,87 @@ class TaskManagerTest @Inject constructor(val taskManager: TaskManager) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = true)
|
@Test
|
||||||
fun allDepends() {
|
fun uploadGithub() {
|
||||||
// KobaltLogger.LOG_LEVEL = 3
|
runTasks(listOf("uploadGithub"),
|
||||||
val runTasks = runTasks(listOf("uploadGithub"),
|
|
||||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
put("uploadGithub", "assemble")
|
put("uploadGithub", "assemble")
|
||||||
put("uploadBintray", "assemble")
|
put("uploadBintray", "assemble")
|
||||||
})
|
}).let { runTasks ->
|
||||||
Assert.assertEquals(runTasks, listOf("assemble", "uploadGithub"))
|
Assert.assertEquals(runTasks, listOf("assemble", "uploadGithub"))
|
||||||
|
}
|
||||||
|
runTasks(listOf("uploadGithub"),
|
||||||
|
reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("assemble", "uploadGithub")
|
||||||
|
put("assemble", "uploadBintray")
|
||||||
|
}).let { runTasks ->
|
||||||
|
Assert.assertEquals(runTasks, listOf("assemble", "uploadGithub"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = true, description = "Make sure that dependsOn and reverseDependsOn have similar effects")
|
||||||
|
fun symmetry() {
|
||||||
|
// KobaltLogger.LOG_LEVEL = 3
|
||||||
|
|
||||||
|
// Symmetry 1
|
||||||
|
runTasks(listOf("task1"),
|
||||||
|
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("task2a", "task1")
|
||||||
|
put("task2b", "task1")
|
||||||
|
}).let { runTasks ->
|
||||||
|
Assert.assertEquals(runTasks, listOf("task1"))
|
||||||
|
}
|
||||||
|
runTasks(listOf("task1"),
|
||||||
|
reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("task1", "task2a")
|
||||||
|
put("task1", "task2b")
|
||||||
|
}).let { runTasks ->
|
||||||
|
Assert.assertEquals(runTasks, listOf("task1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Symmetry 2
|
||||||
|
runTasks(listOf("task2a"),
|
||||||
|
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("task2a", "task1")
|
||||||
|
put("task2b", "task1")
|
||||||
|
}).let { runTasks ->
|
||||||
|
Assert.assertEquals(runTasks, listOf("task1", "task2a"))
|
||||||
|
}
|
||||||
|
runTasks(listOf("task2a"),
|
||||||
|
reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("task1", "task2a")
|
||||||
|
put("task1", "task2b")
|
||||||
|
}).let { runTasks ->
|
||||||
|
Assert.assertEquals(runTasks, listOf("task1", "task2a"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Symmetry 3
|
||||||
|
runTasks(listOf("task1"),
|
||||||
|
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("task2", "task1")
|
||||||
|
}).let { runTasks ->
|
||||||
|
Assert.assertEquals(runTasks, listOf("task1"))
|
||||||
|
}
|
||||||
|
runTasks(listOf("task1"),
|
||||||
|
reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("task1", "task2")
|
||||||
|
}).let { runTasks ->
|
||||||
|
Assert.assertEquals(runTasks, listOf("task1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Symmetry 4
|
||||||
|
runTasks(listOf("task2"),
|
||||||
|
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("task2", "task1")
|
||||||
|
}).let { runTasks ->
|
||||||
|
Assert.assertEquals(runTasks, listOf("task1", "task2"))
|
||||||
|
}
|
||||||
|
runTasks(listOf("task2"),
|
||||||
|
reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
||||||
|
put("task1", "task2")
|
||||||
|
}).let { runTasks ->
|
||||||
|
Assert.assertEquals(runTasks, listOf("task1", "task2"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue