partitionService is a mock, so an unstubbed getAllServiceIds() returns an
empty set and the known-id tests also passed through the fail-open branch.
Assert that a live member is accepted without consulting getAllServiceIds,
so the tests fail if the isKnownServiceId check is broken.
The recently-seen grace period and fails-open-on-unknown-topology paths
of isUnknownService were only tested for pushNotificationToCore. Mirror
those tests for pushNotificationToRuleEngine and pushNotificationToTransport
so a regression scoped to those service types doesn't slip through.
- Use the new isKnownServiceId() instead of getAllServiceIds().contains(),
avoiding two collection allocations on the common (live member) path.
- Reuse SetCache instead of a hand-rolled Caffeine cache for
recentlySeenServices.
- Drop pushNotificationToTransport's null/empty serviceId guard, now
redundant with isUnknownService() treating null/empty as unknown.
- Track skipped-due-to-unknown-service notifications in a counter and
surface it via the existing periodic stats log, since the point of
this guard is to catch a leak that was previously invisible.
getAllServiceIds() rebuilds two HashSets just to test membership of a
single id - PartitionService#isKnownServiceId scans the live service
lists directly instead, for the hot path in DefaultTbClusterService's
per-notification unknown-service guard. SetCache.boundedBySize() adds
an LRU-by-size variant alongside the existing TTL-based constructor.
The clusterService field is typed as the TbClusterService interface, which
does not declare onServiceListChanged (it is a concrete-class @EventListener).
Cast to DefaultTbClusterService in the recently-seen test so it compiles.
Make the unknown-service-id skip a lenient safety net rather than a
precise gatekeeper. A service id is treated as known if it is either a
current member (PartitionService.getAllServiceIds) OR a recently seen one.
The recently-seen set is a bounded (1024) LRU cache fed from
ServiceListChangedEvent, so a node that is briefly absent from the live
snapshot - discovery-propagation lag, rolling restart, transient
scale-down - still receives its notifications instead of having them
dropped; genuine non-delivery to a node that is actually gone is already
handled by the caller-side RPC/REST timeout. An id gone for good ages out
via LRU eviction and the guard tightens again.
The live-snapshot check stays authoritative for current members (discovery
events are change-only, so a pure recently-seen cache would go cold in a
quiet cluster); recently-seen only widens 'known', it never adds a new
drop. Adds a test for the offline-but-recently-seen path.
Follow the existing pushNotificationToTransport convention: a deliberate
skip to a non-member service id now completes the callback as a no-op
success instead of onFailure, so callers don't treat an intentional skip
as a delivery error. Aligns all three skip paths (core, rule engine,
transport) on one contract.
- Extend the unknown-service-id orphan-topic guard to pushNotificationToTransport
- Make HashPartitionService.currentOtherServices volatile (now read on the
per-notification path, written under the synchronized recalculatePartitions)
- Lower the per-skip log from warn to debug to avoid noise when stale service
ids appear in message metadata during normal operation
- Add tests for the transport guard (unknown skipped, known sent)
Per-service notification topics (<notifications-topic>.<serviceId>) are
auto-created by the Kafka producer on first send. pushNotificationToCore and
pushNotificationToRuleEngine forwarded the target service id as-is. That id may
come from message metadata (e.g. the originServiceId of RPC reply and
integration-downlink flows), so an id that does not belong to the cluster
created an orphan notification topic that no node ever consumes and that is
never cleaned up, growing the topic count without bound.
Validate the target service id against current cluster membership
(PartitionService.getAllServiceIds) before sending; when the id is not a known
TB_CORE / TB_RULE_ENGINE service, skip the push and report delivery failure on
the callback (the message was not delivered, so onFailure is the correct signal
and it also lets a waiting caller complete). The check fails open while the
cluster topology is not yet known (empty membership, e.g. right after startup)
so legitimate notifications are never dropped.
The tracking compensated for isManagedByCurrentService reporting isolated tenants
of a profile without dedicated servers as not managed (a dedicated server for any
other profile flipped it). That root cause is fixed in #16345, after which a
tenant's managed status changes only together with its own queue ownership, and
its queue keys are already in the partition change event.
Replace the test that pinned the old flip with one that checks the affected
tenants when a dedicated server for the tenant's own profile joins and leaves.
With the entity partitioning strategy, DummyTask.getEntityId() returns a new
random id per task, so the 200 tasks spread over many partitions and run in
parallel. 200 x 50 ms tasks could all finish within the fixed Thread.sleep(500),
so the cancel found nothing left to discard (discardedCount == 0).
Use 30 s tasks (60 s task timeout) so tasks are always in flight when the job
is cancelled, whatever the partitioning strategy, and cancel as soon as the job
is RUNNING. Cancellation interrupts running tasks (TaskProcessor.cancelRunningTasks),
so the test still finishes quickly. One test body covers both strategies.
The server accepts the WebSocket handshake and closes the session right
away when it rejects a pre-verification token in afterConnectionEstablished.
Java-WebSocket's connectBlocking() releases its latch on both open and close
and then returns engine.isOpen(), so it returns false when the client reads
the close frame before the caller checks the state. The asserted connect in
buildAndConnectWebSocketClient then failed.
The test now connects without asserting the connect result, waits for the
close, and asserts the server close code (1011), so it still proves the
token was rejected.
The rule engine stats report runs on a schedule. On its first report for
a tenant it creates a QUEUE_STATS entity, whose SaveEntityEvent becomes
an ADDED sendNotificationMsgToEdge call. When that tick fell between
Mockito.reset and verify, testFindTenantAssets and
testFindAssetTypesByTenantId saw one extra invocation (179 vs 178, 4 vs 3).
Count only entity ids that have an edge event type, which is the same
filter DefaultTbClusterService applies before sending to an edge.
HttpIntegrationTest creates the integration disabled and enables it right
away, which produces CREATED and UPDATED lifecycle messages. The CREATED task
reads the integration configuration when it runs. If the enable has already
been committed, that task starts the integration (STARTED), and the UPDATED
task that follows calls update() on the running integration and persists an
UPDATED event. waitUntilIntegrationStarted required the latest lifecycle event
to be STARTED, so it timed out after 30 s even though the integration was up.
Accept a successful STARTED or UPDATED as the latest lifecycle event.
WhiteLabelingControllerTest saves the system-level login white-labeling
params with baseUrl "https://domain.com" and never restores them. The
params persist in the shared test database, so when QrCodeSettingsControllerTest
runs later in the same JVM, getBaseUrl() resolves the system base URL to
domain.com and testGetMobileDeepLink fails with
expected "localhost" but was "domain.com".
Reset system white-labeling settings after every WhiteLabelingControllerTest
test, and reset them in QrCodeSettingsControllerTest setup as well.
/api/agentInfos?agentIds=... is served by a derived JPA 'id IN (...)'
query with no ORDER BY, so PostgreSQL may return rows in any order
(e.g. physical tuple order after an UPDATE). The test asserted
infos.get(0) == first and infos.get(1) == second, and failed whenever
the rows came back reversed. Match the returned infos by id instead.
After the managed-status fix the field was only written, never read. It
also held the fallback entries added by resolveByPartitionIdx, so reading
it later as "profiles with dedicated servers" would bring the bug back.
HashPartitionService.resolveByPartitionIdx caches the fallback (regular)
servers of an isolated profile without dedicated servers in
responsibleServices. isManagedByCurrentService then saw a non-empty list
for that profile and reported its tenants as not managed on the regular
servers, although those servers own the tenants' partitions. This happens
as soon as any dedicated server exists in the cluster.
Remember which profiles have dedicated servers before the fallback entries
are added, and use that set in isManagedByCurrentService.
ComponentActor.init calls createProcessor on every init attempt: the
mailbox retries a failed start, and re-initializes an INIT_FAILED actor
(failed start, or failed restart after a configuration update) on the
next RuleNodeUpdatedMsg, reusing the same actor instance. Reusing the
snapshot from actor creation there would keep a stale configuration and
ignore later fixes, so later attempts read the rule node from the
database, as before.
- Resolve affected tenants in PartitionChangeEvent.getAffectedTenants(),
returning null (all tenants) for non rule engine events, empty diffs and
shared queue changes.
- HashPartitionService adds isolated tenants whose managed status changed
without a change of their own queue keys.
- PartitionChangeMsg: forAllTenants/forTenants factories instead of a null
sentinel; affected tenants excluded from toString().
- Fold the AppActor log line into the existing DefaultActorService one.
- Tests: priority ordering in ActorSystemTest, AppActorTest on a real actor
system, DefaultActorServiceTest through onTbApplicationEvent, the
managed-status scenario in HashPartitionServiceTest.
AppActor.doProcess unconditionally broadcasts PARTITION_CHANGE_MSG to
every live TenantActor at high priority, regardless of whether a given
tenant's ownership actually changed. On a shared rule-engine instance
hosting many tenants, this means any single tenant's partition change
(e.g. moving to an isolated queue) interrupts every other tenant's
in-flight message processing, even though only one tenant's ownership
changed.
DefaultActorService now resolves which tenants are actually affected
from the partition-change diff it already has on hand (returning null
when the shared/non-isolated pool itself changed, since those tenants
aren't individually tracked and everyone must still be notified), and
AppActor uses that to broadcast only to the affected tenant actors,
reusing the existing TbEntityTypeActorIdPredicate filtering idiom.
Falls back to the original broadcast-to-everyone behavior whenever the
affected set can't be narrowed down.
PartitionChangeMsg only carried the affected ServiceType, so a
consumer had no way to know which specific tenants (if any) a given
partition change actually affects versus all of them. Add an optional
affectedTenants set: null preserves today's meaning ("could affect
anyone, notify everyone"), a non-null set means only those tenants are
affected. Existing single-arg construction is unchanged and keeps
defaulting to null.
TbActorSystem/TbActorCtx already supported broadcasting to a filtered
subset of children, and separately broadcasting to all children at a
given priority, but not both together. Expose the existing internal
implementation (already used for the priority-only case) as a public
filtered + prioritized overload, so callers can target a subset of
children without giving up delivery priority.