본문으로 건너뛰기
cccskills
무료GitHub에 공개

simba-testing

Guide for testing code built on Simba 5 (leader election and distributed locks). Use when writing or reviewing tests for LeadershipListener callbacks, runWhileLeader / schedule work, partition groups, locks, @SimbaScheduled / @SimbaPartitioned beans, fencing-token resources (FencingSpec), LeaseBackend implementations (LeaseBackendSpec), or deterministic failover tests with InMemoryLeaseBackend and VirtualScheduler.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(2)

  • SKILL.md4.1 KB
  • agents/openai.yaml182 B

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Testing Simba-Based Code

Choose the Layer

You testUse
Application code that takes a SimbaInMemoryLeaseBackend (module simba-testing) on real time
Failover, expiry, timingInMemoryLeaseBackend + VirtualScheduler (virtual time, opt-in API)
A resource that checks fencing tokensFencingSpec (module simba-tck)
A LeaseBackend implementationLeaseBackendSpec (module simba-tck)
Real infrastructureTestcontainers (MySQL, PostgreSQL, Redis) or Curator TestingServer (Zookeeper)
testImplementation("me.ahoo.simba:simba-testing")
testImplementation("me.ahoo.simba:simba-tck")

The examples use FluentAssert's .assert() (me.ahoo.test:fluent-assert-core, brought in by simba-tck); with simba-testing alone, add it or use any assertion library.

Do not mock Simba, Election or Term when the in-memory backend can drive the real engine.

In-Memory Backend

val backend = InMemoryLeaseBackend()
val config = SimbaConfig.builder().leaseDuration(Duration.ofSeconds(3)).renewInterval(Duration.ofSeconds(1)).build()
Simba.builder().backend(backend).config(config).build().use { simba ->
    val elected = LinkedBlockingQueue<Term>()
    simba.election("job").start(object : LeadershipListener {
        override fun onElected(term: Term) { elected += term }
        override fun onRevoked(term: Term, reason: RevokeReason) = Unit
    })
    val term = elected.poll(5, TimeUnit.SECONDS)!!
    backend.owner(term.name)!!.token.assert().isEqualTo(term.token)
}

backend.owner(name) and backend.token(name) inspect the backend. In Spring Boot tests, declare @Bean fun leaseBackend(): LeaseBackend = InMemoryLeaseBackend(); the starter builds Simba over it.

Virtual Time

@OptIn(InternalSimbaApi::class)
val scheduler = VirtualScheduler()
val backend = InMemoryLeaseBackend(scheduler)
val simba = Simba.builder()
    .backend(backend)
    .config(config)
    .scheduler(scheduler)
    .ioExecutor(Runnable::run)
    .callbackExecutor(Runnable::run)
    .seed(0)
    .build()

scheduler.advance(Duration.ofSeconds(4)) { simba.awaitIdle() }   // fire due timers, settle between them

Leader work still runs on virtual threads: wait for it through queues. scheduler, awaitIdle and Scheduler are @InternalSimbaApi (opt-in, no compatibility guarantee).

FencingSpec

class LedgerFencingTest : FencingSpec() {
    override fun write(resource: String, fencingToken: Long) = ledger.settle(resource, fencingToken)
    override fun highestToken(resource: String) = ledger.fencingToken(resource)
    override fun leaseBackend(): LeaseBackend = InMemoryLeaseBackend()   // optional: real lock terms
}

Checks increasing and equal tokens accepted, lower rejected, racing writers, and a stale lock term rejected.

LeaseBackendSpec

class MyLeaseBackendTest : LeaseBackendSpec() {
    override fun createBackend(): LeaseBackend = MyLeaseBackend(store)
    // override val clock: ClockControl? — when the backend's clock is injectable
    // override val shortLease, lease, timeout
}

Every test uses fresh names, so the store can be shared.

Pitfalls

  • Never sleep; wait on queues, latches or futures (or advance virtual time).
  • Assert on the Term the callback/work received, never on shared "current leader" state.
  • Close clients (use {}) so sessions and virtual threads end with the test.
  • renewInterval × 2 ≤ leaseDuration and leaseDuration × (1 − drift) − margin > renewInterval, or SimbaConfig throws.
  • Simba's own engine changes must keep SimulationSpec green; replay with ./gradlew simba-testing:test -Psimba.simulation.seed=N.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

simba

무료

Guide for using Simba 5, the JVM leader-election and distributed-lock library, in applications. Use when adding leader election, leader-only work (runWhileLeader, schedule, @SimbaScheduled), partitioned work (group, @SimbaPartitioned), distributed locks (lock / LockTerm), configuring the JDBC (MySQL, PostgreSQL), Redis or Zookeeper backend, integrating with Spring Boot, using fencing tokens, tuning session timing, or migrating from Simba 4.x. For test-focused work, use the simba-testing skill as well.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

Ahoo-Wang/Simba332026년 10월 20일 업데이트

Ahoo-Wang의 스킬 모두 보기

이 스킬의 문제 신고