46 lines
1.5 KiB
Kotlin
46 lines
1.5 KiB
Kotlin
package com.gzzn.omms.msgexchange.ingress
|
|||
|
|
|
||
|
|
import com.gzzn.omms.msgexchange.domain.ProcStatus
|
||
|
|
import com.gzzn.omms.msgexchange.infra.stub.StubInbox
|
||
|
|
import com.gzzn.omms.msgexchange.infra.stub.StubProcState
|
||
|
|
import com.gzzn.omms.msgexchange.processing.Pump
|
||
|
|
import io.micronaut.test.extensions.junit5.annotation.MicronautTest
|
||
|
|
import jakarta.inject.Inject
|
||
|
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||
|
|
import org.junit.jupiter.api.Assertions.assertNotNull
|
||
|
|
import org.junit.jupiter.api.BeforeEach
|
||
|
|
import org.junit.jupiter.api.Test
|
||
|
|
|
||
|
|
/** 主路径:JDBC 轮询语义(stub 下 InboxPoller + 外部写信箱模拟)。 */
|
||
|
|
@MicronautTest
|
||
|
|
class InboxPollerTest {
|
||
|
|
|
||
|
|
@Inject lateinit var poller: InboxPoller
|
||
|
|
@Inject lateinit var pump: Pump
|
||
|
|
@Inject lateinit var stubInbox: StubInbox
|
||
|
|
@Inject lateinit var stubProc: StubProcState
|
||
|
|
|
||
|
|
@BeforeEach
|
||
|
|
fun clean() {
|
||
|
|
stubInbox.clear()
|
||
|
|
stubProc.clear()
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `poller enqueues externally written mailbox rows`() {
|
||
|
|
val id = stubInbox.simulateExternalWrite("<MSG/>")
|
||
|
|
assertEquals(1, poller.pollOnce())
|
||
|
|
assertNotNull(stubProc.snapshotOf(id))
|
||
|
|
assertEquals(ProcStatus.PENDING, stubProc.snapshotOf(id)!!.state)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `poller is idempotent for already enqueued rows`() {
|
||
|
|
val id = stubInbox.simulateExternalWrite("<MSG/>")
|
||
|
|
poller.pollOnce()
|
||
|
|
assertEquals(0, poller.pollOnce())
|
||
|
|
pump.tick()
|
||
|
|
assertEquals(ProcStatus.FAILED, stubProc.snapshotOf(id)!!.state)
|
||
|
|
}
|
||
|
|
}
|