Daniel Iancu created SLING-13170:
------------------------------------
Summary: Replace Timer-based delay in JobManagerConfiguration
with injectable scheduler for testability
Key: SLING-13170
URL: https://issues.apache.org/jira/browse/SLING-13170
Project: Sling
Issue Type: Improvement
Components: Event
Reporter: Daniel Iancu
h3. Problem
{{JobManagerConfiguration.startProcessing()}} uses {{java.util.Timer}} with a
hardcoded wall-clock delay ({{backgroundLoadDelay}}) to debounce
listener notifications after topology changes. This has two problems:
# *Tests depend on Thread.sleep() and real time* — {{testTopologyChange}}
sleeps 4 seconds to verify no spurious events arrive, making it slow
and inherently flaky (the test was already flaky when
{{backgroundLoadDelay}} was uninitialized at 0).
# *The Timer is fire-and-forget* — there's no way to cancel pending timers
when the component deactivates, potentially leaking threads or
firing after shutdown.
h3. Proposed change
Replace the {{Timer}} in {{startProcessing()}} with a
{{ScheduledExecutorService}} (or similar) that can be injected in tests. This
would
allow tests to use a controllable scheduler to:
* Advance time explicitly instead of sleeping
* Verify debounce behavior deterministically
* Eliminate the 4-second sleep in {{testTopologyChange}}
h3. Scope
{{JobManagerConfiguration.startProcessing()}} — the {{else}} branch for
non-INIT topology events.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)