Fix discrepancies

This commit is contained in:
Alexander Nozik 2021-05-29 17:42:30 +03:00
parent e45d1958a9
commit 50802232c3
8 changed files with 28 additions and 22 deletions

View File

@ -41,7 +41,7 @@ fun Context.buildContext(name: String, vararg plugins: Class<out Plugin>, init:
}
fun buildContext(name: String, vararg plugins: Class<out Plugin>, init: ContextBuilder.() -> Unit = {}): Context {
return Global.buildContext(name = name, plugins = *plugins, init = init)
return Global.buildContext(name = name, plugins = plugins, init = init)
}
//Value operations

View File

@ -7,10 +7,10 @@ import kotlin.reflect.KClass
import kotlin.reflect.KFunction
import kotlin.reflect.jvm.javaMethod
inline val <T> Optional<T>?.nullable: T?
val <T> Optional<T>?.nullable: T?
get() = this?.orElse(null)
inline val <T> T?.optional: Optional<T>
val <T: Any> T?.optional: Optional<T>
get() = Optional.ofNullable(this)
/**

View File

@ -113,7 +113,7 @@ class CachePlugin(meta: Meta) : BasicPlugin(meta) {
private fun evalData() {
data.goal.run()
data.goal.onComplete { res, err ->
(data.goal as Goal<V>).onComplete { res, err ->
if (err != null) {
result.completeExceptionally(err)
} else {

View File

@ -24,7 +24,7 @@ class GoalGroup(private val dependencies: Collection<Goal<*>>) : Goal<Void> {
private var res: CompletableFuture<Void> = CompletableFuture
.allOf(*dependencies.stream().map<CompletableFuture<*>> { it.asCompletableFuture() }.toList().toTypedArray())
.whenComplete { aVoid, throwable ->
.whenComplete { _, throwable ->
if (throwable != null) {
listeners.forEach { l -> l.onGoalFailed(throwable) }
} else {

View File

@ -209,9 +209,9 @@ class ANSIStreamOutput(context: Context, stream: OutputStream) : StreamOutput(co
append(IOUtils.wrapANSI(event.loggerName, IOUtils.ANSI_BLUE) + "\t")
when (event.level) {
Level.ERROR -> appendln(IOUtils.wrapANSI(event.message, IOUtils.ANSI_RED))
Level.WARN -> appendln(IOUtils.wrapANSI(event.message, IOUtils.ANSI_YELLOW))
else -> appendln(event.message)
Level.ERROR -> appendLine(IOUtils.wrapANSI(event.message, IOUtils.ANSI_RED))
Level.WARN -> appendLine(IOUtils.wrapANSI(event.message, IOUtils.ANSI_YELLOW))
else -> appendLine(event.message)
}
}.toByteArray()
}

View File

@ -51,7 +51,7 @@ class WorkspaceTest {
res2.computeAll()
assertEquals(6, counter.get().toLong())
val res3 = wsp.runTask("test2", MetaBuilder().putValue("a", 1))
.getCheckedData("data_2", Number::class.java).get().toLong()
.getCheckedData("data_2", Number::class.java).get().toLong()
assertEquals(6, res3)
assertEquals(8, counter.get().toLong())
}
@ -103,13 +103,13 @@ class WorkspaceTest {
}
wsp = BasicWorkspace.Builder()
.apply { this.context = context }
.staticData("data_1", 1)
.staticData("data_2", 2)
.staticData("data_3", 3)
.task(task1)
.task(task2)
.build()
.apply { this.context = context }
.staticData("data_1", 1)
.staticData("data_2", 2)
.staticData("data_3", 3)
.task(task1)
.task(task2)
.build()
}

View File

@ -117,16 +117,16 @@ class SimpleChain<out R : Any>(private val gen: suspend () -> R) : Chain<R> {
/**
* A stateless Markov chain
*/
class MarkovChain<out R : Any>(private val seed: () -> R, private val gen: suspend (R) -> R) : Chain<R> {
class MarkovChain<out R : Any>(private val seedFactory: () -> R, private val gen: suspend (R) -> R) : Chain<R> {
constructor(seed: R, gen: suspend (R) -> R) : this({ seed }, gen)
constructor(seed: R, gen: suspend (R) -> R) : this(seedFactory = { seed }, gen)
private val _value = TransientValue<R>()
override val value: R
get() = _value.value ?: runBlocking { next() }
override suspend fun next(): R {
_value.update(gen(_value.value ?: seed()))
_value.update(gen(_value.value ?: seedFactory()))
return value
}
@ -138,15 +138,19 @@ class MarkovChain<out R : Any>(private val seed: () -> R, private val gen: suspe
/**
* A chain with possibly mutable state. The state must not be changed outside the chain. Two chins should never share the state
*/
class StatefulChain<S, out R : Any>(val state: S, private val seed: S.() -> R, private val gen: suspend S.(R) -> R) : Chain<R> {
constructor(state: S, seed: R, gen: suspend S.(R) -> R) : this(state, { seed }, gen)
class StatefulChain<S, out R : Any>(
val state: S,
private val seedFactory: S.() -> R,
private val gen: suspend S.(R) -> R,
) : Chain<R> {
constructor(state: S, seed: R, gen: suspend S.(R) -> R) : this(state, seedFactory = { seed }, gen)
private val _value = TransientValue<R>()
override val value: R
get() = _value.value ?: runBlocking { next() }
override suspend fun next(): R {
_value.update(gen(state,_value.value ?: seed(state)))
_value.update(gen(state, _value.value ?: seedFactory(state)))
return value
}

View File

@ -4,12 +4,14 @@ import hep.dataforge.context.Global
import hep.dataforge.data.DataSet
import hep.dataforge.grind.Grind
import hep.dataforge.meta.Meta
import org.junit.Ignore
import spock.lang.Specification
import spock.lang.Timeout
class ExecTest extends Specification {
@Timeout(3)
@Ignore
def "get Java version"() {
given:
def exec = new ExecSpec()