previewApply
What LocalHeddle.apply of new at generation would do to the engine that took this snapshot, with no engine: the same TopologyPreview as LocalHeddle.previewApply on that engine as it stood, but with no TopologyPreview.basis, since a snapshot keeps no revision. Changes nothing, here or anywhere. The leases it holds move as that engine's would, whatever epoch opened them.
policy is required because a snapshot does not keep one: pass the policy the engine ran with. Pass the generation the apply will use (see LocalHeddle.previewApply).
Throws
when policy cannot size totalSlots (see LocalHeddle.reconcileCapacity), or as LocalHeddle.apply does: new's root is not root, or generation is negative.
Samples
val before = Topology("pool", listOf(Topology.Lane("heavy", Weight.of(2)), Topology.Lane("light"), Topology.Lane("spare")))
val policy = LocalPolicy(defaultReservation = 3L)
val (heddle, _) = LocalHeddle.fromTopology(before, policy, epoch = 0L)
heddle.reconcileCapacity(totalSlots = 4L)
val spare = before.groupId("spare")
val running = (heddle.acquire(setOf(spare), setOf(spare), startedAt = 0L) as AcquireOutcome.Acquired).lease
val stored = Json.encodeToString(LocalHeddleSnapshot.serializer(), heddle.persist())
// On the admin screen: decode what was stored, and preview the edit with the engine's policy.
val decoded = LocalHeddle.decode(stored, Json)
check(decoded is RestoreResult.Restored)
val edited = Topology("pool", listOf(Topology.Lane("heavy", Weight.of(3)), Topology.Lane("light")))
val preview = decoded.snapshot.previewApply(policy, edited, generation = 1L)
// The answer the engine gives, with no revision to compare against.
val waits = preview.result.refusals.single()
check(waits is StepRefusal.Draining && waits.child == spare && waits.blockingLeases == listOf(running))
check(preview.basis == null)
check(preview.result == heddle.previewApply(edited, generation = 1L).result)Content copied to clipboard