You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.6 KiB
Kotlin
124 lines
4.6 KiB
Kotlin
package wf.servitor.engine
|
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
import kotlinx.coroutines.delay
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.runBlocking
|
|
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration
|
|
import org.apache.activemq.artemis.api.core.QueueAttributes
|
|
import org.apache.activemq.artemis.api.core.RoutingType
|
|
import org.apache.activemq.artemis.api.core.SimpleString
|
|
import org.apache.activemq.artemis.api.core.client.ActiveMQClient
|
|
import org.apache.activemq.artemis.api.core.client.ClientSession
|
|
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory
|
|
import org.apache.activemq.artemis.api.core.client.ServerLocator
|
|
import org.koin.core.context.startKoin
|
|
import org.koin.core.qualifier.named
|
|
import org.koin.dsl.module
|
|
import wf.servitor.common.Event
|
|
import wf.servitor.common.event.Session
|
|
import wf.servitor.common.workflow.Flow
|
|
import wf.servitor.common.workflow.Workflow
|
|
import wf.servitor.common.workflow.step.ActionStep
|
|
import kotlin.test.Test
|
|
|
|
|
|
class EngineTests {
|
|
fun workflow(): Workflow {
|
|
return Workflow(
|
|
Flow(
|
|
listOf(
|
|
ActionStep("sum = 1 + 1", "sum"),
|
|
ActionStep("sum += 4", "more-sum"),
|
|
ActionStep("sum += nice:plus(sum, 4)", "remote-sum")
|
|
)
|
|
),
|
|
services = mutableMapOf(
|
|
"nice" to mapOf()
|
|
)
|
|
)
|
|
}
|
|
|
|
@Test
|
|
fun testOk() {
|
|
val app = startKoin {
|
|
modules(module {
|
|
single { ActiveMQClient.createServerLocator("tcp://localhost:61616") }
|
|
single { get<ServerLocator>().createSessionFactory() }
|
|
single {
|
|
val serverLocator: ServerLocator = get()
|
|
|
|
|
|
|
|
get<ClientSessionFactory>().createSession(
|
|
"artemis",
|
|
"simetraehcapa",
|
|
false,
|
|
true,
|
|
true,
|
|
serverLocator.isPreAcknowledge,
|
|
serverLocator.ackBatchSize
|
|
)
|
|
}
|
|
single { get<ClientSession>().createProducer() }
|
|
single(named("queue.task")) {
|
|
val session: ClientSession = get()
|
|
println("Creating address")
|
|
session.createAddress(SimpleString("servitor.task"), RoutingType.ANYCAST, true)
|
|
|
|
println("Checking task queue")
|
|
if (!session.queueQuery(SimpleString("servitor.task.queue")).isExists) {
|
|
println("Creating task queue")
|
|
session.createQueue(
|
|
SimpleString("servitor.task"),
|
|
SimpleString("servitor.task.queue"),
|
|
true,
|
|
QueueAttributes().apply {
|
|
routingType = RoutingType.ANYCAST
|
|
durable = true
|
|
purgeOnNoConsumers = false
|
|
maxConsumers = ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers()
|
|
}
|
|
)
|
|
}
|
|
|
|
println("Checking observation queue")
|
|
if (!session.queueQuery(SimpleString("servitor.observe")).isExists) {
|
|
println("Creating observation queue")
|
|
session.createQueue(
|
|
SimpleString("servitor.#"),
|
|
SimpleString("servitor.observe"),
|
|
true,
|
|
QueueAttributes().apply {
|
|
routingType = RoutingType.ANYCAST
|
|
durable = true
|
|
purgeOnNoConsumers = false
|
|
maxConsumers = ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers()
|
|
}
|
|
)
|
|
}
|
|
|
|
Session(get(), "servitor.task.queue")
|
|
}
|
|
})
|
|
|
|
modules(engineModule)
|
|
}
|
|
|
|
val session: Session = app.koin.get(named("queue.task"))
|
|
val engine = Engine()
|
|
val engineJob = GlobalScope.launch {
|
|
engine.run()
|
|
}
|
|
|
|
runBlocking {
|
|
println("Queueing task")
|
|
session.queueTask(Event.Task(workflow()))
|
|
println("Send task")
|
|
delay(5000)
|
|
engine.stop()
|
|
engineJob.join()
|
|
}
|
|
}
|
|
}
|