refactor(config): drop system-time defaults from domain and entry points
删除会被误用的系统时间默认值:MsgEvent.createdAt、ProcState.updatedAt、InboxPoller.pollOnce(now)、HistorySweepJob.run(now)、Identity.of(day)。Identity 的日期边界改由 MessageProcessor 按 PARAM:msgx.operation-day.zone 算出后传入(边界关闭时身份值不变);StubProcState/StubInbox 改注入 Clock(测试可传假时钟),全部调用点显式传时间。 验证:./gradlew test 145 tests / 0 fail / 0 skipped。
This commit is contained in:
@@ -30,6 +30,7 @@ import com.gzzn.omms.msgexchange.domain.SnapshotLogEntry
|
||||
import com.gzzn.omms.msgexchange.infra.persistence.SnapshotLogRepository
|
||||
import io.micronaut.context.annotation.Requires
|
||||
import jakarta.inject.Singleton
|
||||
import java.time.Clock
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
@@ -56,7 +57,7 @@ class StubPipelineLock : PipelineLockRepository {
|
||||
@Singleton
|
||||
@Requires(property = "msgx.stubs", value = "true")
|
||||
/** 内存版 PROC_STATE:入队幂等,写终态时一并写下回填待办。 */
|
||||
class StubProcState : ProcStateRepository {
|
||||
class StubProcState(private val clock: Clock = Clock.systemUTC()) : ProcStateRepository {
|
||||
val rows = linkedMapOf<Long, ProcState>()
|
||||
val bound = linkedMapOf<String, Long>()
|
||||
|
||||
@@ -74,6 +75,7 @@ class StubProcState : ProcStateRepository {
|
||||
msgId, ProcStatus.PENDING,
|
||||
receivedAt = receivedAt,
|
||||
enqueuedAt = enqueuedAt ?: receivedAt,
|
||||
updatedAt = clock.instant(),
|
||||
)
|
||||
return true
|
||||
}
|
||||
@@ -89,7 +91,7 @@ class StubProcState : ProcStateRepository {
|
||||
val owner = bound[identityKey]
|
||||
if (owner != null && owner != msgId) return false
|
||||
bound[identityKey] = msgId
|
||||
rows[msgId] = (rows[msgId] ?: ProcState(msgId, ProcStatus.PENDING)).copy(identityKey = identityKey)
|
||||
rows[msgId] = (rows[msgId] ?: ProcState(msgId, ProcStatus.PENDING, updatedAt = clock.instant())).copy(identityKey = identityKey)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -103,14 +105,14 @@ class StubProcState : ProcStateRepository {
|
||||
errorClass: ErrorClass?,
|
||||
lastError: String?,
|
||||
) {
|
||||
val old = rows[msgId] ?: ProcState(msgId, state)
|
||||
val old = rows[msgId] ?: ProcState(msgId, state, updatedAt = clock.instant())
|
||||
rows[msgId] = old.copy(
|
||||
state = state,
|
||||
nextAttemptAt = nextAttemptAt ?: old.nextAttemptAt,
|
||||
attempts = attempts ?: old.attempts,
|
||||
errorClass = errorClass ?: old.errorClass,
|
||||
lastError = lastError ?: old.lastError,
|
||||
updatedAt = Instant.now(),
|
||||
updatedAt = clock.instant(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -123,7 +125,7 @@ class StubProcState : ProcStateRepository {
|
||||
attempts: Int?,
|
||||
now: Instant,
|
||||
) {
|
||||
val old = rows[msgId] ?: ProcState(msgId, state)
|
||||
val old = rows[msgId] ?: ProcState(msgId, state, updatedAt = clock.instant())
|
||||
rows[msgId] = old.copy(
|
||||
state = state,
|
||||
errorClass = errorClass,
|
||||
@@ -451,7 +453,7 @@ class StubReqTrack : ReqTrackRepository {
|
||||
@Singleton
|
||||
@Requires(property = "msgx.stubs", value = "true")
|
||||
/** 内存版共享信箱:可以模拟上游写入、库方清除,并记录哪些行被打上了处理标记。 */
|
||||
class StubInbox : CminmsgInboxRepository {
|
||||
class StubInbox(private val clock: Clock = Clock.systemUTC()) : CminmsgInboxRepository {
|
||||
val raws = linkedMapOf<Long, String>()
|
||||
private val received = linkedMapOf<Long, Instant>()
|
||||
private val marks = linkedMapOf<Long, String>()
|
||||
@@ -464,7 +466,7 @@ class StubInbox : CminmsgInboxRepository {
|
||||
override fun insertRaw(rawXml: String): Long {
|
||||
val id = ids.incrementAndGet()
|
||||
raws[id] = rawXml
|
||||
received[id] = Instant.now()
|
||||
received[id] = clock.instant()
|
||||
return id
|
||||
}
|
||||
|
||||
@@ -497,7 +499,7 @@ class StubInbox : CminmsgInboxRepository {
|
||||
fun simulateExternalWrite(rawXml: String): Long = insertRaw(rawXml)
|
||||
|
||||
/** 测试辅助:模拟先分配 ID、稍后才可见的迟提交行。 */
|
||||
fun restoreRow(msgId: Long, rawXml: String, receivedAt: Instant = Instant.now()) {
|
||||
fun restoreRow(msgId: Long, rawXml: String, receivedAt: Instant = clock.instant()) {
|
||||
raws[msgId] = rawXml
|
||||
received[msgId] = receivedAt
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user