本文へ移動
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.0 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")

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(leaseDuration = Duration.ofSeconds(3), renewInterval = Duration.ofSeconds(1))
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, leasesExpireIndependently
}

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.
  • Assertions in new tests use FluentAssert .assert().

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは 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月19日 更新

Ahoo-Wang のスキルをすべて見る

このスキルの問題を報告する