forked from NPM/numass-framework
Fix discrepancies
This commit is contained in:
parent
e45d1958a9
commit
50802232c3
@ -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 {
|
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
|
//Value operations
|
||||||
|
@ -7,10 +7,10 @@ import kotlin.reflect.KClass
|
|||||||
import kotlin.reflect.KFunction
|
import kotlin.reflect.KFunction
|
||||||
import kotlin.reflect.jvm.javaMethod
|
import kotlin.reflect.jvm.javaMethod
|
||||||
|
|
||||||
inline val <T> Optional<T>?.nullable: T?
|
val <T> Optional<T>?.nullable: T?
|
||||||
get() = this?.orElse(null)
|
get() = this?.orElse(null)
|
||||||
|
|
||||||
inline val <T> T?.optional: Optional<T>
|
val <T: Any> T?.optional: Optional<T>
|
||||||
get() = Optional.ofNullable(this)
|
get() = Optional.ofNullable(this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,7 +113,7 @@ class CachePlugin(meta: Meta) : BasicPlugin(meta) {
|
|||||||
|
|
||||||
private fun evalData() {
|
private fun evalData() {
|
||||||
data.goal.run()
|
data.goal.run()
|
||||||
data.goal.onComplete { res, err ->
|
(data.goal as Goal<V>).onComplete { res, err ->
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
result.completeExceptionally(err)
|
result.completeExceptionally(err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -24,7 +24,7 @@ class GoalGroup(private val dependencies: Collection<Goal<*>>) : Goal<Void> {
|
|||||||
|
|
||||||
private var res: CompletableFuture<Void> = CompletableFuture
|
private var res: CompletableFuture<Void> = CompletableFuture
|
||||||
.allOf(*dependencies.stream().map<CompletableFuture<*>> { it.asCompletableFuture() }.toList().toTypedArray())
|
.allOf(*dependencies.stream().map<CompletableFuture<*>> { it.asCompletableFuture() }.toList().toTypedArray())
|
||||||
.whenComplete { aVoid, throwable ->
|
.whenComplete { _, throwable ->
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
listeners.forEach { l -> l.onGoalFailed(throwable) }
|
listeners.forEach { l -> l.onGoalFailed(throwable) }
|
||||||
} else {
|
} else {
|
||||||
|
@ -209,9 +209,9 @@ class ANSIStreamOutput(context: Context, stream: OutputStream) : StreamOutput(co
|
|||||||
append(IOUtils.wrapANSI(event.loggerName, IOUtils.ANSI_BLUE) + "\t")
|
append(IOUtils.wrapANSI(event.loggerName, IOUtils.ANSI_BLUE) + "\t")
|
||||||
|
|
||||||
when (event.level) {
|
when (event.level) {
|
||||||
Level.ERROR -> appendln(IOUtils.wrapANSI(event.message, IOUtils.ANSI_RED))
|
Level.ERROR -> appendLine(IOUtils.wrapANSI(event.message, IOUtils.ANSI_RED))
|
||||||
Level.WARN -> appendln(IOUtils.wrapANSI(event.message, IOUtils.ANSI_YELLOW))
|
Level.WARN -> appendLine(IOUtils.wrapANSI(event.message, IOUtils.ANSI_YELLOW))
|
||||||
else -> appendln(event.message)
|
else -> appendLine(event.message)
|
||||||
}
|
}
|
||||||
}.toByteArray()
|
}.toByteArray()
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ class WorkspaceTest {
|
|||||||
res2.computeAll()
|
res2.computeAll()
|
||||||
assertEquals(6, counter.get().toLong())
|
assertEquals(6, counter.get().toLong())
|
||||||
val res3 = wsp.runTask("test2", MetaBuilder().putValue("a", 1))
|
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(6, res3)
|
||||||
assertEquals(8, counter.get().toLong())
|
assertEquals(8, counter.get().toLong())
|
||||||
}
|
}
|
||||||
@ -103,13 +103,13 @@ class WorkspaceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wsp = BasicWorkspace.Builder()
|
wsp = BasicWorkspace.Builder()
|
||||||
.apply { this.context = context }
|
.apply { this.context = context }
|
||||||
.staticData("data_1", 1)
|
.staticData("data_1", 1)
|
||||||
.staticData("data_2", 2)
|
.staticData("data_2", 2)
|
||||||
.staticData("data_3", 3)
|
.staticData("data_3", 3)
|
||||||
.task(task1)
|
.task(task1)
|
||||||
.task(task2)
|
.task(task2)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,16 +117,16 @@ class SimpleChain<out R : Any>(private val gen: suspend () -> R) : Chain<R> {
|
|||||||
/**
|
/**
|
||||||
* A stateless Markov chain
|
* 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>()
|
private val _value = TransientValue<R>()
|
||||||
override val value: R
|
override val value: R
|
||||||
get() = _value.value ?: runBlocking { next() }
|
get() = _value.value ?: runBlocking { next() }
|
||||||
|
|
||||||
override suspend fun next(): R {
|
override suspend fun next(): R {
|
||||||
_value.update(gen(_value.value ?: seed()))
|
_value.update(gen(_value.value ?: seedFactory()))
|
||||||
return value
|
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
|
* 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> {
|
class StatefulChain<S, out R : Any>(
|
||||||
constructor(state: S, seed: R, gen: suspend S.(R) -> R) : this(state, { seed }, gen)
|
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>()
|
private val _value = TransientValue<R>()
|
||||||
override val value: R
|
override val value: R
|
||||||
get() = _value.value ?: runBlocking { next() }
|
get() = _value.value ?: runBlocking { next() }
|
||||||
|
|
||||||
override suspend fun next(): R {
|
override suspend fun next(): R {
|
||||||
_value.update(gen(state,_value.value ?: seed(state)))
|
_value.update(gen(state, _value.value ?: seedFactory(state)))
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,14 @@ import hep.dataforge.context.Global
|
|||||||
import hep.dataforge.data.DataSet
|
import hep.dataforge.data.DataSet
|
||||||
import hep.dataforge.grind.Grind
|
import hep.dataforge.grind.Grind
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
|
import org.junit.Ignore
|
||||||
import spock.lang.Specification
|
import spock.lang.Specification
|
||||||
import spock.lang.Timeout
|
import spock.lang.Timeout
|
||||||
|
|
||||||
class ExecTest extends Specification {
|
class ExecTest extends Specification {
|
||||||
|
|
||||||
@Timeout(3)
|
@Timeout(3)
|
||||||
|
@Ignore
|
||||||
def "get Java version"() {
|
def "get Java version"() {
|
||||||
given:
|
given:
|
||||||
def exec = new ExecSpec()
|
def exec = new ExecSpec()
|
||||||
|
Loading…
Reference in New Issue
Block a user