Renamed to clarify. no nanos
This commit is contained in:
1 parent
390547425e
commit
eb7f8b2ba5
4 files changed
+6
-16
No files matched your search
@@ -1,26 +1,18 @@
|
|||||||
package no.iktdev.eventi.events
|
package no.iktdev.eventi.events
|
||||||
|
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.time.delay
|
import kotlinx.coroutines.time.delay
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import no.iktdev.eventi.MyTime
|
import no.iktdev.eventi.MyTime
|
||||||
import no.iktdev.eventi.PollerTraceStore
|
|
||||||
import no.iktdev.eventi.lifecycle.CurrentState
|
|
||||||
import no.iktdev.eventi.lifecycle.EventState
|
import no.iktdev.eventi.lifecycle.EventState
|
||||||
import no.iktdev.eventi.lifecycle.ILifecycleStore
|
import no.iktdev.eventi.lifecycle.ILifecycleStore
|
||||||
import no.iktdev.eventi.lifecycle.LifecycleStore
|
|
||||||
import no.iktdev.eventi.lifecycle.PollerBackoff
|
import no.iktdev.eventi.lifecycle.PollerBackoff
|
||||||
import no.iktdev.eventi.lifecycle.PollerCycleStart
|
import no.iktdev.eventi.lifecycle.PollerCycleStart
|
||||||
import no.iktdev.eventi.lifecycle.PollerFetched
|
import no.iktdev.eventi.lifecycle.PollerFetched
|
||||||
import no.iktdev.eventi.lifecycle.PollerGrouped
|
import no.iktdev.eventi.lifecycle.PollerGrouped
|
||||||
import no.iktdev.eventi.lifecycle.PollerUpdatedLastSeen
|
import no.iktdev.eventi.lifecycle.PollerUpdatedLastSeen
|
||||||
import no.iktdev.eventi.lifecycle.RefBusy
|
import no.iktdev.eventi.lifecycle.RefBusy
|
||||||
import no.iktdev.eventi.lifecycle.RefDispatchCompleted
|
|
||||||
import no.iktdev.eventi.lifecycle.RefDispatchSkipped
|
import no.iktdev.eventi.lifecycle.RefDispatchSkipped
|
||||||
import no.iktdev.eventi.lifecycle.RefDispatchStarted
|
|
||||||
import no.iktdev.eventi.lifecycle.RefFiltered
|
|
||||||
import no.iktdev.eventi.lifecycle.RefState
|
import no.iktdev.eventi.lifecycle.RefState
|
||||||
import no.iktdev.eventi.lifecycle.RefWatermarkUpdated
|
|
||||||
import no.iktdev.eventi.models.SignalEvent
|
import no.iktdev.eventi.models.SignalEvent
|
||||||
import no.iktdev.eventi.models.store.PersistedEvent
|
import no.iktdev.eventi.models.store.PersistedEvent
|
||||||
import no.iktdev.eventi.serialization.ZDS.toEvent
|
import no.iktdev.eventi.serialization.ZDS.toEvent
|
||||||
@@ -28,8 +20,6 @@ import no.iktdev.eventi.stores.EventStore
|
|||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import kotlin.text.compareTo
|
|
||||||
import kotlin.time.Duration.Companion.milliseconds
|
|
||||||
|
|
||||||
abstract class EventPollerImplementation(
|
abstract class EventPollerImplementation(
|
||||||
private val eventStore: EventStore,
|
private val eventStore: EventStore,
|
||||||
@@ -119,7 +109,7 @@ abstract class EventPollerImplementation(
|
|||||||
val maxSeenThisRound = newPersisted.maxOfOrNull { it.persistedAt }
|
val maxSeenThisRound = newPersisted.maxOfOrNull { it.persistedAt }
|
||||||
if (maxSeenThisRound != null && maxSeenThisRound >= lastSeenTime) {
|
if (maxSeenThisRound != null && maxSeenThisRound >= lastSeenTime) {
|
||||||
val before = lastSeenTime
|
val before = lastSeenTime
|
||||||
lastSeenTime = maxSeenThisRound.plusNanos(1)
|
lastSeenTime = maxSeenThisRound
|
||||||
|
|
||||||
// Lifecycle: global lastSeenTime flyttet
|
// Lifecycle: global lastSeenTime flyttet
|
||||||
lifecycleStore.add(
|
lifecycleStore.add(
|
||||||
@@ -135,7 +125,7 @@ abstract class EventPollerImplementation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun fetchNewPersistedEvents(scanFrom: Instant) =
|
private suspend fun fetchNewPersistedEvents(scanFrom: Instant) =
|
||||||
eventStore.getPersistedEventsAfter(scanFrom)
|
eventStore.getPersistedEventsAtOrAfter(scanFrom)
|
||||||
|
|
||||||
private suspend fun handleEmptyPoll() {
|
private suspend fun handleEmptyPoll() {
|
||||||
// Lifecycle: backoff når ingen events ble funnet
|
// Lifecycle: backoff når ingen events ble funnet
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.time.Instant
|
|||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
interface EventStore {
|
interface EventStore {
|
||||||
fun getPersistedEventsAfter(timestamp: Instant): List<PersistedEvent>
|
fun getPersistedEventsAtOrAfter(timestamp: Instant): List<PersistedEvent>
|
||||||
fun getPersistedEventsFor(referenceId: UUID): List<PersistedEvent>
|
fun getPersistedEventsFor(referenceId: UUID): List<PersistedEvent>
|
||||||
fun persist(event: Event)
|
fun persist(event: Event)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class InMemoryEventStore : EventStore {
|
|||||||
private val persisted = mutableListOf<PersistedEvent>()
|
private val persisted = mutableListOf<PersistedEvent>()
|
||||||
private var nextId = 1L
|
private var nextId = 1L
|
||||||
|
|
||||||
override fun getPersistedEventsAfter(timestamp: Instant): List<PersistedEvent> =
|
override fun getPersistedEventsAtOrAfter(timestamp: Instant): List<PersistedEvent> =
|
||||||
persisted
|
persisted
|
||||||
.filter { it.persistedAt > timestamp }
|
.filter { it.persistedAt > timestamp }
|
||||||
.sortedWith(compareBy<PersistedEvent> { it.persistedAt }.thenBy { it.id })
|
.sortedWith(compareBy<PersistedEvent> { it.persistedAt }.thenBy { it.id })
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ class PollerStartLoopTest : TestBase() {
|
|||||||
|
|
||||||
// Fake EventStore som alltid returnerer samme event
|
// Fake EventStore som alltid returnerer samme event
|
||||||
val fakeStore = object : EventStore {
|
val fakeStore = object : EventStore {
|
||||||
override fun getPersistedEventsAfter(timestamp: Instant): List<PersistedEvent> {
|
override fun getPersistedEventsAtOrAfter(timestamp: Instant): List<PersistedEvent> {
|
||||||
// Alltid returner én event som ligger før watermark
|
// Alltid returner én event som ligger før watermark
|
||||||
return listOf(
|
return listOf(
|
||||||
PersistedEvent(
|
PersistedEvent(
|
||||||
@@ -485,7 +485,7 @@ class PollerStartLoopTest : TestBase() {
|
|||||||
|
|
||||||
// Fixen skal flytte lastSeenTime forbi eventen
|
// Fixen skal flytte lastSeenTime forbi eventen
|
||||||
assertThat<Instant>(poller.lastSeenTime)
|
assertThat<Instant>(poller.lastSeenTime)
|
||||||
.isEqualTo(t(50).plusNanos(1))
|
.isEqualTo(t(50))
|
||||||
|
|
||||||
// Andre poll: nå skal polleren IKKE spinne
|
// Andre poll: nå skal polleren IKKE spinne
|
||||||
val before = poller.lastSeenTime
|
val before = poller.lastSeenTime
|
||||||
|
|||||||
Reference in new issue
Block a user