ndkoval
04/15/2023, 9:44 AMndkoval
04/15/2023, 9:44 AMCLOVIS
04/15/2023, 9:56 AMPetter Måhlén
05/10/2023, 9:09 AMpublic class FireAtLeastOnceConsumer<V>(
private val delegate: Consumer<V>,
) : Consumer<V> {
@Volatile
private var fired = false
public fun consumeIfFirst(value: V) {
if (!fired) {
consume(value)
}
}
override fun consume(data: V) {
fired = true
delegate.consume(data)
}
}
But I'm having a really hard time getting lincheck to find the problem. See thread for more details about what I've tried.CLOVIS
08/21/2023, 5:21 PMOperation
annotation.
Reading the documentation, however, I don't understand how events emitted by the structure should be represented.
To give a bit more precision:
• incoming events are dated. It's possible that we do not receive them in the order in which they were initially created.
• there are complex rules w.r.t which outgoing events are emitted based on which incoming events.
We suspect our system breaks down in edge cases of:
• events which are processed in the incorrect order from their creation date
• events which are processed in parallel in a way that is incoherent with the rules.
As a simplification, we can represent the structure as:
data class Incoming(
val id: UUID,
val createdAt: Instant,
val payload: String,
)
data class Outgoing(
val id: UUID,
val createdAt: Instant,
val payload: String,
)
class SystemUnderTest(
val emit: (Outgoing) -> Unit,
) {
fun receive(event: Incoming) {
// complex logic...
emit(otherEvent1)
emit(otherEvent2) // in some cases...
// ...
}
}
What would a Lincheck model test for this class look like?
I assume something like:
class SUTTest {
private val emit: (Outgoing) -> Unit = // what here??
private val sut = SystemUnderTest(emit)
@Operation fun eventType1() { sut.receive(UUID.random(), Instant.random(), "1") }
@Operation fun eventType2() { sut.receive(UUID.random(), Instant.random(), "2") }
}
But I can't figure out how to represent the different kinds of outgoing events we expect, such that Lincheck can find incoherent sequences.CLOVIS
08/22/2023, 8:00 AM@Operation
functions have to be deterministic?
E.g. is that ok?
@Operation fun send() = sut.send(Random.nextInt())